Factorial Calculator (n!)
This factorial calculator works out n! — every whole number from n down to 1, multiplied together — and prints it exactly, however long it turns out to be.
5! = 5 × 4 × 3 × 2 × 1 = 120. Simple enough. Then 20! is 2,432,902,008,176,640,000, and 100! is a number with 158 digits, and somewhere in between your phone gave up and started rounding.
Where an Ordinary Calculator Stops
The cut-off is sharper than most people expect, and it is worth knowing exactly where it falls.
20! is 2,432,902,008,176,640,000, and a computer holds that exactly. So does 21!, and so, just, does 22!. What fails first is not the storage but the printing: the true 22! ends 7,680,000, while the figure a machine shows you ends 7,700,000. At 23! the stored value is itself wrong, and at 171! there is nothing left to store — the arithmetic overflows and hands back infinity. A pocket calculator gives up long before any of that, switching to something like 5.109e+19 the moment its ten-digit window fills.
For an estimate that is fine. For a homework answer, a proof, or a counting argument you intend to check, it is useless. This page holds whole numbers from start to finish, so 100! comes back with all 158 of its digits and 1000! with all 2,568.
The Zeros on the End, Counted Without the Number
Here is the part that surprises people. You can say exactly how many zeros 1000! ends in without ever working out 1000!.
A zero on the end means a factor of ten, and ten is two times five. In a factorial there are twos everywhere and fives are comparatively rare, so the fives run out first and it is the fives that decide the count. How many factors of five are hiding in 1000!? Every fifth number contributes one, every twenty-fifth contributes another, and so on:
⌊1000÷5⌋ + ⌊1000÷25⌋ + ⌊1000÷125⌋ + ⌊1000÷625⌋ = 200 + 40 + 8 + 1 = 249
So 1000! ends in 249 zeros. Adrien-Marie Legendre published this in 1808, and it remains the reason a web page can answer the question in a millisecond while a naive program is still multiplying.
100! works out to 20 + 4 = 24 zeros, which is the version that turns up in exams.
The Same Trick Gives the Highest Power of Any Prime
Swap the five for a three and you have answered a different exam favourite: what is the largest power of 3 that divides 100!?
Add the whole-number parts of 100÷3, 100÷9, 100÷27 and 100÷81. That is 33 + 11 + 3 + 1 = 48, so 348 divides 100! and 349 does not.
The working panel on this page prints those exponents for the small primes as a matter of course, which means the answer is already on screen rather than something you have to set up. I have not found another factorial tool that does it, and the question is common enough that the omission is odd.
Why 0! Is 1
This is the single most queried fact about factorials, and the usual answer — "it is defined that way" — is true and unsatisfying.
Two better reasons. First, counting: n! counts the arrangements of n things, and there is exactly one way to arrange nothing, namely to do nothing. Doing nothing is a thing you can do, and there is only one of it.
Second, the recurrence. Every factorial obeys n! = n × (n − 1)!. Put n = 1 and it says 1! = 1 × 0!. Since 1! is 1, the value of 0! has no choice but to be 1 as well. Define it differently and that relationship breaks at the very first step, taking the counting formulas that rely on it down with it.
| Number | Its factorial | Digits |
|---|---|---|
| 0 and 1 | 1 | 1 |
| 10 | 3,628,800 | 7 |
| 20 | 2,432,902,008,176,640,000 | 19 |
| 100 | ends in 24 zeros | 158 |
| 1,000 | ends in 249 zeros | 2,568 |
| 1,000,000 | ends in 249,998 zeros | 5,565,709 |
What Happens Past the Point of Printing
A million factorial has 5,565,709 digits. Set in nine-point type it would fill a few thousand pages, and reading it would tell you nothing at all.
So this page stops printing the value somewhere above ten thousand — and keeps answering. The digit count, the trailing zeros and the prime exponents all come from n directly rather than from the number, so they survive long after the value itself has become useless. Type 1000000 and you will get 5,565,709 digits and 249,998 zeros, both exact, in about the time it takes to press the key.
The Two Inputs This Page Turns Down
Negatives have no factorial, and not in the sense that nobody has worked one out. Run n! = n × (n − 1)! downwards and at zero it demands a division by zero. There is nothing to return.
Fractions are a more interesting refusal. There genuinely is a smooth curve passing through all the factorial values, called the gamma function, and 4.5 sits on it at roughly 52.34. But that is a different function with a different formula, and handing back its value under a factorial sign would be quietly misleading. The page says what the object is called and leaves you to go and look at it properly.
Where Factorials Actually Get Used
Almost nobody needs a bare factorial. What they need is a factorial inside something else.
Arrangements of r items from n come out as n! divided by (n − r)!, which the permutation calculator handles; divide that by r! as well and you have the selection count on the combination calculator. Both of those pages cancel the factorials against each other rather than building them, which is the only sane way to do it once n passes a few hundred. Factorials also run through Taylor series, through probability, and through most of the counting arguments you meet after school.
How to Use This Factorial Calculator
Type the number and press =. A trailing exclamation mark is ignored if you write one, and commas are read, so 1,000 and 1000 behave the same. AC empties the box; holding ⌫ deletes digit after digit.
Show the working opens the product, the digit count, Legendre's sum written out term by term, the prime exponents and the last non-zero digit. Before any of it appears the result is put back through the mathematics: n! is rebuilt as n × (n − 1)!, the predicted zero count is compared against the zeros actually sitting on the end of the number, and for smaller n the prime factorisation is multiplied back out to see whether it returns what it started from. The number of checks that passed is printed with the working.
Factorial Calculator FAQ
What is a factorial?
Why is 0! equal to 1?
How many digits does 1000 factorial have?
How many trailing zeros does 100! have?
What is the largest power of 3 that divides 100!?
Can you take the factorial of a negative number?
What is the factorial of a decimal such as 4.5?
Why does my calculator show 9.33e+157 for 100!?
Multiply downwards to get the number; divide n by five, then twenty-five, then a hundred and twenty-five, to know how it ends.