A factorial grows fast. The numbers 1!=11! = 1, 2!=22! = 2, 3!=63! = 6, 4!=244! = 24, 5!=1205! = 120 are still manageable, but by 20!2.4×101820! \approx 2.4 \times 10^{18} the factorial has outpaced anything the human eye can read off a calculator screen, and 100!100! already has 158158 digits. The function n!n! grows faster than any polynomial but slower than any exponential — it lives in its own intermediate regime, and the exact rate of growth is far from obvious from the definition.

What is wanted is a smooth approximation: a formula that takes a large integer nn and gives back something close to n!n! using only elementary operations. That formula exists, was discovered by Abraham de Moivre and refined by James Stirling around 1730, and contains a small shock. Two of the most famous constants in mathematics — π\pi and ee — appear together inside it, despite the original problem involving neither circles nor exponentials:

n!    2πn(ne)n.n! \;\approx\; \sqrt{2\pi n}\,\left(\frac{n}{e}\right)^n.

This is Stirling’s approximation. It says the factorial is essentially nnn^n corrected by ene^{-n} and adorned by the small prefactor 2πn\sqrt{2\pi n}. The approximation is astonishingly accurate even for small nn, and its relative error vanishes as nn grows. This article is about what the formula says, why it works, why π\pi and ee both end up inside it, and how it became one of the most-used results in all of mathematics.

What “approximation” means

To make sense of Stirling’s formula, one needs the right notion of being “close.” The factorial n!n! is a huge number for moderate nn, and the right-hand side 2πn(n/e)n\sqrt{2\pi n}\,(n/e)^n is also a huge number; their absolute difference will itself be huge. What matters is the ratio, which approaches 11:

limnn!2πn(n/e)n=1.\lim_{n \to \infty} \frac{n!}{\sqrt{2\pi n}\,(n/e)^n} = 1.

For finite nn the ratio is slightly larger than 11 — exactly 1.08441.0844 at n=1n = 1, dropping to 1.00841.0084 at n=10n = 10, 1.00081.0008 at n=100n = 100, and 1.000081.00008 at n=1000n = 1000. Roughly, the error is on the order of 1/(12n)1/(12 n). The chart below shows the ratio for the first twenty integers, dropping quickly toward the horizontal line at 11.

Ratio n! / Stirling(n) for n = 1, 2, …, 20 1.00 1.02 1.05 1.08 → 1 1 6 11 16 20 n

By n=10n = 10 the ratio has collapsed to within one percent of 11; by n=20n = 20 it is within half a percent. The approximation is genuinely useful even for the smallest integers anyone bothers to compute factorials of.

Where the formula comes from

The cleanest derivation starts with the integral representation of the factorial. The gamma function Γ(n+1)=n!\Gamma(n+1) = n! has an integral form

n!=0tnetdt.n! = \int_0^\infty t^n e^{-t}\,dt.

The integrand tnett^n e^{-t} is a function that climbs sharply and then decays; the climb dominates while t<nt < n and the decay dominates while t>nt > n, with a peak right at t=nt = n. The width of this peak shrinks (as a fraction of nn) as nn grows, so the integral is dominated more and more by the contributions near the peak.

This is the standard setup for Laplace’s method (also called the saddle-point method): approximate the integrand near its peak by a Gaussian, then integrate the Gaussian exactly. Around t=nt = n, the integrand is approximately

tnet    nnenexp ⁣((tn)22n),t^n e^{-t} \;\approx\; n^n e^{-n}\,\exp\!\left(-\frac{(t-n)^2}{2n}\right),

a Gaussian centred at nn with variance nn. Integrating over all tt — the Gaussian’s tails fall off so fast that the lower limit t=0t = 0 effectively becomes -\infty — gives nnen2πnn^n e^{-n} \cdot \sqrt{2\pi n}. That is Stirling’s formula, with the factor of 2π\sqrt{2\pi} falling out exactly from the Gaussian integral

ex2/2dx=2π.\int_{-\infty}^{\infty} e^{-x^2/2}\,dx = \sqrt{2\pi}.

The π\pi in Stirling is the same π\pi that appears in the bell curve, and the same π\pi that appears in Buffon’s needle and in the Riemann zeta function. The reason it appears in the factorial, of all places, is that the factorial integrand happens to look locally like a Gaussian when nn is large — and the Gaussian, for reasons going back to the geometry of circles, has π\pi inside its normalising constant.

A more refined version

The basic formula has a more accurate sibling, sometimes called Stirling’s series:

n!  =  2πn(ne)n(1+112n+1288n213951840n3+).n! \;=\; \sqrt{2\pi n}\,\left(\frac{n}{e}\right)^n\,\left(1 + \frac{1}{12 n} + \frac{1}{288 n^2} - \frac{139}{51840 n^3} + \cdots\right).

