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:

5 \times 4 \times 3 \times 2 \times 1 = 120

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:

n! = \begin{cases} 1 & \text{if } n = 0 \\[4pt] n \times (n-1) \times (n-2) \times \dots \times 2 \times 1 & \text{if } n \geq 1 \end{cases}

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}.

Growth of n factorial from 1 to 8A bar chart with n on the horizontal axis from 1 to 8 and n factorial on the vertical axis. The bars grow extremely rapidly: 1, 2, 6, 24, 120, 720, 5040, 40320. The last bar is so tall it dominates the chart, illustrating the explosive growth of the factorial function. n n! 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320
The factorial function from $n = 1$ to $n = 8$. The first few values barely register, but $8!$ towers over the rest. Each new bar is roughly $n$ times taller than the previous one — a signature of multiplicative growth.

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:

(n+1)! = (n+1) \times n!

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:

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:

\frac{8!}{6!} = \frac{8 \times 7 \times 6!}{6!} = 8 \times 7 = 56

More generally:

\frac{n!}{(n-r)!} = n \times (n-1) \times \dots \times (n-r+1)

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.

Cancellation of 6 factorial in the fraction 8 factorial over 6 factorialThe expression 8 factorial over 6 factorial is expanded as 8 times 7 times 6 times 5 times 4 times 3 times 2 times 1 over 6 times 5 times 4 times 3 times 2 times 1. The matching factors in the numerator and denominator are crossed out, leaving 8 times 7 equals 56. 8! / 6! = 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 6 × 5 × 4 × 3 × 2 × 1 = 8 × 7 = 56
Cancellation in action. The factors $6 \times 5 \times 4 \times 3 \times 2 \times 1$ appear in both numerator and denominator, leaving only $8 \times 7 = 56$. This is the key algebraic move in every factorial simplification.

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:

(n+2)! = (n+2) \times (n+1) \times n!

So \frac{(n+2)!}{n!} = (n+2)(n+1).

Solving equations. If \frac{n!}{(n-2)!} = 42, what is n?

\frac{n!}{(n-2)!} = n \times (n-1) = 42

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.

Factorial staircase: each step multiplies by the next integerA staircase rising from left to right. Each step is labelled with the factorial value: 0 factorial equals 1, 1 factorial equals 1, 2 factorial equals 2, 3 factorial equals 6, 4 factorial equals 24, 5 factorial equals 120. Arrows between steps are labelled with the multiplier: times 1, times 2, times 3, times 4, times 5. 0!=1 1!=1 2!=2 3!=6 4!=24 5!=120 ×1 ×2 ×3 ×4 ×5
The factorial staircase. Each step multiplies the running product by the next integer. Going from $4! = 24$ to $5! = 120$ means multiplying by $5$. The staircase is the recursion $(n+1)! = (n+1) \times n!$ made visible.

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:

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:

e_p(n!) = \left\lfloor \frac{n}{p} \right\rfloor + \left\lfloor \frac{n}{p^2} \right\rfloor + \left\lfloor \frac{n}{p^3} \right\rfloor + \dots

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.

Legendre formula applied to find the exponent of 2 in 10 factorialA table with four rows. Row 1: floor of 10 over 2 equals 5. Row 2: floor of 10 over 4 equals 2. Row 3: floor of 10 over 8 equals 1. Row 4: floor of 10 over 16 equals 0. The total is 5 plus 2 plus 1 plus 0 equals 8. Each row highlights the multiples being counted. Exponent of 2 in 10! ⌊10/2⌋ = 5 multiples of 2: {2, 4, 6, 8, 10} ⌊10/4⌋ = 2 multiples of 4: {4, 8} ⌊10/8⌋ = 1 multiples of 8: {8} ⌊10/16⌋ = 0 no multiples of 16 ≤ 10 Total = 5 + 2 + 1 + 0 = 8
Legendre's formula for $e_2(10!)$. Each row counts multiples of a higher power of $2$. The sum — $8$ — is the total exponent of $2$ in the prime factorisation of $10!$.

Two worked examples

Example 1: Simplify $\frac{12!}{9! \times 3!}$ and interpret the result

Step 1. Expand 12! using the recursion.

12! = 12 \times 11 \times 10 \times 9!

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.

\frac{12!}{9! \times 3!} = \frac{12 \times 11 \times 10 \times 9!}{9! \times 3!} = \frac{12 \times 11 \times 10}{3!}

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.

3! = 6
\frac{12 \times 11 \times 10}{6} = \frac{1320}{6} = 220

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.

Cancellation in 12 factorial over 9 factorial times 3 factorialA diagram showing the numerator 12 times 11 times 10 times 9 factorial. The 9 factorial portion is crossed out, matching the 9 factorial in the denominator. The remaining fraction is 12 times 11 times 10 over 6, which equals 220. 12! / (9! × 3!) Numerator: 12 × 11 × 10 × 9! Denominator: 9! × 3! After cancellation: (12 × 11 × 10) / 6 = 1320 / 6 = 220
The $9!$ in the numerator and denominator cancel, leaving a small fraction that simplifies to $220$. This cancellation pattern — peeling off the top factors and dividing by a small factorial — is the standard method for computing binomial coefficients.

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.

e_5(100!) = \left\lfloor \frac{100}{5} \right\rfloor + \left\lfloor \frac{100}{25} \right\rfloor + \left\lfloor \frac{100}{125} \right\rfloor + \left\lfloor \frac{100}{625} \right\rfloor + \dots

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.

\left\lfloor \frac{100}{5} \right\rfloor = 20, \quad \left\lfloor \frac{100}{25} \right\rfloor = 4, \quad \left\lfloor \frac{100}{125} \right\rfloor = 0

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.

e_5(100!) = 20 + 4 + 0 = 24

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.

Multiples of 5 and 25 among the integers 1 to 100A number line from 0 to 100. Marks at every multiple of 5 are shown as small red ticks. Marks at multiples of 25 are shown as larger red dots. The count of multiples of 5 is 20, of 25 is 4, giving a total exponent of 24. Multiples of 5 and 25 in {1, …, 100} 0 25 50 75 100 Multiples of 5: 20 (thin ticks + big dots) Multiples of 25: 4 (big red dots only) Exponent of 5 in 100! = 20 + 4 = 24 trailing zeros each thin tick is a multiple of 5, each dot is a multiple of 25
The multiples of $5$ (thin red ticks) and $25$ (large red dots) on the number line from $1$ to $100$. There are $20$ multiples of $5$ and $4$ multiples of $25$. The total exponent of $5$ in $100!$ is $20 + 4 = 24$, which is also the number of 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

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:

n! \approx \sqrt{2\pi n} \left(\frac{n}{e}\right)^n

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:

(n+1)! = (n+1) \times n \times (n-1) \times \dots \times 1 = (n+1) \times [n \times (n-1) \times \dots \times 1] = (n+1) \times n!

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:

(p-1)! \equiv -1 \pmod{p}

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.