Stirling's Approximation Calculator
Stirling's approximation estimates the factorial of a number without multiplying out every integer from 1 to n, which is invaluable when n is large enough that the exact product is impractical or overflows. It appears throughout statistics, statistical mechanics, and combinatorics, usually in its logarithm form. Enter a whole number n and this calculator returns the Stirling estimate of n!, the exact factorial for comparison when it is small enough to compute, the natural logarithm of n! from the formula, and the percent error between the approximation and the true value so you can see how the accuracy improves as n grows.
Stirling's approximation formula
n! approx = sqrt(2 * pi * n) * (n / e)^n
ln(n!) approx = n*ln(n) - n + 0.5*ln(2 * pi * n)
percent error = (Stirling - exact) / exact * 100
e = 2.718281828..., pi = 3.141592653...
The leading-term formula multiplies a slowly growing square-root factor by the dominant power term (n/e)^n. The logarithm form is what is used for very large n because the raw value overflows ordinary floating-point storage beyond about 170 factorial.
Notes on Stirling's approximation
- The relative error is approximately 1 / (12n), so accuracy improves as n grows.
- By definition 0! and 1! both equal 1; Stirling's formula is poor for these tiny cases.
- Exact n! is shown only up to the point where double precision can hold it (about n = 170).
- The logarithm form is the practical version in entropy, statistics, and combinatorics.
- For non-integer arguments the gamma function generalizes the factorial.
Stirling's approximation: frequently asked questions
What is Stirling's approximation?
Stirling's approximation is a formula that estimates the factorial of a large number without multiplying every integer. The basic form is n! is approximately the square root of (2 times pi times n) times (n divided by e) raised to the power n. It becomes proportionally more accurate as n grows.
What is the Stirling formula used here?
This calculator uses the standard leading term, n! is approximately sqrt(2 * pi * n) * (n / e)^n, where e is Euler's number, about 2.718281828. It also reports the natural logarithm form, ln(n!) is approximately n*ln(n) - n + 0.5*ln(2*pi*n), which is what is used in practice for very large n.
How accurate is Stirling's approximation?
The relative error of the basic formula is roughly 1 divided by (12 times n), so it is under 1 percent once n reaches about 9 and under 0.1 percent by n equal to 84. The absolute factorial value grows enormous, but the percentage error keeps shrinking as n increases.
Why use a logarithm form for large factorials?
Factorials overflow ordinary floating-point numbers beyond about 170!, so the value itself cannot be stored. The logarithm form ln(n!) stays manageable and is what statisticians and physicists actually use, for example in entropy and combinatorics calculations, where only the logarithm of the factorial is needed.
Does this work for non-integer n?
The factorial itself is defined only for non-negative integers, so this calculator restricts n to whole numbers of zero or more. For non-integer arguments the gamma function generalizes the factorial, and Stirling's series extends to it, but that is beyond this simple integer tool.
Official sources
- NIST Digital Library of Mathematical Functions: Gamma Function, Asymptotic Expansions (Chapter 5.11).
- National Institute of Standards and Technology: NIST home.
Reviewed by the CalculatorHub team, edited by James Graham, 17 June 2026. See our methodology.