A factorial grows fast. The numbers , , , , are still manageable, but by the factorial has outpaced anything the human eye can read off a calculator screen, and already has digits. The function 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 and gives back something close to 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 — and — appear together inside it, despite the original problem involving neither circles nor exponentials:
This is Stirling’s approximation. It says the factorial is essentially corrected by and adorned by the small prefactor . The approximation is astonishingly accurate even for small , and its relative error vanishes as grows. This article is about what the formula says, why it works, why and 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 is a huge number for moderate , and the right-hand side is also a huge number; their absolute difference will itself be huge. What matters is the ratio, which approaches :
For finite the ratio is slightly larger than — exactly at , dropping to at , at , and at . Roughly, the error is on the order of . The chart below shows the ratio for the first twenty integers, dropping quickly toward the horizontal line at .
By the ratio has collapsed to within one percent of ; by 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 has an integral form
The integrand is a function that climbs sharply and then decays; the climb dominates while and the decay dominates while , with a peak right at . The width of this peak shrinks (as a fraction of ) as 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 , the integrand is approximately
a Gaussian centred at with variance . Integrating over all — the Gaussian’s tails fall off so fast that the lower limit effectively becomes — gives . That is Stirling’s formula, with the factor of falling out exactly from the Gaussian integral
The in Stirling is the same that appears in the bell curve, and the same 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 is large — and the Gaussian, for reasons going back to the geometry of circles, has inside its normalising constant.
A more refined version
The basic formula has a more accurate sibling, sometimes called Stirling’s series:
Each successive term improves the approximation by a power of . The series is asymptotic rather than convergent — adding more and more terms for fixed eventually makes the approximation worse — but truncating at any fixed number of terms gives an extremely accurate approximation as grows. For most working purposes, the leading correction 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 that sits at the centre of Pascal’s triangle has, via Stirling, the asymptotic form . This single asymptotic underlies the calculation of the central limit theorem for binomial random variables: the height of the central column of an -trial coin-flip distribution scales like , which is exactly the spread of a Gaussian with variance — and the whole binomial distribution converges to the normal distribution. The mysterious in Stirling becomes the in the normal density.
Logarithms of factorials show up in statistical mechanics. The entropy of a system with microstates is , and when is a multinomial coefficient — say, the number of ways to distribute molecules among different energy states — Stirling gives a clean formula. For an ideal gas with molecules:
which is the form most often quoted in physics. This is the asymptotic Stirling stripped to its bones, ignoring the lower-order 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 — has an asymptotic shape that is fundamentally analytic in nature. The transcendental constants and both come along for the ride: because exponential decay is the natural setting for factorial growth, and 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 , 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.