Math
Factorial calculator
Factorials outgrow everything. 20! already exceeds what a double-precision float can hold exactly.
The definition
n! is the product of every whole number from 1 up to n. So 5! = 1 × 2 × 3 × 4 × 5 = 120. It counts the number of distinct ways to arrange n items in order: five books on a shelf can be arranged 120 ways.
By convention 0! = 1. That is not arbitrary — there is exactly one way to arrange nothing, the empty arrangement, and defining it as 1 keeps the recurrence n! = n × (n−1)! working at n = 1 and makes the binomial formula behave at its edges.
How fast this grows
Factorial growth outpaces exponential growth comfortably:
- 10! = 3,628,800
- 20! ≈ 2.43 × 1018
- 52! ≈ 8.07 × 1067 — the number of ways to shuffle a deck of cards
- 100! has 158 digits
That 52! figure is worth pausing on. It is larger than the estimated number of atoms in our galaxy. Any well-shuffled deck of cards has, with overwhelming probability, never existed in that order before in human history.
Why this uses big integers
JavaScript numbers are IEEE-754 doubles, exact only up to 253. 21! already exceeds that, so a naive implementation starts returning rounded values while still looking precise — 21! displayed as 51090942171709440000 when the true value ends in 000. Every digit here is computed with BigInt arithmetic, so the output is exact even at 2000!, which has 5,736 digits.
Trailing zeros without computing the factorial
A trailing zero comes from a factor of 10, which needs a 2 and a 5. Factors of 2 are far more plentiful, so the count of trailing zeros is just the number of 5s in the factorisation. Legendre's formula gives it directly:
zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …
For 100!: 20 + 4 + 0 = 24 trailing zeros, found without multiplying anything. This is a common interview question and a genuinely useful shortcut.
Where factorials show up
Permutations and combinations are built from them — nPr = n!/(n−r)! and nCr = n!/(r!(n−r)!). They appear in the Taylor series for ex, sine and cosine, where the factorial in the denominator is what makes the series converge. In algorithm analysis, O(n!) marks the brute-force permutation approach that becomes impossible around n = 15.
For non-integers, the gamma function extends the idea: Γ(n) = (n−1)! for positive integers, but it is defined for fractions and complex numbers too.
Common questions
Why is 0! equal to 1?
There is exactly one way to arrange an empty set. Defining it as 1 also keeps the recurrence n! = n times (n-1)! valid at n = 1, and makes the combination formula work when you choose zero items or all of them.
What is the largest factorial a normal calculator can handle?
Around 170! before a double-precision float overflows to infinity, and exactness is already lost at 21!, which exceeds 2 to the 53rd. This page uses big integers, so every digit is exact up to the 2000! cap.
How do I count trailing zeros without computing the factorial?
Add up n divided by 5, plus n divided by 25, plus n divided by 125, taking the floor each time. For 100! that is 20 + 4 = 24 zeros. Only factors of 5 matter, because factors of 2 are always more plentiful.
Is there a factorial of a decimal?
Not directly, but the gamma function extends the concept to non-integers. It satisfies gamma(n) = (n-1)! for positive whole numbers and is defined for fractions and complex values too.