Skip to content
Math

Harmonic Number Calculator H(n)

Enter any positive number n to compute the nth harmonic number H(n) - the sum of reciprocals 1 + 1/2 + 1/3 + ... + 1/n. You get the exact decimal value, the exact fraction for small integers, the asymptotic logarithmic approximation with error, and a partial-sums chart showing how the series grows. Switch to generalized mode to compute H(n, m) - the sum of 1/k^m - which underpins the Riemann zeta function and p-series analysis.

Your details

Standard computes H(n) = 1 + 1/2 + ... + 1/n. Generalized computes H(n,m) = 1 + 1/2^m + ... + 1/n^m.
Positive number for standard mode (integers give an exact fraction). Positive integer only for generalized mode.
H(n)H(n) 2-3 (moderate n)
2.92896825

The nth harmonic number (exact decimal)

Exact fraction7381/2520
ln(n) + gamma approximation2.92896742
Approximation error-0%
H(n) exact2.92896825
ln(n) + gamma approx2.92896742
01.462.931610
n
  • H(n) exact
  • ln(n) + gamma approx

H(10) = 2.928968 - the sum of the first 10 unit fractions.

  • H(10) = 2.928968, which is approximately ln(10) + 0.5772 = 2.879801.
  • Doubling n to 20 only adds about ln(2) = 0.693 to the sum, giving H(20) = 3.5977. This slow logarithmic growth is why the series diverges but extremely slowly.
  • The asymptotic approximation ln(n) + gamma + 1/(2n) - 1/(12n^2) is within 0.0000% of the exact value, becoming more accurate as n grows.

Next stepThe harmonic series diverges to infinity, but you need H(n) > 10 only at n around 12367, and H(n) > 20 only at around n = 272 million.

Formula

H(n)=k=1n1k=1+12+13++1nlnn+γ+12n112n2,γ0.5772H(n) = \sum_{k=1}^{n} \frac{1}{k} = 1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{n} \approx \ln n + \gamma + \frac{1}{2n} - \frac{1}{12n^2}, \quad \gamma \approx 0.5772

Worked example

H(5) = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 60/60 + 30/60 + 20/60 + 15/60 + 12/60 = 137/60 = 2.28333. The approximation gives ln(5) + 0.5772 + 1/10 - 1/300 = 1.6094 + 0.5772 + 0.1000 - 0.0033 = 2.2833, an error of less than 0.001%.

What is a harmonic number?

The nth harmonic number H(n) is the sum of the first n terms of the harmonic series: H(n) = 1 + 1/2 + 1/3 + ... + 1/n. The name "harmonic" comes from the harmonic series in music, where overtone frequencies are integer multiples (and therefore their reciprocals are harmonically related). Harmonic numbers appear throughout mathematics: they give the expected number of coupon types needed to collect a full set, the average number of comparisons in Quicksort, the depth of binary search trees, and the divergence of the harmonic series itself, which Nicole Oresme proved in the 14th century. H(1) = 1 is the only harmonic number that is itself a whole number; for n > 1, H(n) is always a non-integer rational number. As n grows, H(n) grows without bound but extremely slowly - it takes about n = 12367 terms for H(n) to exceed 10.

How to calculate harmonic numbers

For a positive integer n, add the fractions 1/1 + 1/2 + ... + 1/n. Finding the exact rational form requires a common denominator: for example, H(4) = 12/12 + 6/12 + 4/12 + 3/12 = 25/12. For large n the direct sum still converges but needs many operations, so the asymptotic approximation H(n) = ln(n) + gamma + 1/(2n) - 1/(12n^2) is useful, where gamma = 0.57721566... is the Euler-Mascheroni constant. This approximation is within 0.01% for n as small as 10 and improves steadily. For non-integer n, the harmonic number is defined by the extension H(n) = psi(n+1) + gamma, where psi is the digamma function (the logarithmic derivative of the gamma function), or equivalently by the convergent series sum_{k=0}^{inf} n / [(k+1)(k+n+1)].

Generalized harmonic numbers and the Riemann zeta function

