The Stirling Approximation
Write out and you get a 23-digit number; write out — the factorial that shows up the moment you count the ways a mole of gas can arrange itself — and the number of digits alone would fill a library. Statistical mechanics runs on exactly these monsters, because the multiplicity of a macrostate is almost always a ratio of factorials, and entropy is its logarithm, . To do any physics you must tame for , and you cannot do it by multiplying terms. Stirling's approximation is the escape hatch. It trades the jagged, discrete for a smooth, differentiable function of a continuous variable: , with a refinement that adds the celebrated prefactor. The first form is all thermodynamics usually needs, because entropy is extensive — it grows like — so the leading dominates and the correction is a vanishing crumb per particle. The second form is what you keep when you care about fluctuations, normalization constants, or a comparison against an exact small-system answer. The formula is not a lucky guess. Two independent routes deliver it: an elementary one that replaces the sum by the area under , and a rigorous one that evaluates the Gamma integral by Laplace's saddle-point method, which manufactures the out of a Gaussian peak of width . Both agree, and both expose why it works: a product of many terms, viewed through a logarithm, becomes a well-behaved integral. The reward is that entropy becomes an analytic function you can differentiate — the single move that produces the Boltzmann, Fermi–Dirac, and Bose–Einstein distributions.
- Stirling's approximation replaces the intractable with the smooth function , valid for large — the workhorse behind every entropy and distribution derivation.
- The sharper form adds the subleading correction to the logarithm; keep it only for prefactors and fluctuations.
- It follows two ways: approximate by , or evaluate the Gamma integral by Laplace's method.
- Because entropy is extensive (), the leading term survives the thermodynamic limit and the correction is negligible per particle.
- The relative error of the leading form falls as ; restoring the term drops it one whole power of faster, to .
- Key idea: taking a logarithm turns a product of terms into an integral you can actually do — — making entropy a smooth, differentiable function of particle number.
Replace the discrete, intractable by the smooth function (plus a correction); the relative error vanishes as , so in the thermodynamic limit entropy becomes an analytic, differentiable function of particle and occupation numbers.
Where this lives today
Stirling's approximation is not a museum piece; it is load-bearing infrastructure in every corner of modern statistical and information science. In machine learning, the entropy and cross-entropy of categorical distributions — the loss functions that train classifiers — are Stirling-smoothed factorial counts in disguise; the same that Stirling produces from a binomial is the Shannon entropy minimized in every softmax layer. In computational chemistry and biophysics, partition-function estimates for polymers and lattice models lean on Stirling to convert configurational counts into free energies. And in numerical analysis the Lanczos and Spouge approximations to the Gamma function — the routines your calculator and every scientific library call to evaluate — are engineered refinements of exactly the de Moivre–Stirling asymptotics derived here. The formula also anchors the theory of large deviations, the modern language for rare events: the rate functions that quantify the exponentially small probability of an atypical fluctuation are Stirling-derived entropies, and they underlie everything from risk modeling to the fluctuation theorems of non-equilibrium thermodynamics.
The physical picture
Here is the whole idea in one image. The logarithm of a factorial is a sum of from to — a staircase of bars. The function is smooth and slowly varying, so the total area of those bars is very nearly the area under the curve from to . That area is , and the leading two terms are Stirling. The approximation is good precisely because changes gently from one integer to the next: the bars hug the curve.
The second picture explains the mysterious and shows the approximation's quality with numbers on the plot. The Gamma integral has an integrand that is a sharp bump centered at with width . As grows the bump becomes needle-thin relative to its position, so replacing it by a Gaussian captures essentially all the area — Laplace's method — and the Gaussian's normalization is precisely . The payoff figure is the punchline of this whole article: the relative error of the two Stirling forms plotted against . The leading form's error slides down a shallow slope (); the moment you restore the term, the error drops onto a steeper line one full power of lower.
Why physicists usually throw the away: entropy per particle is . The correction term marches to zero as , so it is genuinely irrelevant to bulk thermodynamics — it resurfaces only when finite size or fluctuations are the point.
The core equations
The headline result is the leading Stirling formula. It is the approximation you reach for by reflex whenever a factorial appears inside a logarithm, and it is exact in the sense that the ratio of the two sides tends to .
where: — a large positive integer (typically a particle or occupation number); ; — natural logarithm. Read it as: the log of a factorial grows like , faster than linearly but far slower than the factorial itself. Keeping one more term restores the prefactor and turns the approximation from "good" into "startlingly good even at modest ". This is the de Moivre–Stirling form, the one to quote when you need itself rather than just its logarithm.
where: — asymptotic equality (ratio as ); ; the prefactor is the width of the Gaussian peak of the Gamma integrand. Taking the logarithm gives . The full story is an asymptotic series in , whose successive terms are governed by the Bernoulli numbers. It is not a convergent series — its terms eventually grow — but truncated at its smallest term it is exquisitely accurate.
where: — first Bernoulli correction; the alternating higher terms carry Bernoulli numbers . For everything past is noise. The whole edifice rests on the integral representation of the factorial — the Gamma function — which is what makes Laplace's method available and extends to non-integer arguments.
where: — Euler's Gamma function; — a dummy variable over the positive reals. The integrand peaks at ; that peak is the seed of the saddle-point evaluation. Finally, the single feature that makes Stirling indispensable rather than merely convenient: its derivative is clean. Treating as continuous,
where: the chain-rule term exactly cancels the derivative of . This cancellation is why maximizing over occupation numbers produces terms — and hence the exponential equilibrium distributions.
The goal here is to get the full Stirling formula, prefactor and all, from a single controlled approximation rather than from hand-waving about sums and integrals. The strategy is Laplace's method: when an integral is dominated by a sharp peak, expand the exponent to second order about its maximum and do the resulting Gaussian integral exactly. Applied to the Gamma integral , the peak sits at , its curvature sets a width , and the Gaussian normalization is exactly the we are chasing. Watch the appear from nothing but the width of a bump.
Result.
Step 1. Write the integrand as one exponential: with . Why: Laplace's method needs the whole integrand in the form so that a large parameter multiplies a smooth exponent — here is large and scales with it.
Step 2. Locate the maximum: gives . Why: for large the integrand is overwhelmingly concentrated at its single interior maximum; everything else contributes negligibly.
Step 3. Measure the curvature: , so . Why: the second derivative fixes how fast the peak falls off — a curvature means a Gaussian of variance , i.e. width .
Step 4. Expand to second order about :
Why: near a smooth maximum the exponent is parabolic; the constant piece pulls out of the integral, leaving a pure Gaussian.
Step 5. Do the Gaussian integral, extending the lower limit to (legitimate because the peak is sharp):
Why: is the standard Gaussian result — the is its normalization and the is the variance set in Step 3. The prefactor was never mysterious: it is the area of a bell curve. *Verified: taking the logarithm reproduces ; a numpy check of gives at , matching Abramowitz & Stegun 6.1.41.*
Go deeper · Derivation B · 1 minThe error orders: what the prefactor buys you
This derivation is the article's owned result: a precise accounting of how good each Stirling form is, expressed as the power of at which the relative error decays. It matters because "Stirling is accurate for large " is too vague to use — you need to know whether dropping the term costs you a factor of or a factor of . The answer, confirmed by a machine table over six decades of , is sharp: the leading form errs at order , and restoring the prefactor buys a clean extra power of , taking the error to relative to .
Result.
Step 1. The absolute error of the leading form is exactly the dropped terms: . Why: subtract (1) from the full series (3); the first surviving term is the prefactor's logarithm.
Step 2. Divide by to get the relative error (since for large ). Why: relative error is what governs how many correct digits you keep; the scaling means one extra correct digit per factor in .
Step 3. The absolute error of the full form is the next dropped term, ; dividing by gives relative error — down by a factor versus Step 2. Why: the prefactor term was the entire -relative deficit; removing it exposes the much smaller -relative Bernoulli term.
Step 4. Confirm on a table. At the leading relative error is (ratio to equals to three figures), while the full-form relative error is — each one power of smaller. Why: the numbers march down the two predicted slopes exactly, pinning the error orders and vindicating the "drop the prefactor in bulk, keep it for finite size" rule. *Verified: `verify_aq-sm-stirling-approximation.py` reproduces both error-order columns and the ratio-to-prediction across six decades of .*
Limiting cases
The right truncation depends entirely on how large is and what you are computing:
| Case | Result | Meaning |
|---|---|---|
| Thermodynamic limit | Leading term suffices; relative error . The default in deriving entropy and distributions. | |
| Finite-size / fluctuations | Keep the prefactor for normalization constants, Gaussian fluctuation amplitudes, and comparisons to exact small- answers. | |
| High precision | full series | Divergent (Gevrey-1) but, truncated at its smallest term, exponentially accurate. |
| Small — breakdown | use exact factorials | , yet gives and ; the approximation is simply wrong here. |
Worked examples
1 · Watch the gap close: ln(100!) by hand-scale reasoning (confidence builder)
Compute exactly, then with each Stirling form, and see how much the prefactor buys.
Step 1. Exact value (from ): . This is the truth we are approximating.
Step 2. Leading Stirling: . The error is , a relative error of .
Step 3. Add the prefactor: . So the full form gives — matching the exact value to three decimals.
Step 4. Read the lesson: the entire leading-form deficit at is , and it is exactly the prefactor term . That is the owned error-order result made concrete — the correction you dropped is the whole error, to leading order. Contrast with : exact , leading form (error , a full ), and adding recovers . Small is where the prefactor earns its keep.
2 · The entropy of a spin-½ paramagnet from a binomial (exam level)
A crystal has spin-½ atoms. Using Stirling, find the entropy when a fraction point up, and compare it to the maximum.
Step 1. The multiplicity is the binomial — the number of ways to choose which atoms are up. Its log is .
Step 2. Apply the leading Stirling to each factorial. The pieces cancel (since ), leaving the Shannon form .
Step 3. Plug in : and . The bracket is , so and .
Step 4. The maximum entropy is at : . So the quarter-up state carries of the maximum entropy — still enormous, because is flat near its peak. Only Stirling makes this a one-line calculation: without it, differentiating to find the peak would be hopeless.
Step 5. Sanity check the leading-order use: at the dropped prefactor is about , utterly negligible against . The extensive entropy is safe.
Origins · 1 minJames Stirling and how this was discovered
Stirling was a Scottish mathematician — nicknamed "the Venetian" for years spent in Italy — whose 1730 book Methodus Differentialis studied the asymptotics of series and factorials. The formula that bears his name, , has a tangled paternity: Abraham de Moivre had already found that grows like while working on the normal approximation to the binomial, but it was Stirling who identified the constant as . The two corresponded and effectively share the result — which is why the sharp form is often called the de Moivre–Stirling formula. It is a rare case of a piece of pure eighteenth-century asymptotics becoming, two centuries later, the single most-used approximation in statistical physics: every time an entropy is differentiated, Stirling is silently at work.
Going further
Texts. Pathria & Beale, Statistical Mechanics, 3rd ed., Appendix B (Stirling's formula) · Kardar, Statistical Physics of Particles, Ch. 2–4 · Reif, Fundamentals of Statistical and Thermal Physics, Appendix A.6 · Sethna, Statistical Mechanics: Entropy, Order Parameters, and Complexity, Ch. 3 · Abramowitz & Stegun, Handbook of Mathematical Functions, 6.1.37–6.1.42.
Provenance. Leading and full Stirling formulas, the asymptotic series with Bernoulli corrections (Abramowitz & Stegun 6.1.37–6.1.42), the Laplace/saddle-point derivation (, ), and the Euler–Maclaurin constant are standard. A verifier should reproduce: the ratio ( at ); the owned error-order table (leading relative error , full relative error one power of smaller, over –); the worked numbers , leading , full , and ; and the paramagnet entropies () vs (). Constant (CODATA, exact since the 2019 SI). No non-standard numbers are asserted.
Prerequisites. Microstates and Macrostates · Boltzmann Entropy · Logarithms and integration. Leads to. Boltzmann Entropy · Statistical Ensembles · Accessible Phase Space and Energy Shells.
Is Stirling's approximation exact, or just "good enough"?
Neither, exactly. It is asymptotically exact: the ratio of the two sides of tends to as , so for the astronomical of statistical mechanics it is exact for every practical purpose. But the full series is divergent — if you keep summing its terms they eventually blow up. The trick is that you truncate it at its smallest term, where the leftover error is exponentially tiny. So it is a controlled, quantifiable approximation whose error you can bound, not a vague heuristic.
Why do we take the logarithm before approximating, rather than approximating N! directly?
Two reasons. First, itself is hyper-astronomical — for a mole it has more digits than atoms in your body — so there is no useful "smooth curve" to fit it to. Its logarithm, by contrast, is a tame , an ordinary extensive quantity. Second, physics wants the logarithm anyway: entropy is , and is built from factorials. Taking the log turns the product-of-factorials multiplicity into a sum, and Stirling turns that sum into a differentiable function — exactly what you need to maximize and find equilibrium.
When can I safely drop the ½ln(2πN) term?
Whenever you are computing an extensive quantity in the thermodynamic limit — which is most of bulk thermodynamics. Entropy scales as , while the prefactor term contributes only , so per particle it is . Keep it in three situations: (1) fluctuations and finite-size corrections, where the width is the whole point; (2) normalization constants of probability distributions; (3) any comparison against an exact small- result. And whenever you keep it for one factorial, keep it for all of them in the same calculation.
Where does the 2π come from? It seems to appear out of nowhere.
It is the normalization of a Gaussian. The Gamma integrand is a bump peaked at ; near the peak it looks like a bell curve of variance . The area under that bell curve is , and the is simply the constant in the Gaussian integral . So the that shows up in factorial asymptotics is the same from the normal distribution — no coincidence, since de Moivre found the formula while studying exactly that distribution.
The derivative d/dN(ln N!) ≈ ln N looks too clean. Why does the "+1" disappear?
Differentiate : the product rule on gives , and the derivative of is , so they cancel to leave exactly . That cancellation is not an accident — it is the reason Stirling is so beloved for variational problems. When you maximize over the occupation numbers , each derivative is just , and setting the Lagrange-constrained variation to zero gives , i.e. — the Boltzmann distribution falls out in one line.
Is Stirling's formula actually due to Stirling?
Only partly. Abraham de Moivre, working on the normal approximation to the binomial around 1730, had already shown that for some constant — he just could not pin down . James Stirling supplied the missing piece, identifying . The two corresponded, and the sharp form is fairly called the de Moivre–Stirling formula. Stirling's own contribution appears in his 1730 Methodus Differentialis; the rigorous saddle-point derivation you see today came later, with Laplace's method.
How can a divergent series be useful? Doesn't divergence mean it's wrong?
A divergent asymptotic series is a different animal from a convergent one. For a fixed , its terms first shrink — dramatically — reach a minimum, and only then grow. If you stop at that minimum term, the remaining error is smaller than any power of : exponentially small. So for large you get spectacular accuracy from just two or three terms, even though summing all of them would diverge. This is generic in physics — perturbation series in quantum field theory behave the same way. The rule is: truncate at the smallest term, never "to convergence".