Skip to content

Stirling’s Factorial Approximation

Updated:

Estimate the factorial of a large number instantly with Stirling's approximation: enter n and get n! ≈ √(2πn)(n/e)ⁿ in scientific notation. Ideal for statistics, probability, and combinatorics.

Stirling's Approximation Calculator

Input Fields
If enabled, the result will update automatically when you change any value.

Stirling’s Approximation Formula

Formula
\[n! \approx \sqrt{2\pi n}\left(\frac{n}{e}\right)^{n}\]

Where:

  • \(n\) — the number whose factorial is approximated (\(n \ge 1\))
  • \(\pi\) — the mathematical constant pi (≈ 3.14159)
  • \(e\) — Euler's number (≈ 2.71828)

The formula replaces the product \(1 \cdot 2 \cdot 3 \cdots n\) with a closed-form expression involving a square root and an exponential term, which can be evaluated in constant time no matter how large \(n\) is.

Stirling’s Approximation – Calculation Example

Example: approximate the factorial of 5.

\[n! \approx \sqrt{2\pi \cdot 5}\left(\frac{5}{e}\right)^{5}\]

\[\sqrt{10\pi} \approx 5.60499, \qquad \left(\frac{5}{e}\right)^{5} = \frac{3125}{e^{5}} \approx 21.05609\]

\[5! \approx 5.60499 \times 21.05609 \approx 118.019\]

Result: \(5! \approx 1.180190 \times 10^{2}\). The exact value is \(5! = 120\), so the approximation underestimates it by about 1.65%.

How to Use the Calculator

  1. Enter a positive integer in the Number of elements (n) field. The default value is 5.
  2. The result field labeled n! ≈ immediately shows the approximated factorial in scientific notation (for example, 1.180190e+2).
  3. To estimate a different factorial, simply type a new value for \(n\); the result updates automatically.

What Is Stirling’s Approximation?

A factorial \(n!\) is the product of all integers from 1 to \(n\). Factorials grow extremely fast: \(10!\) is already 3,628,800, and \(100!\) is a 158-digit number. Computing such values exactly requires arbitrary-precision arithmetic, and in many applications the exact digits are simply not needed. Stirling's approximation, named after the 18th-century Scottish mathematician James Stirling, gives a fast estimate of \(n!\) using only elementary operations.

The approximation is remarkably accurate. The relative error is roughly \(\frac{1}{12n}\), so it is about 0.8% for \(n = 10\), 0.1% for \(n = 80\), and vanishingly small for very large \(n\). This is why the formula is a cornerstone of asymptotic analysis: it converts products that grow factorially into expressions involving \(n^{n}\), \(e^{n}\), and \(\sqrt{n}\), which are far easier to manipulate algebraically.

Stirling's approximation appears throughout mathematics and science. It underlies the derivation of the normal approximation to the binomial distribution, the entropy formula in statistical mechanics and information theory, and the asymptotic behavior of the Gamma function \(\Gamma(n+1) = n!\). It is also the standard tool for estimating binomial coefficients, which count the arrangements in combinatorial structures such as those generated by the Leibniz harmonic triangle or the sums produced by Floyd's triangle.

Accuracy of the Approximation

\(n\) Exact \(n!\) Stirling’s approximation Relative error
1 1 0.9221 −7.79%
2 2 1.9190 −4.05%
5 120 118.019 −1.65%
10 3,628,800 3,598,696 −0.83%
20 2.4329×1018 2.4228×1018 −0.42%

Notice that the approximation always underestimates the true value, and the error shrinks steadily as \(n\) grows. For most practical purposes the estimate is already excellent by \(n = 20\).

Limitations and Practical Tips

  • Small n: the formula is intended for large \(n\). For \(n < 10\) the error may be noticeable, so use the exact factorial when every digit matters.
  • Always a slight underestimate: the simple version used here omits correction factors; a more precise variant multiplies the result by \(e^{1/(12n)}\).
  • Scientific notation output: results are displayed in exponential form (e.g., 9.332621e+157 for \(n = 100\)), which is the standard way to handle numbers too large for ordinary decimal notation.
  • Integer input only: enter a positive integer. For non-integer arguments, the generalization of the factorial is the Gamma function, which satisfies the same approximation for large arguments.
  • Order-of-magnitude work: when comparing growth rates, as with sequences built from an arithmetic progression versus factorial growth, Stirling's formula quickly shows that \(n!\) eventually dwarfs any polynomial or exponential \(c^{n}\).

Frequently Asked Questions

How do I calculate Stirling's approximation by hand?

Take the number n, divide it by e (≈ 2.71828), and raise the result to the power of n. Then multiply by the square root of 2πn. For example, for n = 10: \((10/e)^{10} \approx 1.0189\) million is too awkward by hand, so people usually work with logarithms instead: \(\ln(n!) \approx n\ln n - n + \frac{1}{2}\ln(2\pi n)\), which keeps all quantities manageable even for n in the millions.

Why does Stirling's approximation always underestimate the true factorial?

The basic formula \(\sqrt{2\pi n}(n/e)^{n}\) is the first term of an infinite asymptotic series. The next correction factor is \(e^{1/(12n)}\), which is slightly greater than 1, so the true value is always a bit larger than the estimate. Multiplying the calculator's result by \(e^{1/(12n)}\) removes most of the remaining error; the correction is below 1% once n exceeds about 9.

How accurate is Stirling's approximation for different values of n?

The relative error is approximately \(\frac{1}{12n}\). That means roughly 8% error at n = 1, 0.8% at n = 10, 0.1% at n = 80, and less than 0.01% beyond n = 850. If you need the exact integer value of n! (for instance in combinatorics proofs), compute the factorial directly for small n; for statistical estimates and order-of-magnitude comparisons, Stirling's formula is virtually always good enough.

What units does a factorial have?

A factorial is a pure count of ordered arrangements, so it is dimensionless — there are no units to convert. The result is just a very large number, which is why it is displayed in scientific notation (e.g., 9.33e+157). If you see the exponent written as 1e+157, that means 10 raised to the 157th power, not 157 factorial or a unit prefix.

Can I use Stirling's formula for non-integer or negative numbers?

Not directly. The factorial is defined only for non-negative integers, and this calculator requires a positive integer. For fractional values like 4.5 or 7.3, the correct tool is the Gamma function, where \(\Gamma(n+1) = n!\) and the same approximation \(\Gamma(x+1) \approx \sqrt{2\pi x}(x/e)^{x}\) holds for large x. For negative non-integers the Gamma function is defined, but Stirling's approximation needs careful handling with complex numbers.

What happens if I enter a very large n, like 10,000 or 1 billion?

The formula evaluates in constant time, so huge inputs are no problem — that is its main advantage over multiplying all integers up to n. However, standard double-precision arithmetic saturates around \(1.8 \times 10^{308}\), which corresponds to about n = 170. Beyond that, the calculator returns Infinity; to handle larger n, work with the logarithmic form \(n\ln n - n + \frac{1}{2}\ln(2\pi n)\) instead.

Where is Stirling's approximation used in practice?

It is central wherever factorials appear in formulas. In probability it justifies the normal approximation to the binomial distribution; in statistical mechanics it turns the factorials in entropy formulas into \(n\ln n - n\), giving the famous Boltzmann and Shannon entropy expressions; and in algorithm analysis it estimates the cost of algorithms that generate permutations. It also gives quick estimates of binomial coefficients via \(\binom{n}{k} \approx \frac{n!}{k!(n-k)!}\).

Leave a Reply

Your email address will not be published. Required fields are marked *