The factorial of a whole number n, written n!, is the product of every whole number from 1 up to n. It shows up constantly in combinatorics — counting permutations, combinations, probabilities, and the number of ways to arrange a set of items — and it grows at an almost unbelievable rate.
This factorial calculator computes n! instantly for any non-negative integer. It also shows you:
- how many digits the result has, and
- how many trailing zeros it ends with.
Type any whole number into the box and the result updates immediately. Because factorials quickly become enormous, the digit count and trailing-zero count are often the only practical way to describe a very large factorial without printing millions of digits on screen.
How to Use
- Enter a Non-Negative Integer (n) in the box. The default is 5, so the page opens showing 5! = 120.
- Optionally enter Divide by m! (default 0) to also compute n! / m! — for example, 10! / 7! = 720, which is the same as P(10,3).
- Optionally enter Also divide by k! (default 0) to also compute n! / (m! x k!), the multinomial-style ratio used when arranging n items with m identical of one kind and k identical of another.
- Read the result card: n! (Exact Result, n <= 20) is the full product for n up to 20. For n above 20, n! overflows the exact-integer range the engine can display, so the exact value and the n!/m! ratios are reported as 0; the Number of Digits and Trailing Zeros still work for any n and are the only practical way to describe a number with millions of digits.
- Negative numbers and fractions are not valid factorial inputs; the engine clamps n to 0, which returns 0! = 1.
The Factorial Formula
By definition,
n! = 1 × 2 × 3 × … × (n − 1) × n
with the special convention that 0! = 1. That last rule looks odd at first, but it keeps the formulas for permutations and combinations consistent: there is exactly one way to arrange zero items, just as there is exactly one way to choose nothing from a set.
A few anchor values are worth memorizing:
- 0! = 1
- 1! = 1
- 2! = 2
- 3! = 6
- 4! = 24
- 5! = 120
- 10! = 3,628,800
- 20! = 2,432,902,008,176,640,000
Notice how fast the result blows up. From 10 to 20 the input only doubles, but the answer grows from about 3.6 million to about 2.4 quintillion — a factor of nearly 670 billion.
This explosive growth is why factorials are the engine behind combinatorics: the number of ways to arrange even a modest deck of cards is already astronomical.
Two derived facts are especially useful:
- Digit count. The number of decimal digits of n! is floor(sum(log10(k) for k = 1..n)) + 1. For n = 1000, n! has 2,568 digits; for n = 1,000,000 it has 5,565,709 digits.
- Trailing zeros. A trailing zero appears every time a factor of 10 (that is, 2 × 5) divides the product. Because factorials always contain more factors of 2 than 5, the number of trailing zeros is exactly how many times 5 divides the product, given by Legendre's formula: sum of floor(n / 5^j). For n = 1,000,000 that sum is 249,998.
Where Factorials Show Up
The factorial is the building block of counting. If you have n distinct items and want to line them up in order, there are n! possible orderings — choose the first item n ways, the second n−1 ways, and so on. From that one idea come:
- Permutations P(n, k) = n! / (n − k)!, the number of ways to pick and arrange k items out of n.
- Combinations C(n, k) = n! / (k! (n − k)!), the number of ways to pick k items when order does not matter.
- Probabilities, such as the chance of one specific ordering winning, which is 1 / n! and quickly drops well below 0.0001%.
For example, shuffling a standard 52-card deck produces one of 52! possible orderings — a number with 68 digits.
The probability that any given shuffled deck is in the exact order you see right now is roughly 1.24 × 10^-68, far below a trillionth of a percent. That is why a well-shuffled deck is almost guaranteed to be an arrangement that has never existed in human history.
Examples
Example 1 — Arranging 5 books on a shelf. You own 5 distinct books and want to know how many ways you can line them up. n = 5 gives 5! = 120 possible orderings. If you also want to choose which 3 of the 5 books to actually put out front, you would use C(5, 3) = 10 — a factorial-based combination, not the full 5!.
Example 2 — Ten runners finish a race. In how many ways can gold, silver, and bronze be awarded to 10 runners?
- The number of full orderings is 10! = 3,628,800.
- The number of top-3 finishes (a permutation factorial) is 10! / 7! = 720.
If a race has 10,000 entrants, the chance of guessing the exact podium order is about 1 in 9.994 × 10^14, or roughly 0.0000000000001% — effectively zero.
Example 3 — Zero factorial. n = 0 returns 0! = 1. This is not a bug: combinatorially, there is exactly one way to arrange nothing, and defining 0! = 1 keeps C(n, 0) = 1, which is the answer you want when you ask "how many ways to choose zero items."
Example 4 — A million factorial. Typing n = 1,000,000 does not print a 5.5-million-digit number on screen (no phone or browser can). Instead the calculator reports that 1,000,000! has 5,565,709 digits and ends with 249,998 zeros. Those two numbers describe the result completely and are computed exactly without ever constructing the giant integer.
FAQ
What is a factorial in simple terms?
A factorial n! means multiply all whole numbers from 1 up to n together. For example, 5! = 1 × 2 × 3 × 4 × 5 = 120. It counts how many ways you can arrange n distinct items in a line.
What is 0 factorial?
0! = 1 by mathematical convention. The reason is combinatorial: there is exactly one way to arrange zero items, and defining 0! = 1 makes the formulas for permutations and combinations work for edge cases like choosing zero items from a set.
Why does my calculator reject negative numbers?
Factorial is mathematically defined only for non-negative integers. There is no meaningful integer product that runs from 1 down to a negative number.
If you type a negative number or a fraction, this engine clamps the input to 0 and returns 0! = 1 rather than a nonsense value. So treat any result for n < 0 as undefined, and enter a whole number 0 or above.
(The continuous Gamma function extends factorial to real numbers, but that is a different tool and is not what this page computes.)
How big does n! get?
Extremely fast. 10! is about 3.6 million, 20! is about 2.4 quintillion, and 100! has 158 digits. By n = 1,000,000 the result has 5,565,709 digits — far more than the number of atoms in the observable universe. That is why this page also reports a digit count instead of trying to print the whole number. The digit count uses Stirling's approximation and is exact for all practical n; at the very largest sizes it can occasionally be off by one digit.
Why does n! end with so many zeros?
Each trailing zero comes from a factor of 10 in the product, and each 10 needs one factor of 2 and one factor of 5.
Since factorials always contain far more factors of 2 than 5, the number of trailing zeros equals the number of times 5 divides the product. It is computed by Legendre's formula: sum of floor(n / 5^j). For n = 1,000,000 that sum is 249,998 trailing zeros.
What is the difference between a factorial, a permutation, and a combination?
A factorial n! counts every possible ordering of n items. A permutation P(n, k) counts ordered selections of k items from n, and equals n! / (n − k)!. A combination C(n, k) counts unordered selections, and equals n! / (k! (n − k)!). The factorial is the raw ingredient; permutations and combinations are factorial ratios tailored to specific counting questions.
Can I compute factorial for a decimal like 5.5?
Not on this page. This calculator handles only whole numbers 0, 1, 2, …; a fractional input is clamped to the nearest lower integer for the product, and the result is not the Gamma-function value Γ(6.5). If you need the continuous extension, use a Gamma function tool instead.
Disclaimer
This factorial calculator is provided for informational purposes only and does not constitute mathematical, statistical, or engineering advice. Results are computed exactly for small non-negative integers; for very large inputs the digit count and trailing-zero count are reported using Legendre's formula and standard logarithm-based estimates. Always verify critical computations independently.