Home / Math / Factorial Calculator
Factorial Calculator
Enter a whole number from 0 to 1,000 to get its factorial as an exact integer, along with the number of digits, the number of trailing zeros, scientific notation and how close Stirling's formula comes.
What a factorial is
The factorial of a non-negative whole number n, written n!, is the product of all positive whole numbers up to n: n! = n × (n − 1) × (n − 2) × … × 2 × 1. So 5! = 5 × 4 × 3 × 2 × 1 = 120. By convention 0! = 1, which is the empty product and keeps formulas for arrangements and combinations consistent. Factorials answer the question: in how many different orders can n distinct items be placed in a line? Three items give 3! = 6 orders, and ten items give 10! = 3,628,800.
The double factorial n!! multiplies every second number instead: n!! = n × (n − 2) × (n − 4) × … down to 2 or 1. Thus 10!! = 10 × 8 × 6 × 4 × 2 = 3,840 and 7!! = 7 × 5 × 3 × 1 = 105. It is not (n!)!, a common misreading.
How fast factorials grow
Factorials grow faster than any fixed power or exponential. 20! is 2,432,902,008,176,640,000, which just fits in a signed 64-bit integer, while 21! does not. 100! has 158 digits and 1,000! has 2,568. Ordinary spreadsheet cells and standard double-precision numbers lose exactness once the value exceeds about 9 × 1015, and overflow entirely beyond 170!. This page uses big-integer arithmetic, so every digit shown is exact. Values with more than 200 digits are abbreviated to the leading and trailing digits plus the digit count.
Trailing zeros and Stirling's approximation
Each trailing zero in n! comes from a factor of 10, and each 10 pairs a 2 with a 5. Twos are plentiful, so the count of fives decides it: floor(n/5) + floor(n/25) + floor(n/125) + …. For n = 100 this gives 20 + 4 = 24 trailing zeros. The result row counts them directly from the exact value, and the two methods agree.
For large n, Stirling's formula n! ≈ √(2πn) × (n/e)n gives a quick estimate. It always falls slightly below the true value, with a relative error of roughly 1 ÷ (12n), so it is within about 0.8% at n = 10 and about 0.08% at n = 100.
Where factorials appear
- Permutations: arranging r items chosen from n uses n! ÷ (n − r)!.
- Combinations: choosing r from n without regard to order uses n! ÷ (r! × (n − r)!).
- Probability: counting equally likely orderings, such as shuffled decks, where 52! is roughly 8.07 × 1067.
- Series: terms such as xn ÷ n! build the exponential function and sine and cosine.
Only whole numbers from 0 to 1,000 are accepted. Negative integers have no factorial, and factorials of fractions need the gamma function, which this page does not cover. For powers see the exponent calculator.
Worked example
Compute 25!, the number of ways to arrange 25 distinct items in a row. It already runs to 26 digits.
Inputs
| Whole number n | 25 |
|---|---|
| Type | Factorial n! |
Result
1.551121 × 10^25
| Exact value | 15511210043330985984000000 |
|---|---|
| Number of digits | 26 |
| Trailing zeros | 6 |
| Scientific notation | 1.551121 × 10^25 |
| Stirling approximation error | -0.3328% (the approximation is slightly low) |
Factorials up to 20
| n | n! |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 2 |
| 3 | 6 |
| 4 | 24 |
| 5 | 120 |
| 6 | 720 |
| 7 | 5040 |
| 8 | 40320 |
| 9 | 362880 |
| 10 | 3628800 |
| 11 | 39916800 |
Accuracy note: Results use standard double-precision arithmetic, so very large or very small values may be rounded. Check important results by another method.
Frequently asked questions
What is a factorial?
The factorial of n is the product of all whole numbers from 1 up to n. For example, 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720.
Why is 0 factorial equal to 1?
It is defined as the empty product, and the definition makes formulas for combinations and series work. There is exactly one way to arrange zero items: do nothing.
How many trailing zeros does n! have?
Count the factors of 5: add floor(n/5), floor(n/25), floor(n/125) and so on. For 100! that gives 20 + 4 = 24 trailing zeros.
What is a double factorial?
The double factorial n!! multiplies every second number down from n. So 9!! = 9 × 7 × 5 × 3 × 1 = 945, and 10!! = 10 × 8 × 6 × 4 × 2 = 3,840.
Why does the calculator stop at 1,000?
The exact answer for 1,000! already has 2,568 digits. The limit keeps the page fast while still covering almost all practical uses.
Related calculators
References and sources
- NIST Digital Library of Mathematical Functions, section 5.11: Stirling's formula and the gamma function. Link
- Graham, R., Knuth, D. and Patashnik, O., Concrete Mathematics, chapter 5, on factorials and binomial coefficients.