= Stirling formula
{c}
{title2=$n!\sim\sqrt{2\pi n}(n/e)^n$}
{wiki}
= Stirling's formula
{c}
{synonym}
= Stirling's approximation
{c}
{synonym}
<Stirling's formula> turns the long product defining a <factorial> into a short expression. For positive <integers> $n$, put
$$
S_n=\sqrt{2\pi n}\left(\frac ne\right)^n.
$$
Then $n!\sim S_n$ as $n\to\infty$. This is <asymptotic equivalence>: $S_n/n!\to1$, so the <relative error> tends to zero. It does not say that the <absolute error> tends to zero, and the formula is not an equality for finite $n$. The <Gamma function> extends this approximation beyond integer inputs. https://dlmf.nist.gov/5.11[NIST Digital Library of Mathematical Functions, §5.11: Gamma-function asymptotic expansions]{ref}
For $n=10$,
$$
10!=3\,628\,800,\qquad S_{10}\simeq3\,598\,695.619,\qquad
\frac{S_{10}-10!}{10!}\simeq-0.00829596.
$$
The leading estimate is about $0.830\%$ low. Multiplying by the first correction factor gives
$$
S_{10}\left(1+\frac1{120}\right)\simeq3\,628\,684.749,
$$
which is about $0.003176\%$ low. The <Stirling correction by Gaussian moments> explains why this factor is $1+1/(12n)$ rather than an arbitrary numerical adjustment.
\Image[/stirling-factorial-relative-error.png]
{title=Relative factorial errors shrink faster after the first Stirling correction}
{description=For each integer $1\leq n\leq100$, the curves compare $S_n$ and $S_n(1+1/(12n))$ with the exact <factorial>. The vertical axis is the nonnegative <relative error>, on a logarithmic scale.}
The usefulness is in ratios as well as in enormous numbers. Applying <Stirling's formula> to the three <factorials> in a <central binomial coefficient> gives
$$
\binom{2n}{n}\sim\frac{4^n}{\sqrt{\pi n}}.
$$
This counts the ways to choose exactly half of $2n$ objects. Equivalently, for $2n$ independent fair coin tosses, the <binomial distribution> assigns probability $\binom{2n}{n}/4^n\sim1/\sqrt{\pi n}$ to exactly $n$ heads. An exponentially large count becomes a simple probability scale after cancellation.
For numerical calculations, taking the <natural logarithm> yields
$$
\log(n!)=n\log n-n+\frac12\log(2\pi n)+r_n,
$$
where $r_n\to0$. Computing a <logarithm> of a large <factorial> avoids representing the factorial itself. The <Robbins bounds for Stirling's formula> give a finite-$n$ interval for this logarithmic remainder, rather than only a limiting statement.
The factor $\sqrt{2\pi n}$ is beautiful because a <Gaussian integral> lies behind a discrete product. The <Gaussian peak behind Stirling's formula> displays this connection through the <Gamma integral> and <Laplace's method>. A rigorous proof must also control the tails of the integral; the local expansion explains the geometry but is not by itself a complete proof.
James Stirling published \i[Methodus differentialis] in 1730, a treatise on <summation> and <interpolation> of infinite <series>. This setting connects the formula with a practical calculation problem: taking <logarithms> turns a long product into a <sum>, whose growth can be approximated. https://commons.wikimedia.org/wiki/File:Methodus_differentialis,_sive_tractatus_de_summatione_et_interpolatione_serierum_infinitarum_(IA_10053880bsb).pdf[James Stirling, Methodus differentialis (1730), digitized original and bibliographic record]{ref}
Back to article page