The exclamation mark in 5! is not excitement; it is the factorial sign, and it turns up everywhere from probability homework to scheduling problems. It also grows faster than almost anything else you meet in school maths, which is why calculators give up so quickly and why questions such as "how many zeros are at the end of 100!" are exam favourites.
This guide explains what a factorial is, why 0! is defined as 1, where factorials come from in counting problems, how to count trailing zeros without computing the number, and how to estimate the size of enormous factorials. Every figure below was produced with our calculator.
Definition
For a whole number n ≥ 1, n factorial is the product of all whole numbers from 1 to n:
n! = n × (n − 1) × (n − 2) × … × 2 × 1
So 5! = 5 × 4 × 3 × 2 × 1 = 120, and 10! = 3,628,800.
Each factorial is the previous one times the next number: n! = n × (n − 1)!. That recursive rule is how factorials are computed in practice, and it explains the special case below.
Why 0! = 1
Using n! = n × (n − 1)! with n = 1 gives 1! = 1 × 0!. Since 1! = 1, the only value that works is 0! = 1.
There is also a counting reason. n! is the number of ways to arrange n distinct objects in a row. There is exactly one way to arrange nothing: leave it empty. And formulas such as the number of combinations, n! ÷ (k! × (n − k)!), only give correct answers at the edges (choosing all or none) if 0! = 1.
Factorials are not defined for negative integers. The gamma function extends the idea to fractions and most real numbers, but not to −1, −2, −3 ….
Where factorials come from
Arranging things in order
Eight people can be arranged in a line in 8! = 40,320 ways: 8 choices for the first position, 7 for the second, and so on.
A deck of cards
A standard 52-card deck can be shuffled into 52! different orders, a 68-digit number of about 8.07 × 10⁶⁷. Any thoroughly shuffled deck is almost certainly in an order that has never existed before.
Permutations and combinations
Choosing and arranging k items from n uses n! ÷ (n − k)!. Choosing without caring about order divides again by k!. The Permutation and Combination Calculator applies these formulas directly, and the Probability Calculator builds on them.
How fast factorials grow
| n | n! | Digits |
|---|---|---|
| 5 | 120 | 3 |
| 10 | 3,628,800 | 7 |
| 13 | 6,227,020,800 | 10 |
| 20 | 2,432,902,008,176,640,000 | 19 |
| 25 | 15,511,210,043,330,985,984,000,000 | 26 |
| 100 | ≈ 9.33 × 10¹⁵⁷ | 158 |
| 1,000 | ≈ 4.02 × 10²⁵⁶⁷ | 2,568 |
Two practical consequences. First, 20! is the largest factorial that fits in a standard 64-bit integer, so programs overflow quickly. Second, ordinary calculators and spreadsheets store numbers in floating point, which keeps only 15 to 17 significant digits. From the low twenties onwards, the digits they show for n! are rounded and the tail is not the real one.
Counting trailing zeros (Legendre's formula)
A trailing zero comes from a factor of 10 = 2 × 5. In any factorial there are far more factors of 2 than of 5, so the number of trailing zeros equals the number of factors of 5.
Count them by adding how many multiples of 5, 25, 125 … are at most n:
zeros(n) = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …
The brackets mean "round down". Multiples of 25 contribute a second 5, multiples of 125 a third, and so on. This is a special case of Legendre's formula.
Example: 25! ⌊25/5⌋ + ⌊25/25⌋ = 5 + 1 = 6 trailing zeros. Look at the table: 15,511,210,043,330,985,984,000000.
Example: 100! 20 + 4 = 24 trailing zeros.
Example: 1,000! 200 + 40 + 8 + 1 = 249 trailing zeros.
A common mistake is to stop after dividing by 5, which gives 20 for 100! instead of 24.
Estimating huge factorials (Stirling's formula)
When n! is too large to write out, Stirling's approximation gives its size:
n! ≈ √(2πn) × (n/e)ⁿ
Taking logarithms turns this into an easy sum, and the whole-number part of log₁₀(n!) plus 1 gives the number of digits. For n = 1,000,000, log₁₀(n!) ≈ 5,565,708.9, so one million factorial has 5,565,709 digits.
How to use the Factorial Calculator
- Open the Factorial Calculator.
- Type a whole number into n (whole number).
- For results up to 40 digits, the answer appears in full with digit grouping. For longer results, the card shows scientific notation and a scrollable panel lists every digit, with a button to copy all of them.
- Read the Number of digits, the Trailing zeros and Exact?, which confirms the value was computed exactly with whole-number arithmetic.
- Open the steps to see the product written out (for small n), the Legendre sum for trailing zeros and the digit count.
Exact values are calculated up to 25,000!, which has more than 90,000 digits. From there up to 10¹², the calculator switches to Stirling's formula and gives the digit count, trailing zeros and a scientific-notation estimate.
Other ways to compute factorials
- Spreadsheets:
=FACT(10)returns 3,628,800. Results are floating-point values, so they stop being exact in the low twenties, and 171! and above return an error because 170! is the largest factorial below the floating-point limit. - Programming: Python's
math.factorial(100)is exact at any size because Python integers have no fixed limit. Many other languages need a big-integer library. - Scientific calculators: usually have an x! key, but overflow at 69! or 70! on models limited to 10⁹⁹.
For powers rather than products, the Exponent Calculator gives similarly exact results with every digit.
Common mistakes
Thinking 0! = 0
It is 1, for both the algebraic and the counting reasons above.
Treating (2n)! as 2 × n!
6! = 720, while 2 × 3! = 12. The factorial applies to the whole bracket.
Counting only multiples of 5 for trailing zeros
Multiples of 25, 125 and higher powers add extra fives. Include every term until the division gives 0.
Trusting spreadsheet digits for large n
A spreadsheet's 25! has rounded digits in its tail. Use exact arithmetic when every digit matters.
Frequently asked questions
Why is 0 factorial equal to 1?
Because n! = n × (n − 1)! requires 1! = 1 × 0!, which only works if 0! = 1. It also matches the fact that there is exactly one way to arrange zero objects.
How many trailing zeros does 100! have?
- Count the factors of 5: ⌊100/5⌋ = 20 plus ⌊100/25⌋ = 4 gives 24.
How many digits does 100 factorial have?
158 digits. It is approximately 9.33 × 10¹⁵⁷.
Can you take the factorial of a negative number or a decimal?
Not with the ordinary definition, which needs whole numbers of 0 or more. The gamma function extends factorials to most real numbers, but it is undefined at negative integers.
What is the largest factorial a normal calculator can show?
Most handheld calculators with a 10⁹⁹ limit stop at 69!. Spreadsheets using double-precision numbers stop at 170!, and show only the first 15 or so digits correctly.