Stirling Approximation Calculator
Approximate n! for large n using Stirling formula and its refinement.
Compare exact vs approximate factorials and see relative error for any input.
Stirling Approximation
For large n, computing n! by direct multiplication is slow and overflows quickly. Stirling’s formula gives a remarkably accurate continuous approximation that grows polynomially in cost rather than linearly.
Standard Form
n! ≈ √(2πn) × (n / e)^n
Refined Form (with correction)
n! ≈ √(2πn) × (n / e)^n × (1 + 1/(12n) + 1/(288n²) − 139/(51840n³))
The corrections are the first terms of an asymptotic series. Adding more terms improves accuracy up to a point, after which the series diverges; asymptotic series rarely converge in the classical sense.
Logarithmic Form (most useful in practice)
ln(n!) ≈ n × ln(n) − n + ½ × ln(2πn)
This avoids the overflow problem entirely. It works for n in the millions on a calculator, and for n in the billions in numerical software.
Worked Example: n = 10
- Exact: 10! = 3,628,800
- Standard Stirling: √(20π) × (10/e)¹⁰ ≈ 3,598,696 (error 0.83%)
- Refined Stirling, all three correction terms: ≈ 3,628,800.05 (error 0.0000015%)
Even at modest n the refined form is essentially exact.
How Accurate Is Stirling?
This calculator applies all three correction terms, so its refined column is far tighter than the one-term version most textbooks stop at. Both are shown, because the gap between them is the clearest demonstration of what an asymptotic series buys you.
| n | Standard | Refined, 1 term | Refined, 3 terms (this calculator) |
|---|---|---|---|
| 1 | 7.79% | 0.10% | 0.029% |
| 5 | 1.65% | 0.012% | 0.0000117% |
| 10 | 0.83% | 0.0032% | 0.0000015% |
| 100 | 0.083% | 0.000034% | 0.00000000022% |
Relative error of standard Stirling falls like 1/(12n), so it halves roughly each time you double n. The three-term version improves far faster, gaining several orders of magnitude over the same range.
Where the series turns on you
Add correction terms and accuracy improves for large n. For small n it gets worse, and eventually absurd. The third term carries a coefficient of −139/51840, and as n shrinks that term grows like 1/n³ while the others grow more slowly. Below about n = 0.11 it overwhelms the rest and the whole correction goes negative, which would report a negative factorial. The calculator refuses rather than printing one.
That is the defining property of an asymptotic series: it is not converging toward the answer, and there is a point past which more terms means less accuracy. For small or fractional arguments use the gamma function directly instead.
Why It Matters
| Field | Use |
|---|---|
| Statistical mechanics | Entropy of N-particle systems |
| Information theory | Asymptotics of binomial coefficients |
| Probability | Central limit theorem proofs |
| Combinatorics | Counting permutations and partitions |
| Numerical computing | Avoiding factorial overflow |
Connection to the Gamma Function
For non-integer arguments:
Γ(z+1) ≈ √(2π/z) × (z/e)^z × refinement(z)
This extends Stirling smoothly to all positive real and complex z (not on the negative real axis). The result is a key tool in physics and analytic number theory.
Caveat
Stirling is an asymptotic approximation: it improves as n grows, but for tiny n (say n = 0 or 1) the error is significant. Use exact factorial up to about n = 20 in most languages, then switch to Stirling or to a logarithmic Lanczos approximation for larger arguments. For very large n, work in log space. Even Stirling’s own value overflows an IEEE double past about n = 170, which is why this calculator switches to reporting ln(n!) beyond that point.
How we build and check this calculator
This calculator runs entirely in your browser, so the numbers you enter stay on your device. The math behind it is written by hand and tested against worked examples and standard references before the page goes live.
SuperGlobalCalculator is independently built and maintained. See how we build and verify our calculators.