Factorials explained: what n! means, why 0! = 1 and how fast it grows
The factorial of a whole number n, written n!, is the product of every whole number from 1 to n: 5! = 5 Γ 4 Γ 3 Γ 2 Γ 1 = 120. It counts the number of ways to arrange n different things in order. By convention 0! = 1. The factorial calculator gives exact values up to 20,000!, and this guide explains the ideas behind them.
What a factorial is
Arrange three books on a shelf. Any of the 3 can go first, either of the remaining 2 second, and the last one third: 3 Γ 2 Γ 1 = 6 orders. The same reasoning for n items gives n!. The first few values are 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120 and 6! = 720. Each factorial is the previous one multiplied by the next number, n! = n Γ (n β 1)!, which is often the easiest way to work them out.
Why 0! equals 1
Three separate arguments give the same answer:
- The pattern: since n! = n Γ (n β 1)!, setting n = 1 gives 1! = 1 Γ 0!, so 0! must be 1.
- Counting: there is exactly one way to arrange nothing, the empty arrangement.
- The empty product: multiplying no numbers together gives 1, the same way adding no numbers gives 0.
It also keeps formulas working. The number of ways to choose all n items from n is n! / (n! Γ 0!), which must be 1.
How fast factorials grow
Factorials grow faster than any power. 10! = 3,628,800, enough to arrange ten people in a different order every second for 42 days. 20! = 2,432,902,008,176,640,000, the largest factorial that fits in a standard 64-bit integer. 52!, the number of ways to shuffle a deck of cards, is about 8.07 Γ 10βΆβ·, a 68-digit number, and 70! is the first factorial larger than a googol, 10ΒΉβ°β°. Standard 64-bit floating point, used by spreadsheets and most programming languages, overflows after 170!, and many handheld calculators stop even earlier, at 69!, just below a googol. The calculator avoids that by using exact whole-number arithmetic, and it also shows the digit count and the value in scientific notation. For exact arithmetic on other huge numbers, there is the big number calculator.
Counting trailing zeros
How many zeros does 100! end in? Each trailing zero comes from a factor of 10 = 2 Γ 5, and there are always more factors of 2 than of 5, so count the 5s. Every multiple of 5 contributes one, every multiple of 25 one more, every multiple of 125 another:
- 100 Γ· 5 = 20 multiples of 5;
- 100 Γ· 25 = 4 multiples of 25;
- 125 is more than 100, so stop.
100! ends in 20 + 4 = 24 zeros, even though it has 158 digits in total. For 1000! the count is 200 + 40 + 8 + 1 = 249.
Stirling's approximation
For large n, multiplying everything out is slow, and Stirling's approximation gives a close estimate: n! β β(2Οn) Γ (n / e)βΏ. For n = 10 it gives about 3,598,696 against the true 3,628,800, only 0.83% low. The relative error shrinks roughly like 1/(12n), so at 100 it is under 0.1%. The calculator shows the approximation and its error next to the exact value. Factorials can even be extended to fractions using the gamma function, where n! = Ξ(n + 1); for example 0.5! = βΟ / 2 β 0.8862. Factorials of negative integers are undefined.
Where factorials are used
Factorials are the backbone of counting problems:
- Permutations, ordered selections: choosing a first, second and third place from 10 runners gives 10 Γ 9 Γ 8 = 720 ways, which is 10! / 7!.
- Combinations, unordered selections: n! / (r! (n β r)!). There are 2,598,960 five-card poker hands, and 13,983,816 ways to pick 6 numbers from 49; Lottery odds explained: how the jackpot probability is calculated, and what it means shows how that turns into odds.
- Series in calculus, such as eΛ£ = 1 + x + xΒ²/2! + xΒ³/3! + β¦
The permutation and combination calculator handles the counting formulas directly. The factorial calculator adds two relatives: the double factorial n!!, which multiplies every other number (7!! = 7 Γ 5 Γ 3 Γ 1 = 105), and the subfactorial !n, the number of ways to rearrange n items so that none stays in its original place (!4 = 9).
Sources and further reading
The claims in this guide rest on these references, which were checked when the guide was last updated. Spotted an error? The contact page says how to report it.