Stirling Approximation Calculator
Estimate large factorials with the square root of two pi n times n over e to the power n.
What it does
Stirling's approximation is a classical estimate for large factorials. It replaces the product of the first n integers with a smooth expression involving the square root of two pi n and the nth power of n over e.
This tool returns the estimate, the natural logarithm of the factorial, and the exact factorial with its relative error when n is small enough to compute exactly. The page opens with n equal to 10.
For n = 10 the estimate is about 3,598,696 while the exact factorial is 3,628,800, an error under one percent. The logarithmic form gives about 15.096.
The approximation comes from approximating the sum of logarithms of the integers by an integral, with the constant determined by the Gaussian integral. Refined versions add correction terms in powers of one over n.
For n beyond about 170 the exact factorial overflows standard floating point, so the tool reports it as not computed while still giving the logarithmic estimate.
How to use
- Enter the whole number n.
- Read the Stirling estimate as the main result.
- Use the natural log value for very large n.
- Check the exact factorial when it is available.
- Look at the relative error to judge accuracy.
- Try n = 100 to see the error fall below a tenth of a percent.
Formula
- n
- The whole number whose factorial is estimated.
- e
- The base of natural logarithms.
- ln(n!)
- Natural logarithm of the factorial, useful for large n.
The ratio of the approximation to the true factorial approaches 1 as n grows, even though the absolute difference becomes large. Adding the correction factor 1 plus 1 over 12n improves small cases substantially.
Worked example
Example: n = 10
The page opens with n = 10.
- Compute n ln n minus n: 10 times 2.302585 minus 10 is about 13.02585.
- Add half of ln(2 pi n), about 2.07024, to get 15.09608.
- Exponentiate to get about 3,598,696.
- The exact factorial is 3,628,800.
- The relative error is about minus 0.83 percent.
- The tool reports approximation 3,598,696 and log_factorial 15.096082.
Reference table
| n | Stirling estimate | Exact factorial | Relative error |
|---|---|---|---|
| 10 | 3,598,696 | 3,628,800 | -0.8296 % |
| 100 | about 9.32 times ten to the 157 | about 9.33 times ten to the 157 | -0.0833 % |
Limits
- Accepts whole numbers of n from 1 to 1,000,000.
- Exact factorial is only reported up to n = 170.
- For log factorial above 700 the exponential form is not displayed.
- The basic formula is asymptotic, not exact for finite n.
Common mistakes
- Using the approximation as an exact value for small n.
- Forgetting the square root of two pi n factor.
- Confusing the log form with the factorial itself.
- Expecting the absolute error to shrink as n grows.
- Applying the estimate to non integer inputs.
Try it yourself
Quick checks. Answers sit tucked under each question.
Stirling estimate for n = 10?
About 3,598,696, roughly 0.83 percent below the true value.
What is ln(10!) approximately?
15.096.
Why does the estimate improve with n?
The ratio of estimate to exact factorial tends to 1 as n grows.
Questions
What is Stirling's formula?
An asymptotic estimate for factorials using sqrt(2 pi n)(n/e)^n.
Why use the log form?
It avoids overflow when the factorial is enormous.
How accurate is it?
The relative error falls quickly, about 0.8 percent at n = 10 and 0.08 percent at n = 100.
Can I improve it?
Yes, multiply by 1 plus 1 over 12n plus further correction terms.
Where does two pi come from?
From the Gaussian integral that normalises the local approximation.
Does the formula work for small n?
It is usable but relatively less accurate; exact factorials are better there.
Sources
- University of Connecticut, Keith Conrad notes on Stirling's formula
- Princeton University, asymptotic approximations and Stirling's formula
- California State University Stanislaus, Stirling's approximation notes