Understanding the factorial calculator — concept and principle
The factorial of a whole number n, written n!, is the product of all whole numbers from 1 to n. It counts the number of ways to arrange n different objects in a row, so it sits at the heart of permutations, combinations, probability and series expansions. This calculator gives n! exactly up to 25!, in scientific notation for larger n, the number of digits in n!, and the double factorial n!!.
How it is calculated
- Factorial: n! = 1 × 2 × 3 × … × n, with 0! = 1.
- Number of digits: ⌊log₁₀(n!)⌋ + 1, computed from ln(n!) so that huge factorials need not be written out.
- Double factorial: n!! = n × (n − 2) × (n − 4) × …, stopping at 2 for even n or 1 for odd n.
n must be a whole number from 0 up to 1,000,000; the double factorial is shown for n up to 60.
The principle
To arrange n distinct items, there are n choices for the first position, n − 1 for the second, and so on down to 1 for the last. Multiplying the choices gives n!. The rule n! = n × (n − 1)! also explains why 0! = 1: since 1! = 1 × 0!, 0! must be 1, and there is exactly one way to arrange nothing. Factorials grow faster than any exponential function. Stirling's approximation, n! ≈ √(2πn) (n/e)ⁿ, describes that growth and is already within about 0.4% at n = 20.
Worked example
- Input: n = 20.
- Multiply 1 × 2 × … × 20 = 2432902008176640000 (about 2.43 × 10¹⁸).
- log₁₀(20!) ≈ 18.386, so the number of digits is ⌊18.386⌋ + 1 = 19.
- Double factorial: 20!! = 20 × 18 × 16 × … × 2. Each factor is 2 times a number from 1 to 10, so 20!! = 2¹⁰ × 10! = 1,024 × 3,628,800 = 3715891200.
| n | n! |
|---|---|
| 5 | 120 |
| 10 | 3628800 |
| 15 | 1307674368000 |
| 20 | 2432902008176640000 |
| 25 | 15511210043330985984000000 |
| 30 | 2.65252860e+32 |
| 40 | 8.15915283e+47 |
How to read the result
The digit count shows how quickly factorials explode: 10! already has 7 digits, 20! has 19 and 100! has 158. 20! is the number of orders in which 20 people can stand in a queue. Above 25! the calculator switches to scientific notation, so only the leading digits are shown.
Common mistakes
- Thinking 0! = 0; by definition it is 1.
- Reading n!! as (n!)!; the double factorial skips every other number and is much smaller than n!.
- Applying the factorial to negative numbers or fractions; for those the gamma function, with Γ(n + 1) = n!, is used instead.
- Cancelling factorials incorrectly: 10! ÷ 8! is 10 × 9 = 90, not 10 ÷ 8.
Frequently asked questions
Why is 0 factorial equal to 1?
It keeps the rule n! = n × (n − 1)! consistent and matches the fact that there is one way to arrange an empty set, which also makes formulas such as nC0 = 1 work.
How many trailing zeros does n! have?
Count the factors of 5: ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …. For 20! that is 4, matching the four zeros at the end of 2432902008176640000.
Is there a factorial of a decimal number?
Not in the counting sense, but the gamma function extends it; for example Γ(1.5) = (0.5)! = √π ÷ 2 ≈ 0.8862.
Sources: Donald E. Knuth, The Art of Computer Programming, Vol. 1, §1.2.5 (Permutations and Factorials) · NIST Digital Library of Mathematical Functions, §5.11 (Stirling's series for the gamma function)