Factorial Calculator: Exact n!, Trailing Zeros and Stirling's Formula
By FindMySum · Last reviewed
A factorial calculator multiplies every whole number from 1 up to n. The result, written n!, grows faster than almost any function you meet in school mathematics: 10! is already 3,628,800, and 100! has 158 digits. This calculator gives every digit of n! up to 5,000!, along with the digit count, the number of trailing zeros, the double factorial and Stirling's approximation. This article explains each of them.
The definition
For a whole number n,
n! = n × (n − 1) × (n − 2) × … × 2 × 1
and 0! is defined as 1. The calculator's default is 10:
10! = 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 3,628,800
That number has 7 digits and ends in 2 zeros. The same value is the first term of the On-Line Encyclopedia of Integer Sequences entry A000142 that most people check, and what Excel's FACT(10) returns.
Factorials count arrangements. There are n ways to choose the first item in a row, n − 1 for the second, and so on down to one way for the last, so n different objects can be lined up in n! different orders. Ten books on a shelf can stand in 3,628,800 orders; a 52-card deck in about 8.07 × 10⁶⁷.
Why 0! = 1
Three arguments lead to the same answer. There is exactly one way to arrange zero objects (do nothing). The step rule n! = n × (n − 1)! gives 1! = 1 × 0!, which only works if 0! = 1. And a product with no factors is 1, the identity for multiplication, just as an empty sum is 0. Without this convention, formulas for combinations such as C(n, n) = n! ÷ (n! × 0!) would break.
Counting digits and trailing zeros
The number of digits of n! is one more than the integer part of log₁₀(n!). The calculator counts the digits of the exact result directly, so there is no rounding risk at the boundary between, say, 157 and 158 digits.
Trailing zeros are a neater problem. Every zero at the end of a number comes from a factor of 10, which is 2 × 5. Among 1, 2, …, n there are far more even numbers than multiples of 5, so the number of 5s sets the count. Legendre's formula adds them up:
trailing zeros of n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …
Multiples of 25 contribute an extra 5, multiples of 125 another, and so on. For 100! that gives 20 + 4 = 24 zeros; for 1000!, 200 + 40 + 8 + 1 = 249. The jump at multiples of 25 is why 24! ends in four zeros but 25! ends in six.
Exact digits versus floating point
Spreadsheets and most calculators store numbers as 64-bit floating point, which keeps about 15 to 17 significant digits and overflows above roughly 1.8 × 10³⁰⁸. That means 18! is the last factorial they hold exactly and 170! is the last they can show at all. This calculator multiplies integers of unlimited length, splitting the product into balanced halves so even 5000!, a 16,326-digit number, takes only a few milliseconds. You can copy every digit.
Stirling's approximation
For large n, writing out n! is less useful than knowing its size. Stirling's formula gives it:
n! ≈ √(2πn) × (n/e)ⁿ
It is remarkably good. For 10! it gives about 3,598,696, which is 0.83% low; for 100! the error is 0.083%, and for 1000! it is 0.0083%. The relative error is close to −1/(12n), the first correction term in Stirling's series, as listed in the NIST Digital Library of Mathematical Functions, §5.11. The calculator shows the approximation and its error next to the exact value so you can watch it converge.
Double factorials
The double factorial n!! multiplies every second number down from n:
- 9!! = 9 × 7 × 5 × 3 × 1 = 945
- 10!! = 10 × 8 × 6 × 4 × 2 = 3,840
It is not the factorial of a factorial. Double factorials of odd numbers count the ways to pair up an even number of objects (n + 1 people into pairs), and both kinds appear in the integrals of sinⁿx and in physics formulas for spheres in many dimensions. Excel calls it FACTDOUBLE, and its values match OEIS sequence A006882.
Beyond whole numbers
The factorial is defined only for whole numbers 0, 1, 2 and so on. The gamma function extends it smoothly: Γ(n + 1) = n! for whole n, and Γ(1.5) = √π ÷ 2 gives a meaning to "0.5!". Gamma is undefined at zero and at negative integers, which is why there is no −1!. This calculator sticks to whole numbers, where every digit can be exact.
More questions
How can I find the number of digits in n! without calculating it?
Add up the base-10 logarithms: the number of digits is ⌊log₁₀(1) + log₁₀(2) + … + log₁₀(n)⌋ + 1. For large n, Stirling's formula gives the sum almost exactly: log₁₀(n!) ≈ n·log₁₀(n/e) + ½·log₁₀(2πn). For n = 1,000 that is about 2,567.6, so 1000! has 2,568 digits.
What is the last non-zero digit of a factorial?
It is the digit just before the trailing zeros, and it follows its own pattern: 8 for 10! (3,628,800), 4 for 20! and 4 for 100!. There is no simple closed formula, but you can read it off the full digit list the calculator shows.
Which grows faster, n! or 2ⁿ?
n! wins easily. 2ⁿ doubles at each step, while n! multiplies by n, so from n = 4 onwards n! is larger (24 against 16) and the gap keeps widening. Factorials even outgrow any fixed power base, such as 10ⁿ, once n passes about 25. Only functions like nⁿ grow faster.
Where do factorials appear outside counting problems?
In the Taylor series of eˣ, sin x and cos x, where each term is divided by a factorial; in the Poisson and binomial probability formulas; in statistical mechanics, where Stirling's formula turns ln N! into N ln N − N for very large particle counts; and in the gamma function used throughout calculus and statistics.
Is there a factorial key on a scientific calculator?
Usually, marked n! or x!, often as a second function. It gives a rounded value and overflows above 69! on many handheld models (their limit is 10^100) or 170! on most computers. For more digits, or anything larger, use an arbitrary-precision tool such as this calculator.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.