Factorial Calculator — Calculate n!
Calculate the factorial of any integer from 0 to 170. See the result, number of digits, and trailing zeros. See also Exponent Calculator and Percentage Calculator.
How to Calculate Factorials
The factorial of a non-negative integer n, written as n!, is the product of all positive integers from 1 to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. By convention, 0! = 1. Factorials grow extremely fast — 20! already exceeds 2 quintillion. This calculator handles values up to 170!, which is the largest factorial that fits in a JavaScript floating-point number.
Factorial Formula
n! = n × (n−1) × (n−2) × ... × 2 × 1
0! = 1 (by definition)
1! = 1
Recursive: n! = n × (n−1)!
Trailing zeros in n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ...
Example
10! = ?
10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1
= 3,628,800
Digits: 7 | Trailing zeros: 2
Frequently Asked Questions
Why is 0! equal to 1?
By convention and mathematical consistency. The empty product (multiplying zero numbers together) is defined as 1. This also makes formulas like combinations C(n,0) = n!/0!n! = 1 work correctly.
Why does the calculator stop at 170?
JavaScript uses 64-bit floating-point numbers, which can represent values up to about 1.8 × 10^308. 170! ≈ 7.26 × 10^306 fits, but 171! ≈ 1.24 × 10^309 overflows to Infinity.
How are trailing zeros calculated?
Trailing zeros come from factors of 10, and each 10 = 2 × 5. Since there are always more factors of 2 than 5 in n!, count the factors of 5: ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... For 10!, that's ⌊10/5⌋ = 2 trailing zeros.
What are factorials used for?
Factorials appear in permutations (n! ways to arrange n items), combinations (C(n,k) = n!/(k!(n-k)!)), probability, Taylor series, and many areas of mathematics and computer science.
Solved Examples — Factorials
Example: How many ways can 6 people stand in a line?
Solution:
Step 1: This is a permutation of 6 items = 6!
Step 2: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720
Answer: 720 different arrangements
Example: Calculate C(8, 3) — choosing 3 items from 8
Solution:
Step 1: C(8,3) = 8! / (3! × 5!)
Step 2: = (8 × 7 × 6) / (3 × 2 × 1)
Step 3: = 336 / 6 = 56
Answer: 56 combinations
Example: How many trailing zeros does 25! have?
Solution:
Step 1: Count factors of 5 in 25!
Step 2: ⌊25/5⌋ + ⌊25/25⌋ = 5 + 1 = 6
Step 3: (No need to check 125 since 25/125 < 1)
Answer: 6 trailing zeros
Example: Simplify 12! / 10!
Solution:
Step 1: 12! / 10! = (12 × 11 × 10!) / 10!
Step 2: The 10! cancels out
Step 3: = 12 × 11 = 132
Answer: 132
Practice Questions
Try these on your own:
- Calculate 7! (Answer: 5,040)
- How many trailing zeros does 100! have? (Answer: 24)
- Simplify 15! / 13! (Answer: 210)
- How many ways can a president, VP, and secretary be chosen from 10 candidates? (Answer: P(10,3) = 720)
- Calculate C(10, 4) using factorials (Answer: 210)
- How many digits does 20! have? (Answer: 19 digits)
Common Mistakes to Avoid
A common error is thinking n! means n × something simple — students sometimes confuse 5! with 5 × 1 = 5 instead of 5 × 4 × 3 × 2 × 1 = 120. Another mistake is trying to simplify factorials by canceling incorrectly: n! / (n-1)! = n, not 1. Remember that factorials grow astronomically fast — 10! = 3,628,800, and 20! is already 2.43 × 10¹⁸. When computing combinations or permutations, always simplify before multiplying to avoid overflow. Students also forget that 0! = 1 (not 0) — this is a definition that makes the combinations formula work correctly. Finally, negative factorials are undefined — there is no such thing as (-3)! in standard mathematics.
Key Takeaways
- n! = n × (n-1) × (n-2) × ... × 2 × 1. It counts the number of ways to arrange n distinct items.
- 0! = 1 by definition. Factorials are undefined for negative integers.
- Factorials grow extremely fast: 10! = 3.6 million, 15! = 1.3 trillion, 20! = 2.4 quintillion.
- Combinations formula: C(n,k) = n! / (k! × (n-k)!). Permutations: P(n,k) = n! / (n-k)!.
- Trailing zeros in n! come from pairs of factors 2 and 5 — count factors of 5 since there are always more 2s.
- Use cancellation when dividing factorials: n! / (n-2)! = n × (n-1), avoiding huge intermediate calculations.