# Stirling's approximation

 related topics {math, number, function} {rate, high, increase}

In mathematics, Stirling's approximation (or Stirling's formula) is an approximation for large factorials. It is named after James Stirling.

The formula as typically used in applications is

The next term in the O(log(n)) is 12ln(2πn); a more precise variant of the formula is therefore

often written

## Contents

### Derivation

The formula, together with precise estimates of its error, can be derived as follows. Instead of approximating n!, one considers its natural logarithm:

The right-hand side of this equation is (almost) the approximation by the trapezoid rule of the integral $\int_1^n \ln(x)\,{\rm d}x = n \ln n - n + 1,$ and the error in this approximation is given by the Euler–Maclaurin formula:

where Bk is a Bernoulli number and Rm,n is the remainder term in the Euler–Maclaurin formula. Take limits to find that

Denote this limit by y. Because the remainder Rm,n in the Euler–Maclaurin formula satisfies

where we use Big-O notation, combining the equations above yields the approximation formula in its logarithmic form:

Taking the exponential of both sides, and choosing any positive integer m, we get a formula involving an unknown quantity ey. For m=1, the formula is

The quantity ey can be found by taking the limit on both sides as n tends to infinity and using Wallis' product, which shows that $e^y = \sqrt{2 \pi}$. Therefore, we get Stirling's formula:

The formula may also be obtained by repeated integration by parts, and the leading term can be found through Laplace's method. Stirling's formula, without the factor $\sqrt{2 \pi n}$ that is often irrelevant in applications, can be quickly obtained by approximating the sum

with an integral: