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.