Factorial Calculator: How It Works
The factorial of n is the product of every whole number from 1 to n. It counts the ways a set can be arranged, which is why it sits at the base of combinatorics and probability — and why it grows faster than almost any function you will meet.
Definition
n! = n × (n−1) × (n−2) × … × 2 × 1
5! = 5 × 4 × 3 × 2 × 1 = 120.
By definition 0! = 1. This is not a convention adopted for convenience — there is exactly one way to arrange an empty set (do nothing), and the value keeps the recursive relation n! = n × (n−1)! consistent at n = 1.
How fast it grows
| n | n! |
|---|---|
| 5 | 120 |
| 10 | 3,628,800 |
| 15 | 1,307,674,368,000 |
| 20 | 2,432,902,008,176,640,000 |
| 25 | ≈ 1.55 × 10²⁵ |
| 70 | ≈ 1.20 × 10¹⁰⁰ |
Twenty is where a 64-bit signed integer overflows — 21! no longer fits. Seventy is roughly where a standard double-precision float gives up. A deck of 52 cards has 52! ≈ 8 × 10⁶⁷ possible orderings, which is more than the estimated number of atoms in our galaxy. Every properly shuffled deck has, with overwhelming probability, never existed before.
Permutations and combinations
| Formula | Order matters? | |
|---|---|---|
| Permutations | P(n,r) = n! ÷ (n−r)! | Yes |
| Combinations | C(n,r) = n! ÷ [r!(n−r)!] | No |
Choosing 3 people from 10 for specific roles of chair, secretary and treasurer is a permutation: 10! ÷ 7! = 720. Choosing 3 people for an unranked committee is a combination: 10! ÷ (3! × 7!) = 120. The factor of 6 between them is 3!, the number of ways to order any three chosen people.
This is exactly how lottery odds are computed. Choosing 6 numbers from 49 without regard to order gives C(49,6) = 13,983,816 possible tickets.
Where factorials appear
- Probability — the denominators of most counting problems.
- Taylor series — the expansions of sin, cos and eˣ all divide by factorials.
- Algorithm analysis — O(n!) marks the brute-force travelling salesman approach as infeasible beyond very small inputs.
- Statistics — binomial and Poisson distributions.
Beyond whole numbers
The gamma function extends factorials to non-integers, with Γ(n) = (n−1)! for positive integers. It gives meaning to expressions like (½)!, which equals √π ÷ 2 — a genuinely surprising result linking factorials to π, and one that appears throughout statistics.
Stirling's approximation
For large n, computing a factorial exactly becomes impractical, and Stirling's approximation gives a close estimate: n! ≈ √(2πn) × (n ÷ e)ⁿ. It is accurate to within about 1% by n = 10 and improves from there, which makes it standard in statistical mechanics and asymptotic analysis.