Stirling's Formula and Stirling's Approximation
A physics student dives into proving Stirling's formula from scratch using the Gamma function — a key tool for the Thermal & Statistical Mechanics journey ahead.
Some original drawings have corrections. Read the notes on those drawings alongside the worked steps.

Finally! I got into the physics department, and now that I’m in the 2nd semester of my 3rd year, I’m taking Thermal & Statistical Mechanics! Statistical mechanics, a field just as tantalizing as quantum mechanics!!! For some reason I really want to do well at it….
Maybe it’s because of this vague feeling I have — enough to make me consider double-majoring in statistics — that, in my own opinion, statistics could be a huge weapon for explaining the natural world and society….
Anyway, I’ll get down to organizing what I’ve been diligently learning. First off, the goal of this book really is to teach “statistical mechanics.”
Then thermodynamics?? What’s up with that??
By learning how to apply certain tools of statistical mechanics to thermodynamics, we naturally get a feel for statistical mechanics, and after that, apparently the book actually teaches you what statistical mechanics really is. So this semester is going to be only thermodynamics, apparently. Let’s learn well from here, and next semester we’ll dive into statistical mechanics!!!
So…. Up through Chapter 3 is pretty much ‘basics,’ so up to here…. I’ll just treat it as redefining the terms and concepts, and starting from around Chapter 4 I’ll study in my own way and organize the thermodynamics. Up through Chapter 3 is just an intro to the math and… very basic???
If you’ve studied quantum mechanics, the prior knowledge about probability and statistics should just be covered by quantum mechanics.
So, I’m going to try to prove Stirling’s formula, which I’ll use a lot going forward!!! To talk about Stirling’s formula, I first need to talk a bit about the gamma function, so I’ll refer a little to the mathematical physics textbook.
From a factorial to an integral
Start with a positive parameter $\alpha>0$. Then
$$\int_0^\infty e^{-\alpha x}\,dx=\frac1\alpha.$$Differentiating with respect to $\alpha$ brings down one factor of $-x$ each time. The exponential still beats every fixed power of $x$ at infinity, so these integrals converge. For a nonnegative integer $n$, repeating the step gives
$$\int_0^\infty x^n e^{-\alpha x}\,dx=\frac{n!}{\alpha^{n+1}}.$$Set $\alpha=1$ and—there’s our factorial!


Oh! The factorial, which we only used in high-school probability & statistics class, can be expressed as an integral like this!?

But the right-hand side of the above equation is precisely the gamma function we’re curious about,
, taken at $n+1$:

That is, to put it another way, n! as a product only makes sense for whole numbers, and for other n you use the gamma function instead: n! = Γ(n+1)!!! The integral works when the argument is positive; for negative non-integers you extend it with Γ(x+1) = xΓ(x), and at 0, −1, −2, … the gamma function has no value (it blows up).
Careful with the one-step shift: $0!=\Gamma(1)=\int_0^\infty e^{-x}\,dx=1$. It is not $\Gamma(0)$; that point is a pole.
For a real argument $z>0$, the integral definition is $\Gamma(z)=\int_0^\infty x^{z-1}e^{-x}\,dx$. Integration by parts gives $\Gamma(z+1)=z\Gamma(z)$. This recurrence also lets us extend the function to negative non-integers; the original integral itself does not converge there.
To a physics major’s eye, it’s really… fascinating, lol.
So first, let me lay down the definition of the gamma function!!!

