Stirling Approximation Calculator

Estimate large factorials with the square root of two pi n times n over e to the power n.

Math and PercentUpdated 2026-11-192 min read
Stirling Approximation Calculator
A whole number from 1 to 1,000,000.
Stirling estimate of n factorial
...
Natural log of n factorial...
Exact factorial when computable...
Relative error...
n used...

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

  1. Enter the whole number n.
  2. Read the Stirling estimate as the main result.
  3. Use the natural log value for very large n.
  4. Check the exact factorial when it is available.
  5. Look at the relative error to judge accuracy.
  6. Try n = 100 to see the error fall below a tenth of a percent.

Formula

n factorial is approximately sqrt(2 pi n) times (n / e) to the power n; ln(n factorial) is approximately n ln n minus n plus half ln(2 pi n)
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.

  1. Compute n ln n minus n: 10 times 2.302585 minus 10 is about 13.02585.
  2. Add half of ln(2 pi n), about 2.07024, to get 15.09608.
  3. Exponentiate to get about 3,598,696.
  4. The exact factorial is 3,628,800.
  5. The relative error is about minus 0.83 percent.
  6. The tool reports approximation 3,598,696 and log_factorial 15.096082.

Reference table

Stirling estimates for sample n
nStirling estimateExact factorialRelative error
103,598,6963,628,800-0.8296 %
100about 9.32 times ten to the 157about 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

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.