# Stirling's approximation

We want to derive here Stirling's approximation, i.e. we want to show that for large ${\displaystyle n}$ we have:

${\displaystyle n!\sim {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}}$

We start by writing ${\displaystyle n!}$ with Euler's ${\displaystyle \Gamma }$ function:

${\displaystyle n!=\int _{0}^{\infty }t^{n}e^{-t}dt}$
Changing variable to ${\displaystyle s=t/n}$ we get:
${\displaystyle n!=\int _{0}^{\infty }s^{n}n^{n}e^{-sn}nds=\int _{0}^{\infty }s^{n}e^{-sn}n^{n+1}ds}$
which we rewrite as:
${\displaystyle n!=\int _{0}^{\infty }e^{-sn+n\ln s+(n+1)\ln n}ds=e^{(n+1)\ln n}\int _{0}^{\infty }e^{n(\ln s-s)}ds}$
The last one is an integral in the form of those studied in the appendix The saddle point approximation; using the notation shown there we have ${\displaystyle f(s)=\ln s-s}$ and its maximum is at ${\displaystyle s=1}$. Since ${\displaystyle f''(1)=-1}$, we get:
${\displaystyle n!\sim e^{(n+1)\ln n}{\sqrt {\frac {2\pi }{n\cdot |-1|}}}e^{-n}=n^{n}n{\sqrt {\frac {2\pi }{n}}}e^{-n}={\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}}$
Therefore:
${\displaystyle n!\sim {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}}$

Taking the logarithm we find another famous expression for Stirling's approximation:

${\displaystyle \ln n!\sim n\ln n-n+{\frac {1}{2}}\ln(2\pi n)}$