What Is a Factorial
A factorial is the simplest fast-growing function in math. 5 factorial is 120. 10 factorial is 3.6 million. 70 factorial is bigger than the number of atoms in the observable universe.
Key takeaways
- A factorial of a positive integer n, written n!, is the product of every positive integer from 1 up to n, so 5! is 5 x 4 x 3 x 2 x 1 = 120.
- Factorials grow absurdly fast: 10! is 3,628,800, 20! is about 2.4 quintillion, and 70! is roughly 1.2 x 10^100, more than the estimated 10^80 atoms in the observable universe.
- A standard 52-card deck has 52! possible orderings, about 8 x 10^67, which means a thorough shuffle almost certainly produces an ordering that has never existed before and never will again.
- The gamma function extends factorials to non-integers, and it produces surprises like gamma(1/2) = the square root of pi, which means (-1/2)! equals the square root of pi.
- Standard 64-bit integers cannot hold anything past 20!, so beyond that you need arbitrary-precision integers or you compute log(n!) by summing logs, which is what most statistics libraries do internally.
A factorial of a positive integer n is the product of all positive integers from 1 up to n. Written n!. So 5! = 5 × 4 × 3 × 2 × 1 = 120. The exclamation mark notation was introduced by Christian Kramp in 1808 because writing the multiplication out got tedious. The idea is much older than the notation. Indian mathematicians were writing down permutation counts centuries earlier, and Bhāskara II laid out the rules for them in the 12th century.
The way I think about factorials is that they're the simplest function that grows insanely fast. 10! is 3.6 million. 20! is 2.4 quintillion. 70! exceeds the number of atoms in the observable universe. The reason factorials show up everywhere in combinatorics and probability is that counting arrangements naturally involves multiplying down: pick 1 of 5 options, then 1 of 4 remaining, then 1 of 3, and so on.
Plain English
The Definition
Formally:
n! = n × (n − 1) × (n − 2) × ... × 2 × 1
With the special case:
0! = 1
Why is 0! equal to 1? Because the factorial counts the number of ways to arrange a set of n distinct objects, and there's exactly one way to arrange zero objects (the empty arrangement). It also makes the recursive definition consistent: n! = n × (n−1)! works at n = 1 only if 0! = 1.
How Fast Factorials Grow
Some values to give you a feel:
- 5! = 120
- 10! = 3,628,800
- 15! ≈ 1.3 trillion
- 20! ≈ 2.4 quintillion (2.4 × 10¹⁸)
- 52! ≈ 8 × 10⁶⁷ (the number of distinct shuffle orderings of a standard deck of cards)
- 70! ≈ 1.2 × 10¹⁰⁰ (more than the number of atoms in the observable universe, ~10⁸⁰)
Computers running at standard 64-bit integer precision can't store anything past 20!. After that, you need arbitrary-precision integers (BigInteger in Java, big numbers in Python by default).
Why Factorials Show Up
The most common use is counting permutations: the number of ways to arrange n distinct objects in order. If you have 5 books and want to know how many ways you can line them up on a shelf, the answer is 5! = 120. The first slot has 5 choices, the second 4 (one book is gone), the third 3, and so on.
Combinations (where order doesn't matter) use factorials in the formula:
C(n, k) = n! / (k! × (n − k)!)
This is “n choose k,” the number of ways to pick k items from nwhen the order doesn't matter. It's the central object of combinatorics and shows up in everything from poker probabilities to the binomial expansion.
The Famous Card Deck Result
A standard deck of 52 cards has 52! possible orderings, which is roughly 8 × 10⁶⁷. Compare to:
- Number of seconds since the Big Bang: ~4 × 10¹⁷.
- Number of atoms on Earth: ~10⁵⁰.
- Number of atoms in the observable universe: ~10⁸⁰.
52! is bigger than every counting number in cosmology except the universe's atom count. This means: every time you shuffle a deck of cards thoroughly, you're almost certainly producing an ordering that has never existed before in the history of the universe and will never exist again. That's a factorial doing real work.
The Gamma Function
Factorials are defined for non-negative integers. But what about (1/2)! or (2.5)!? The gamma function extends factorials to non-integer values:
Γ(n) = (n − 1)! for positive integers
The gamma function is defined for all complex numbers except non-positive integers, using an integral formula. It satisfies the same recursive relation: Γ(n + 1) = n · Γ(n). So Γ(1/2) = √π, which means (−1/2)! = √π, an unexpected appearance of pi inside a generalized factorial.
Common Identities
Useful relationships:
- n! = n × (n − 1)! The recursive definition.
- (n + 1)! / n! = n + 1 Adjacent factorials cancel cleanly.
- n! / k! = n × (n − 1) × ... × (k + 1) for
k < n. The falling factorial. - Stirling's approximation:
n! ≈ √(2πn) × (n/e)ⁿ. The standard way to estimate factorials for large n without computing them directly.
Where Factorials Appear
Beyond combinatorics:
- Taylor series. Every Taylor expansion has factorials in the denominators (1/n!).
- Probability distributions. Poisson, binomial, hypergeometric distributions all use factorials.
- Counting trees and graphs. Cayley's formula counts labeled trees and uses n^(n-2), which is closely related.
- Quantum mechanics. Hermite polynomials and harmonic oscillator solutions contain factorials.
- Cryptography. Permutation cryptosystems leverage the size of n! for security.
Computing Factorials Efficiently
For programmers: factorials grow so fast that for nearly any real-world calculation, you compute the result symbolically or use the gamma function's logarithmic form. Naive iteration works for n ≤ 20 in 64-bit. Beyond that, use big-integer libraries or compute log(n!) by summing log(k) from 1 to n, which is what most statistics libraries do internally.
Takeaway
n! = n × (n−1) × ... × 2 × 1, with 0! = 1. Factorials grow faster than exponentials and dominate combinatorial counting. They generalize through the gamma function to non-integers. They show up in Taylor series, probability, and combinatorics. The fact that 52! is larger than the number of atoms on Earth is the cleanest way to internalize how fast factorials grow.
The Take
Factorials are one of those concepts that's simple to define and impossible to fully grasp without examples. The card-deck result is the example. Once you accept that one shuffle of one deck produces an arrangement that has likely never existed before in the universe, the rest of factorial math is easier to take seriously. They're the simplest function in math that breaks human intuition about “a really big number.”
Frequently asked questions
- What is a factorial in simple terms?
- A factorial is what you get when you multiply every whole number from 1 up to your number. Write it with an exclamation mark: 5! means 5 x 4 x 3 x 2 x 1, which is 120. The notation was introduced by Christian Kramp in 1808 because writing the multiplication out every time got tedious. The function itself goes back to at least 12th-century Indian mathematicians.
- Why is 0 factorial equal to 1?
- Because a factorial counts the ways to arrange n distinct objects, and there is exactly one way to arrange zero objects: the empty arrangement. It also keeps the recursive definition consistent. n! = n x (n-1)! only works at n = 1 if 0! equals 1. It's a convention, but it's a convention with a real reason behind it.
- How big is 52 factorial?
- 52! is roughly 8 x 10^67, the number of distinct orderings of a shuffled deck of cards. For scale, there have been about 4 x 10^17 seconds since the Big Bang and roughly 10^50 atoms on Earth. It's bigger than every counting number in cosmology except the universe's total atom count of about 10^80.
- What is the gamma function and how does it relate to factorials?
- The gamma function extends factorials to non-integer and complex values. For positive integers, gamma(n) = (n-1)!. It satisfies the same recursion, gamma(n+1) = n x gamma(n), and it is defined everywhere except the non-positive integers. It gives meaning to things like (2.5)! and produces gamma(1/2) = the square root of pi.
- How do you compute large factorials in code?
- Naive iteration only works up to n = 20 in 64-bit integers. Past that you need arbitrary-precision integers, like Java's BigInteger or Python's default big ints. For most real calculations you don't want the exact value at all. You compute log(n!) by summing log(k) from 1 to n, or use Stirling's approximation, n! is approximately the square root of 2*pi*n times (n/e)^n.
- Where do factorials show up outside of math class?
- Factorials drive combinatorics and probability. They count permutations, they sit inside the combinations formula C(n,k) = n! / (k! x (n-k)!), and they appear in Poisson, binomial, and hypergeometric distributions. They also show up in the denominators of every Taylor series, in Hermite polynomials in quantum mechanics, and in permutation cryptosystems that lean on how large n! gets.
Written by
Tech Talk News Editorial
Computer engineering background. Writes about software, AI, markets, and real estate, and the places where the three meet.
More about the author