Each successive term improves the approximation by a power of 1/n1/n. The series is asymptotic rather than convergent — adding more and more terms for fixed nn eventually makes the approximation worse — but truncating at any fixed number of terms gives an extremely accurate approximation as nn grows. For most working purposes, the leading correction 1+1/(12n)1 + 1/(12n) is already more than enough.

What the formula is used for

The two most common uses of Stirling’s approximation are estimating binomial coefficients and estimating logarithms of factorials.

The binomial coefficient (2nn)\binom{2n}{n} that sits at the centre of Pascal’s triangle has, via Stirling, the asymptotic form (2nn)4n/πn\binom{2n}{n} \sim 4^n / \sqrt{\pi n}. This single asymptotic underlies the calculation of the central limit theorem for binomial random variables: the height of the central column of an nn-trial coin-flip distribution scales like 1/n1/\sqrt{n}, which is exactly the spread of a Gaussian with variance nn — and the whole binomial distribution converges to the normal distribution. The mysterious π\pi in Stirling becomes the 2π\sqrt{2\pi} in the normal density.

Logarithms of factorials show up in statistical mechanics. The entropy of a system with WW microstates is S=kBlogWS = k_B \log W, and when WW is a multinomial coefficient — say, the number of ways to distribute NN molecules among different energy states — Stirling gives a clean formula. For an ideal gas with NN molecules:

log(N!)    NlogNN,\log(N!) \;\approx\; N \log N - N,

which is the form most often quoted in physics. This is the asymptotic Stirling stripped to its bones, ignoring the lower-order 12log(2πn)\frac{1}{2}\log(2\pi n) correction. The fact that Stirling makes the messy combinatorics of statistical mechanics tractable is the reason the formula is on every physics-undergraduate cheat sheet.

In information theory, large-deviation principles and Shannon’s entropy formulas use Stirling to convert combinatorial counts of typical sequences into smooth functions of probabilities. In number theory, asymptotic estimates of the prime-counting function, of partition counts, and of many other multiplicative quantities ultimately reduce to Stirling-type asymptotic calculations.

Why this approximation is special

The deeper lesson of Stirling’s formula is that the factorial — a purely arithmetic object, defined by the recurrence n!=n(n1)!n! = n \cdot (n-1)! — has an asymptotic shape that is fundamentally analytic in nature. The transcendental constants ee and π\pi both come along for the ride: ee because exponential decay is the natural setting for factorial growth, and π\pi because the integrand defining the factorial happens to look Gaussian near its peak.

Two of the most famous constants in mathematics, neither of which appears anywhere in the definition of n!n!, both turn up inside the formula that describes how the factorial grows. This is the kind of surprising connection that working mathematicians cherish, and it is the kind of insight that turns a routine “estimate this combinatorial quantity” problem into a window onto the unity of analysis, combinatorics, and probability. Three centuries after Stirling published it, the formula remains one of the small handful of asymptotic results that every working mathematician carries around in their head.

Frequently asked

Who actually proved Stirling's formula first?

James Stirling published the asymptotic series in 1730, building on partial work by Abraham de Moivre. De Moivre had already shown a few years earlier that n! ≈ C·n^(n+1/2)·e^(−n) for some constant C, but could not pin down C beyond a series. Stirling's contribution was identifying that the constant is √(2π), which let him write the full formula. Some sources call the result the de Moivre–Stirling formula in acknowledgement of both.

Why do π and e both appear in the factorial?

The e appears because of the natural place factorial growth sits on the exponential scale: log(n!) is roughly n·log(n) − n, and the −n becomes a factor of e^(−n) when you exponentiate. The π is far more mysterious. It arrives from the Gaussian integral ∫e^(−x²)dx = √π, which appears when Stirling's formula is derived via Laplace's saddle-point method applied to the gamma-function integral. The π is the same π that appears in Buffon's needle and in the normal distribution — its presence in factorial growth is a signature that the Gaussian function is lurking beneath the surface.

How accurate is the approximation?

Remarkably accurate, even for small n. For n = 10 the relative error is about 0.83%; for n = 100 it drops to 0.083%; for n = 1000 it is 0.0083%. The error shrinks roughly as 1/(12n), and a refined version of the formula adds correction terms 1 + 1/(12n) + 1/(288n²) − ⋯ that drive the error down further. For most practical purposes the basic formula is good enough, and is the standard tool whenever logarithms of factorials need to be estimated quickly.

Where is Stirling's formula used?

Almost everywhere asymptotic analysis matters. The standard proof of the central limit theorem uses Stirling to estimate binomial coefficients. In statistical mechanics, the entropy S = k·log(W) of a system with W microstates is approximated using Stirling on the multinomial coefficients counting W, leading directly to the famous formula S = k·N(log(N) − 1) for an ideal gas. Information theory and large-deviation principles use Stirling whenever combinatorial counts need to be turned into smooth approximations. It is one of the most-applied formulas in all of mathematics, despite being only an approximation.