Core answer: n! = n × (n−1) × … × 2 × 1 counts the ways to arrange n distinct items in order: 3! = 6, 4! = 24, 5! = 120, 10! = 3,628,800. By convention 0! = 1 (one way to arrange nothing). Factorials grow faster than exponentials — 20! ≈ 2.4×10¹⁸, already beyond 64-bit integers.
Why factorial counts arrangements
Lining up 4 people: 4 choices for the first spot, 3 for the next, 2, then 1 → 4 × 3 × 2 × 1 = 24 orders. Each choice is independent, so the counts multiply (the multiplication principle). This single idea builds permutations P(n,k) = n!/(n−k)! and combinations C(n,k) = n!/(k!(n−k)!).
Growth table (respect the explosion)
| n | n! | Scale |
|---|---|---|
| 5 | 120 | a small meeting |
| 10 | 3.6 M | a city's population |
| 13 | 6.2 B | ~Earth's people |
| 20 | 2.4×10¹⁸ | grains of sand on a beach |
| 52 | 8×10⁶⁷ | card shuffles — more than atoms in the Milky Way |
A properly shuffled deck has almost certainly never existed in that order before in history.
Stirling's approximation (for big n)
n! ≈ √(2πn) × (n/e)ⁿ. Accurate to ~1% already at n = 10, and the only sane way to estimate 100! (≈ 9.33×10¹⁵⁷) or compute with logs: ln(n!) ≈ n ln n − n.
Worked examples
Example 1 — Seating arrangements. 6 guests at a round table: fix one person (rotations are identical) → (6−1)! = 120 arrangements.
Example 2 — Password space. A 4-digit PIN using 4 distinct digits from 0–9: P(10,4) = 10!/6! = 5,040 possibilities.
Example 3 — Anagrams. "LEVEL" has 5!/(2!·2!) = 30 distinct arrangements — divide by repeats (two L's, two E's).
Common mistakes and myths
- "0! = 0" — no, 0! = 1; it's defined so C(n,n) = n!/(n!·0!) = 1 works.
- Factorials of negatives or fractions — undefined for negative integers; fractions use the Gamma function (0.5! = √π/2) — advanced territory.
- Underestimating growth — factorial beats 2ⁿ by n = 4 and beats n¹⁰⁰ eventually; brute-forcing 15-city traveling salesman (15! ≈ 1.3×10¹² routes) is already hopeless.
- Overflow blindness — 13! overflows 32-bit int, 21! overflows 64-bit; use big integers or logarithms in code.
- Double factorial confusion — n!! skips (7!! = 7×5×3×1 = 105), it is NOT (n!)!.