In short
The factorial of a non-negative integer n, written n!, is the product n \times (n-1) \times (n-2) \times \dots \times 2 \times 1. By convention, 0! = 1. The factorial counts the number of ways to arrange n distinct objects in a line. It satisfies the recursion (n+1)! = (n+1) \times n!, which is the key to most factorial manipulations. For any prime p, the exponent of p in the prime factorisation of n! is given by Legendre's formula: \sum_{k=1}^{\infty} \lfloor n/p^k \rfloor.
You have 5 books on a shelf — a maths textbook, a physics textbook, a chemistry textbook, a novel, and a dictionary. You want to rearrange them. In how many different orders can the 5 books stand?
For the first position, you have 5 choices. Once you place a book there, 4 remain for the second position. Then 3, then 2, then 1. By the multiplication principle:
That product — 5 \times 4 \times 3 \times 2 \times 1 — appears so often in mathematics that it has its own notation: 5!, read "five factorial." Every time you arrange n distinct objects in a row, the answer is n!. Every time you count the ways to fill n slots where the choices shrink by one at each step, n! appears. The exclamation mark is not hyperbole — it is earned. Factorials grow faster than exponentials, faster than polynomials, faster than almost anything you have seen so far.
Definition of n!
Factorial
For any non-negative integer n:
Equivalently, n! is the product of all positive integers from 1 to n.
The first few values:
| n | n! |
|---|---|
| 0 | 1 |
| 1 | 1 |
| 2 | 2 |
| 3 | 6 |
| 4 | 24 |
| 5 | 120 |
| 6 | 720 |
| 7 | 5{,}040 |
| 8 | 40{,}320 |
| 9 | 362{,}880 |
| 10 | 3{,}628{,}800 |
By 10! you already have over three million — roughly the population of Jaipur. By 15! the value exceeds one trillion. By 20! it is larger than the number of grains of sand on Earth (estimated at about 10^{18}), since 20! = 2{,}432{,}902{,}008{,}176{,}640{,}000 \approx 2.4 \times 10^{18}.
Why 0! = 1. This is not a trick and not arbitrary. There is exactly one way to arrange zero objects: do nothing. The empty arrangement exists — it is the unique sequence of length 0. Defining 0! = 1 also makes every factorial formula consistent. For instance, the recursion (n+1)! = (n+1) \times n! gives 1! = 1 \times 0!, so 0! must be 1 for the formula to hold at n = 0. The number of subsets of a set with n elements is 2^n, and the formula for choosing 0 elements from n is \binom{n}{0} = \frac{n!}{0! \cdot n!}, which equals 1 only when 0! = 1. Every algebraic and combinatorial road leads to the same answer.
Properties of the factorial
Recursive property. The most useful single fact about factorials:
This follows directly from the definition: (n+1)! = (n+1) \times n \times (n-1) \times \dots \times 1 = (n+1) \times n!. It works for all n \geq 0:
- 1! = 1 \times 0! = 1 \times 1 = 1
- 2! = 2 \times 1! = 2 \times 1 = 2
- 3! = 3 \times 2! = 3 \times 2 = 6
- 4! = 4 \times 3! = 4 \times 6 = 24
The recursion is how you compute factorials step by step, and it is how you simplify factorial expressions algebraically.
Cancellation. The recursion lets you cancel common factorial factors in fractions. For instance:
More generally:
This is a product of r consecutive integers descending from n. It appears constantly in permutations.
Divisibility. n! is divisible by every integer from 1 to n, because each of those integers appears as a factor in the product. In fact, n! is divisible by the product of any k consecutive integers from 1 to n.
The recursion (n+1)! = (n+1) \times n!
The recursion deserves its own section because it is the single most-used tool for working with factorials.
Simplifying ratios. Express \frac{(n+2)!}{n!} in terms of n:
So \frac{(n+2)!}{n!} = (n+2)(n+1).
Solving equations. If \frac{n!}{(n-2)!} = 42, what is n?
So n(n-1) = 42. This gives n^2 - n - 42 = 0, which factors as (n-7)(n+6) = 0. Since n must be a positive integer, n = 7.
Check: \frac{7!}{5!} = 7 \times 6 = 42. Correct.
Building the staircase. Every value of n! is built from the previous one by a single multiplication. Think of it as a staircase: to go from n! to (n+1)!, you multiply by (n+1). To go backwards — from (n+1)! to n! — you divide by (n+1). The recursion is the single step of the staircase, and the full factorial is the result of climbing from 0! = 1 all the way up to n.
Exponent of a prime in n!
Here is a question that connects factorials to number theory: what is the highest power of a prime p that divides n!?
Take 10! and the prime 2. The product 10! = 1 \times 2 \times 3 \times 4 \times 5 \times 6 \times 7 \times 8 \times 9 \times 10 contains several factors of 2:
- Multiples of 2 in \{1, \dots, 10\}: 2, 4, 6, 8, 10 — that is \lfloor 10/2 \rfloor = 5 numbers, contributing at least one factor of 2 each.
- Multiples of 4 = 2^2: 4, 8 — that is \lfloor 10/4 \rfloor = 2 numbers, contributing an extra factor of 2 each.
- Multiples of 8 = 2^3: 8 — that is \lfloor 10/8 \rfloor = 1 number, contributing yet another extra factor of 2.
- Multiples of 16 = 2^4: none in \{1, \dots, 10\}, so \lfloor 10/16 \rfloor = 0.
Total exponent of 2 in 10!: 5 + 2 + 1 + 0 = 8.
Check: 10! = 3{,}628{,}800 = 2^8 \times 3^4 \times 5^2 \times 7. The exponent of 2 is indeed 8.
This method works for any prime p and any n, and it is called Legendre's formula.
Exponent of a prime $p$ in $n!$ (Legendre's formula)
The largest power of a prime p that divides n! is:
The sum is finite because \lfloor n/p^k \rfloor = 0 once p^k > n.
Why it works. Each term \lfloor n/p^k \rfloor counts how many integers from 1 to n are divisible by p^k. Each such integer contributes at least k factors of p to the product n!. But counting "multiples of p" already counted one factor from each; counting "multiples of p^2" adds the second factor, and so on. The sum adds up all the contributions without double-counting.
Two worked examples
Example 1: Simplify $\frac{12!}{9! \times 3!}$ and interpret the result
Step 1. Expand 12! using the recursion.
Why: the recursion (n+1)! = (n+1) \times n! applied three times peels off the factors 12, 11, 10 and leaves 9! in the remaining product.
Step 2. Cancel 9! in numerator and denominator.
Why: since 9! appears as a factor in both numerator and denominator, it cancels completely, just as \frac{6a}{3a} = 2.
Step 3. Compute 3! and simplify.
Why: 12 \times 11 = 132, then 132 \times 10 = 1320, then 1320 \div 6 = 220. The division by 3! is exact — the numerator is always divisible by 3! in expressions of this form.
Step 4. Interpret the result.
The expression \frac{12!}{9! \times 3!} is the binomial coefficient \binom{12}{3}, which counts the number of ways to choose 3 objects from 12 without regard to order. So there are 220 ways to pick 3 items from 12.
Result. \frac{12!}{9! \times 3!} = 220.
The number 220 is the answer to every "choose 3 from 12" question: 12 students and you want to pick a team of 3; 12 colours and you want a palette of 3; 12 toppings and you want 3 on your pizza. The formula \frac{n!}{r! \times (n-r)!} handles them all.
Example 2: Find the exponent of $5$ in $100!$ (and hence the number of trailing zeros in $100!$)
Step 1. Apply Legendre's formula with p = 5 and n = 100.
Why: each term counts the integers from 1 to 100 that are divisible by 5^k, adding one extra factor of 5 for each.
Step 2. Compute each floor.
All higher powers of 5 exceed 100, so the remaining terms are all 0.
Why: there are 20 multiples of 5 up to 100 (5, 10, 15, \dots, 100), 4 multiples of 25 (25, 50, 75, 100), and no multiples of 125.
Step 3. Sum.
Why: Legendre's formula says the total exponent is the sum of these floor values. Each multiple of 5 contributed one factor of 5 (counted in the first term), each multiple of 25 contributed an extra factor (counted in the second term), and no number contributed a third extra factor.
Step 4. Connect to trailing zeros.
A trailing zero is produced by a factor of 10 = 2 \times 5. Since factors of 2 are more abundant than factors of 5 in 100! (the exponent of 2 is much larger — it is 97), the number of trailing zeros is determined by the scarcer factor, which is 5.
Result. 100! has exactly 24 trailing zeros.
The trailing-zeros problem is a classic JEE question, and Legendre's formula turns it into a short calculation. The scarcer prime (5) always determines the count, because every factor of 10 needs one 2 and one 5, and there are always more factors of 2 than 5 in n!.
Common confusions
-
"0! should be 0 because there is nothing to multiply." The product of no numbers is 1 (the empty product), not 0. This is the same convention that makes x^0 = 1 in exponents and powers — the empty product is the multiplicative identity.
-
"n! means n multiplied by itself." No — n! is the product of all integers from 1 to n, not n \times n = n^2. So 4! = 4 \times 3 \times 2 \times 1 = 24, not 4 \times 4 = 16.
-
"(a + b)! = a! + b!." This is almost never true. 3! + 2! = 6 + 2 = 8, but (3 + 2)! = 5! = 120. The factorial does not distribute over addition.
-
"(a \cdot b)! = a! \cdot b!." Also false in general. (2 \cdot 3)! = 6! = 720, but 2! \cdot 3! = 2 \times 6 = 12.
-
"The number of trailing zeros in n! is \lfloor n/10 \rfloor." Close but wrong. The correct answer uses Legendre's formula with p = 5: you need \lfloor n/5 \rfloor + \lfloor n/25 \rfloor + \lfloor n/125 \rfloor + \dots, because multiples of 25, 125, etc. contribute extra factors of 5. For n = 100, \lfloor 100/10 \rfloor = 10 but the correct answer is 24.
-
"Factorials are only defined for positive integers." Standard factorials are defined for non-negative integers (so 0! is included). There is an extension to non-integer and even complex inputs called the Gamma function, where \Gamma(n+1) = n! for non-negative integers, but that is beyond the scope of this article.
Going deeper
If you have the definition, the recursion, the cancellation technique, and Legendre's formula, you are fully equipped for permutations and combinations. The rest of this section is for readers who want to see how fast factorials grow and how the factorial connects to deeper mathematics.
Stirling's approximation
For large n, computing n! exactly is impractical — the numbers are enormous. But an excellent approximation exists:
This is Stirling's formula. For n = 10: \sqrt{20\pi} \cdot (10/e)^{10} \approx 7.926 \times 3{,}628{,}800 / 3{,}628{,}800 \approx 3{,}598{,}696, while 10! = 3{,}628{,}800 — the approximation is off by about 0.8\%. The accuracy improves as n grows. Stirling's formula shows that n! grows roughly like (n/e)^n, which is faster than a^n for any fixed base a — factorial growth dominates exponential growth.
Proof by induction that n! = n \times (n-1)!
The recursion is so obvious from the definition that it barely needs a proof, but writing one anyway is good practice with mathematical induction.
Base case: n = 1. The claim is 1! = 1 \times 0!. Indeed, 1! = 1 and 1 \times 0! = 1 \times 1 = 1.
Inductive step: Assume n! = n \times (n-1)! holds for some n \geq 1. Then:
The step follows directly from the definition of (n+1)! as the product of all integers from 1 to n+1. The inductive hypothesis was used to identify the bracketed portion as n!.
Wilson's theorem: a connection to primes
Here is a surprising link between factorials and primes. An integer p > 1 is prime if and only if:
For example, 4! = 24 \equiv -1 \pmod{5} (since 24 = 5 \times 5 - 1), confirming that 5 is prime. And 5! = 120 \equiv 0 \pmod{6} (since 120 = 6 \times 20), confirming that 6 is not prime. Wilson's theorem is beautiful but computationally useless for testing primality, because computing (p-1)! is harder than simply checking divisibility. Its value is theoretical — it shows that the factorial carries deep structural information about primes.
Where this leads next
The factorial is a building block for the entire combinatorics sequence.
- Permutations — Basics — the formula {}^nP_r = \frac{n!}{(n-r)!} is a direct application of the factorial and the multiplication principle.
- Fundamental Principle of Counting — the article that built the multiplication principle, which is the reason n! counts arrangements.
- Exponents and Powers — where the law a^0 = 1 mirrors the convention 0! = 1, both as empty products.
- Number Theory Basics — Legendre's formula connects the factorial to prime factorisation, and Wilson's theorem links it to primality.
- Mathematical Induction — the technique for proving factorial identities rigorously, including the recursion itself.