What a factorial counts
n! is the number of ways to put n distinct objects in order. Line up three books and there are 3! = 6 shelf orders; line up ten and there are 3,628,800. The reasoning is a chain of choices: n candidates for the first position, n − 1 still unused for the second, and so on until one remains. Multiply the choices and you have the factorial.
That interpretation is why factorials appear wherever arrangements are counted. The permutation calculator uses n!/(n−r)! for ordered selections; the combination calculator divides by r! to throw the ordering away. Factorials also sit in the denominators of the Taylor series for ex, sin x and cos x, in the Poisson and binomial probability formulas, and in the coefficients of Pascal's triangle.
The growth is unlike anything else you meet in elementary mathematics. Doubling is exponential and feels fast, but 220 is about a million while 20! is about 2.4 quintillion. Factorial growth outruns every fixed exponential eventually, because each new factor is larger than the last rather than constant. That is precisely why a brute-force search over orderings — the travelling-salesman route, a seating plan, a permutation cipher — becomes impossible somewhere around twenty items no matter how fast the computer.
How this calculator gets every digit right
Ordinary computer arithmetic cannot hold a large factorial. A 64-bit floating-point number represents integers exactly only up to 9,007,199,254,740,991, which 21! already exceeds, and it overflows to infinity entirely above 170!. So this page does not use floating-point multiplication for the value. It stores the running product as an array of seven-digit blocks and multiplies the whole array by each new factor with a carry, exactly the way you were taught long multiplication — which is why 1000! comes back with all 2,568 of its digits accounted for rather than as an overflow.
Three quantities are then read straight off that exact result. The digit count is the length of the string. The trailing zeros are counted from the end of it. And log₁₀ of the value is accumulated as a sum of logarithms while the product is built, which keeps it accurate even for inputs where the value itself is astronomically large.
The trailing-zero count has an elegant shortcut worth knowing, called Legendre's formula. A trailing zero comes from a factor of 10, and each 10 needs a 2 and a 5. Among the numbers 1 to n there are always more factors of 2 than of 5, so the count of fives decides the answer: ⌊n/5⌋ numbers contribute at least one five, ⌊n/25⌋ contribute a second, ⌊n/125⌋ a third, and so on. For n = 100 that is 20 + 4 = 24 zeros. The calculator shows this sum as a step and cross-checks it against the digits it actually produced.
For non-integer input the factorial is replaced by the gamma function, the unique smooth extension satisfying Γ(x + 1) = x·Γ(x) with Γ(1) = 1. It gives Γ(1.5) = √π/2 = 0.886227 for the famous "half factorial", and it is what makes expressions like the volume of an n-dimensional sphere or the density of the chi-square distribution well defined for odd dimensions.
Worked example: 10!, its zeros, and a Stirling check
Compute 10! by hand, then verify it three ways.
- Multiply upward. 1 × 2 = 2; × 3 = 6; × 4 = 24; × 5 = 120; × 6 = 720; × 7 = 5,040; × 8 = 40,320; × 9 = 362,880; × 10 = 3,628,800.
- Count the digits. 3,628,800 has 7 digits, and log₁₀(3,628,800) = 6.5598, so ⌊6.5598⌋ + 1 = 7 as expected.
- Predict the trailing zeros. Legendre's formula gives ⌊10/5⌋ = 2, and ⌊10/25⌋ = 0, so the total is 2. The value ends in "00" — correct.
- Check with Stirling. √(2π × 10) = √62.832 = 7.9267, and (10/e)10 = 3.67879410 = 454,000. Multiplying gives about 3,598,700, which is 0.83% below the true 3,628,800. Stirling's relative error is close to 1/(12n), and 1/120 = 0.833% — a match to two significant figures.
Now push the same machinery to 100!. Legendre's formula gives ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24 trailing zeros. Summing log₁₀ of every factor from 2 to 100 gives 157.97000, so the value has ⌊157.97⌋ + 1 = 158 digits and begins 9.332621544 × 10157. Enter 100 above and all three figures appear without any of the digits being estimated.
How to read the result
Read the digit count first when the number is large. "158 digits" conveys the scale of 100! far better than 158 printed digits do, and it is the figure you actually need when you are deciding whether an algorithm is feasible or whether a data type will hold a value.
Some thresholds worth carrying in your head, each of them a hard boundary in real code. 12! = 479,001,600 is the largest factorial that fits in a signed 32-bit integer. 20! = 2,432,902,008,176,640,000 is the largest that fits in a signed 64-bit integer, and 21! overflows it. 18! is the largest that a double-precision float still represents exactly, because 19! exceeds 253. 170! ≈ 7.26 × 10306 is the largest that a double can hold at all; 171! returns infinity in almost every language that uses IEEE 754. Any of these will silently corrupt a calculation if you cross it in the wrong type.
The trailing-zero count answers a class of contest and interview question by itself, and it also tells you the largest power of 10 that divides n!. Because it grows like n/4 rather than n, roughly a quarter of the digits at the end of a large factorial are zeros: 1000! ends in 249 zeros, which you can verify with ⌊1000/5⌋ + ⌊1000/25⌋ + ⌊1000/125⌋ + ⌊1000/625⌋ = 200 + 40 + 8 + 1.
If you need to compare two enormous factorials, compare the log₁₀ values rather than the numbers. The difference between the logs is the log of the ratio, so a gap of 3 means one is a thousand times the other. That trick is also what keeps the combination calculator honest for large binomial coefficients, where the factorials involved would overflow long before their quotient does.
Factorials from 0! to 20!
| n | n! | Digits | Trailing zeros |
|---|---|---|---|
| 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 0 |
| 2 | 2 | 1 | 0 |
| 3 | 6 | 1 | 0 |
| 4 | 24 | 2 | 0 |
| 5 | 120 | 3 | 1 |
| 6 | 720 | 3 | 1 |
| 7 | 5,040 | 4 | 1 |
| 8 | 40,320 | 5 | 1 |
| 9 | 362,880 | 6 | 1 |
| 10 | 3,628,800 | 7 | 2 |
| 11 | 39,916,800 | 8 | 2 |
| 12 | 479,001,600 | 9 | 2 |
| 13 | 6,227,020,800 | 10 | 2 |
| 14 | 87,178,291,200 | 11 | 2 |
| 15 | 1,307,674,368,000 | 13 | 3 |
| 16 | 20,922,789,888,000 | 14 | 3 |
| 17 | 355,687,428,096,000 | 15 | 3 |
| 18 | 6,402,373,705,728,000 | 16 | 3 |
| 19 | 121,645,100,408,832,000 | 18 | 3 |
| 20 | 2,432,902,008,176,640,000 | 19 | 4 |
Notice that the digit count sometimes jumps by two (14 to 15, 18 to 19) and sometimes not at all — the increase is ⌊log₁₀ n⌋ rounded by where the leading digits happen to fall.
Traps and misconceptions
- Thinking 0! = 0. It is 1. The empty product is 1 the same way an empty sum is 0, and any other value would break C(n, n) = 1 and the series for ex.
- Reading n!! as (n!)!. The double factorial skips alternate terms — 9!! = 945 — while (3!)! = 720. Two exclamation marks never mean apply the operation twice.
- Asking for the factorial of a negative whole number. It does not exist. The gamma function has poles at 0, −1, −2 and every negative integer, so Γ(x) runs to infinity there; only non-integer negatives have a finite value.
- Letting a language overflow silently. 21! wraps around in a 64-bit signed integer and 171! becomes infinity in a double. If your factorial is unexpectedly negative or infinite, you have crossed a type boundary rather than made an arithmetic error.
- Computing n! to get a binomial coefficient. C(52, 5) is under three million, yet 52! has 68 digits. Cancel the factorials symbolically first, or use the multiplicative recurrence.
- Counting trailing zeros with twos. The factors of 5 are always the scarcer of the pair, so only fives are counted. Using twos gives a wildly too-large answer.
- Assuming Stirling's approximation is close enough. Its relative error is about 1/(12n), so it is 8% out at n = 1 and 0.83% out at n = 10. Useful for magnitude, not for exact digits.
Double factorials, gamma and the near neighbours
Several relatives of the factorial turn up often enough to be worth naming.
The double factorial n!! multiplies every second term: 8!! = 8 × 6 × 4 × 2 = 384 and 9!! = 9 × 7 × 5 × 3 = 945. It appears in the closed form for integrals of powers of sine and cosine, and in the volume of an even-dimensional sphere. The two are linked by (2k)!! = 2k · k! and (2k)! = (2k)!! × (2k−1)!!, which is a useful identity when a formula hands you one and you want the other.
The gamma function is the continuous version, and it is what lets a factorial appear in the density of a chi-square or t distribution where the degrees of freedom may be odd. Γ(n + 1) = n! at every whole number, Γ(1/2) = √π, and the reflection formula Γ(x)Γ(1 − x) = π/sin(πx) ties values on either side of the poles together.
The falling factorial n(n−1)…(n−r+1) — sometimes written n(r) or (n)r — is the piece of n! that survives when you divide by (n − r)!. It is the count of ordered selections, and it is what you should actually compute when a formula appears to demand two huge factorials.
Finally, factorials appear in series in a way that is easy to check yourself. e = 1 + 1/1! + 1/2! + 1/3! + … converges to 2.718282 after only eight terms because the denominators grow so fast. If you want to see that growth plotted against ordinary exponential growth, the exponential growth calculator and the scientific notation calculator are the tools for handling the magnitudes involved.
Key terms
- Factorial
- n! — the product of all whole numbers from 1 to n, and the number of orderings of n distinct objects. 0! = 1.
- Double factorial
- n!! — the product of n, n−2, n−4 and so on down to 2 or 1. Not the factorial applied twice.
- Gamma function
- Γ(x), the smooth extension of the factorial to real and complex arguments, with Γ(n + 1) = n! for whole n.
- Legendre's formula
- The count of a prime p in the factorisation of n!, equal to ⌊n/p⌋ + ⌊n/p²⌋ + …. With p = 5 it gives the trailing zeros.
- Stirling's approximation
- n! ≈ √(2πn)(n/e)ⁿ. Excellent for magnitude at large n, with relative error near 1/(12n).
- Empty product
- The product of no factors at all, defined as 1 so that multiplying by it changes nothing. This is what makes 0! = 1.