So now, for the case we were curious about, ‘when it’s not a natural number,’ according to the definition of the gamma function you just substitute and calculate.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
It comes out like this. During the calculations, the Gaussian integral technique is required!!! It’s not hard!! In fact, putting $x=u^2$ gives
$$\Gamma(1/2)=2\int_0^\infty e^{-u^2}\,du=\sqrt\pi.$$Then the recurrence does the rest: $\Gamma(3/2)=\frac12\sqrt\pi$, while $\Gamma(-1/2)=\Gamma(1/2)/(-1/2)=-2\sqrt\pi$. That explains both the positive and negative half-integers in the table.
Let’s move on to Stirling’s formula!!! In thermal and statistical mechanics, numbers like
will frequently come up, apparently. Ah, and in thermal statistics n is a ridiculously huge number….
![]()
Just think about 1 mol — 1 mole means about 6 x 10^23 — and in the combination, if n is 6 x 10^23… lol, 6 x 10^23 factorial? There probably isn’t enough paper on Earth to write out all those digits??
Back in high-school math class, there’s something we learned to handle ridiculously huge numbers more easily. That something is log. When it comes to using this log, chemistry folks usually use common log with base 10, whereas physics folks tend to use natural log ln with base e (exponential)! We’re going to take ln of the combination.
Why the factorial becomes a Gaussian
Stirling’s formula approximates a large factorial and, after taking its logarithm, $\ln(n!)$—let me just throw the equation out there first:

Alright, alright, alright — this right here is Stirling’s formula.
This is why I introduced the gamma function earlier. Let me verify the above Stirling formula!!!

Why choose $x=n+y\sqrt n$? The exponent $f(x)=n\ln x-x$ is largest at $x=n$, because $f'(x)=n/x-1$. Around that peak, $f''(n)=-1/n$: a change of order $\sqrt n$ in $x$ changes the exponent by order one. The substitution measures distance from the peak in just those natural units.


For $y$ fixed as $n$ grows, expand the logarithm near the peak:
$$n\ln(n+y\sqrt n)-(n+y\sqrt n) =n\ln n-n-\frac{y^2}{2}+O\!\left(\frac{|y|^3}{\sqrt n}\right).$$The linear terms cancel! That’s why a Gaussian $e^{-y^2/2}$ appears. This is a local approximation near the peak, not a Taylor series valid for every $y$ all the way to infinity. The pictures give the large-$n$ reasoning; a full error proof also has to control the tails outside that central region.


Extending the Gaussian’s lower limit from $-\sqrt n$ to $-\infty$ loses a tail that tends to zero. Its full integral is $\sqrt{2\pi}$, so
$$n!\sim\sqrt{2\pi n}\left(\frac ne\right)^n.$$Here $\sim$ means the ratio of the two sides tends to 1 as the positive integer $n$ grows. We’re estimating the huge factorial itself with a small relative error.

Which part can we drop?
The last picture goes one step too far when it drops $\sqrt{2\pi n}$ from the factorial itself. That factor grows with $n$; $n!/(n/e)^n$ does not tend to 1. Keep the square-root factor when you want a multiplicatively accurate factorial.
Taking logarithms is a different matter:
$$\ln(n!)=n\ln n-n+\frac12\ln(2\pi n)+O(1/n).$$In a leading-order thermodynamic calculation, we often use $\ln(n!)\approx n\ln n-n$. The omitted term grows only like $\ln n$, rather than $n\ln n$, and its contribution per particle tends to zero. It is small on that scale—not literally zero.
For a quick check, $10!=3{,}628{,}800$. Keeping the square-root factor gives about $3{,}598{,}696$, an underestimate of 0.83%. Dropping it gives only about $453{,}999$. Same dominant exponential, very different factorial! Heh, this is why we should say what kind of accuracy we want.
Heads-up. In the final original drawing, read the version without $\sqrt{2\pi n}$ only as a leading-log approximation, $\ln(n!)\approx n\ln n-n$, not a relative-error approximation to $n!$ itself.
The integral definition and recurrence are recorded in the NIST DLMF, Gamma Function and Functional Relations ; the more precise asymptotic expansion is in §5.11 .




















Questions or corrections?
Did a step lose you, or does a number look off? Email me or use the contact page. Include the note title and the step or figure you mean.
Feedback goes to me privately by email; it is not posted as a public comment.