The generalized harmonic number H(n, m) = sum_{k=1}^{n} 1/k^m extends the concept to higher-order sums. When m = 1 you get the ordinary harmonic number. When m = 2 you get 1 + 1/4 + 1/9 + ... + 1/n^2, which converges to pi^2/6 as n goes to infinity - the answer to the famous Basel problem solved by Euler in 1735. In general, the infinite series sum_{k=1}^{inf} 1/k^m equals the Riemann zeta function zeta(m) for m > 1: zeta(2) = pi^2/6, zeta(3) (Apery's constant) = 1.202..., zeta(4) = pi^4/90. The generalized harmonic numbers are therefore partial sums that approach these celebrated constants. They also arise in combinatorics, the analysis of sorting algorithms, and the study of polylogarithms.

Applications of harmonic numbers

Harmonic numbers appear in a surprising range of fields. In computer science, the expected number of comparisons in Quicksort on a random list of n elements is approximately 2n ln(n) = 2n H(n), and the coupon-collector problem asks how many random draws you need to collect all n distinct coupons - the answer is n times H(n), so collecting all 50 US state quarters takes about 50 x H(50) = 50 x 4.499 = 225 draws on average. In number theory, harmonic numbers relate to perfect numbers and to Wolstenholme's theorem on prime numbers. In physics, the harmonic series describes the overtones of a vibrating string, and generalized harmonic numbers appear in quantum field theory. In probability, the harmonic distribution is used in linguistics (Zipf's law: the r-th most common word appears with frequency proportional to 1/r).

Famous harmonic numbers

nH(n) decimalExact fractionApprox ln(n)+gamma
11.0000001/11.000000
21.5000003/21.270671
31.83333311/61.671472
42.08333325/121.979061
52.283333137/602.240694
62.45000049/202.471021
72.592857363/1402.677930
82.717857761/2802.866572
92.8289687129/25203.040534
102.9289687381/25203.202312
203.597740-3.588962
504.499205-4.499015
1005.187378-5.187376
10007.485471-7.485471

Selected values of H(n), H(n) as an exact fraction, and the approximation error.

Frequently asked questions

What is the harmonic number formula?

H(n) = 1 + 1/2 + 1/3 + ... + 1/n = sum of 1/k for k from 1 to n. For large n, the approximation H(n) = ln(n) + 0.57722 + 1/(2n) - 1/(12n^2) is very accurate. The only exact integer value is H(1) = 1; all other harmonic numbers are positive rationals with denominators that grow quickly.

Does the harmonic series converge?

No. The harmonic series 1 + 1/2 + 1/3 + ... diverges to infinity, meaning its sum grows without bound as more terms are added. This was first proved by Nicole Oresme around 1350 and is one of the most famous results in analysis. However, the divergence is extremely slow: H(n) grows as ln(n), so you need about n = 12,367 terms for the sum to first exceed 10, and roughly n = 272 million terms to exceed 20.

What is the Euler-Mascheroni constant gamma?

The Euler-Mascheroni constant gamma = 0.57721566490153... is the limiting difference between the nth harmonic number and the natural logarithm of n: gamma = lim_{n -> inf} [H(n) - ln(n)]. It appears in the asymptotic formula for harmonic numbers, in the digamma function, and in many results in number theory and analysis. Whether gamma is rational or irrational remains an open problem in mathematics.

What is the generalized harmonic number H(n, m)?

H(n, m) = 1/1^m + 1/2^m + ... + 1/n^m is the sum of the first n terms of the p-series with exponent m. When m = 1 it reduces to the ordinary harmonic number. For m = 2 the limit as n goes to infinity is pi^2/6 (the Basel problem). For m > 1 the series converges and the limit is the Riemann zeta function zeta(m). For m = 1 the series diverges. This calculator computes H(n, m) for positive integer n and integer m >= 1.

Can I compute harmonic numbers for non-integer n?

Yes. For non-integer n, the harmonic number is extended via the digamma function: H(n) = psi(n+1) + gamma, where psi is the logarithmic derivative of the gamma function. This interpolates smoothly between integer values and satisfies H(0) = 0 and the recurrence H(n) = H(n-1) + 1/n for all positive real n. This calculator uses a convergent series approximation for non-integers that is accurate to about 8 decimal places for n up to 1000.

How many terms of the harmonic series do I need to exceed 10?

You need H(n) > 10, which first occurs at n = 12367 (H(12367) = 10.00004...). To exceed 20, you need roughly n = 272,400,600. To exceed 100, you need n to be astronomically large - approximately e^(100 - gamma) = e^99.42 which is about 3.4 x 10^43. This illustrates how slowly the harmonic series grows despite diverging to infinity.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…