Factorial Calculator
n! — the product of every whole number from 1 to n. With step-by-step expansion, real-life examples, a log-scale growth visual, and Stirling's approximation for huge n.
Factorial — n!
Related Calculators
Factorial Calculator — n! with full expansion + growth visual
Enter any non-negative integer up to 170 and the calculator returns n! — the product of every whole number from 1 to n. The show-your-work section expands the full multiplication (for n ≤ 12), so you see the math, not just the answer. The bar chart visualizes how factorial growth explodes on a log scale — useful intuition before you trust the number. For large n the result is shown in compact scientific notation (with a "show full digits" expander) and we surface Stirling's approximation alongside, so you can sanity-check the magnitude.
Factorial is the building block of combinatorics. Once you have n! comfortably, the formulas for combinations, permutations, and probability stop being scary.
Where factorials show up in the real world
Factorial isn't an abstract toy — it appears any time you count distinct orderings, divide by the number of arrangements that don't matter, or expand a smooth function into a power series.
Counting arrangements
5 books on a shelf → 5! = 120 orders. 7 people in a line → 5,040 queues. Anagrams of an all-distinct-letters word.
Probability denominators
Card-shuffling probabilities, lottery odds, draw-without-replacement problems often look like favorable-arrangements / n!.
Combinations & permutations
Both build on factorial: C(n, r) = n! / (r! × (n−r)!), P(n, r) = n! / (n−r)!. Pascal's triangle entries are factorials in disguise.
Taylor series
e^x = Σ x^n / n!, sin(x) = x − x³/3! + x⁵/5! − …, cos(x) = 1 − x²/2! + x⁴/4! − …. Factorials in the denominator make these series converge fast.
Algorithm analysis
Brute-force tour orderings for the Travelling Salesman: 10 cities → 3.6M tours, 20 cities → 2.4 quintillion. n! is the gold standard "this approach does not scale".
Statistical mechanics
Counting microstates of a system with indistinguishable particles uses N! / (n₁! n₂! …). Boltzmann's entropy formula relies on it.
Precision — what changes around n = 18 and n = 170
JavaScript represents numbers as 64-bit floats, which can hold integers exactly up to 2^53 ≈ 9 × 10^15. That's enough for 18! exactly:
- n ≤ 18: result is exact to the last digit.
- 19 ≤ n ≤ 170: result is approximate. The magnitude is correct, but the last few digits may drift. We flag this with a warning.
- n ≥ 171: 170! is about 7.3 × 10^306. Beyond that JavaScript overflows to Infinity — the calculator errors out.
For most homework and competition problems, n stays comfortably below 18.
Stirling's approximation — when n! is too big to write out
Computing 100! by hand is hopeless. Computing it on a 64-bit float is barely possible and only approximate. Mathematicians use Stirling's formula:
A closed-form expression — no multiplication chain. Yet it's accurate. The relative error is roughly 1 / (12n), so:
- n = 9 → error already under 1%.
- n = 84 → error under 0.1%.
- n = 170 → error around 0.049%.
Stirling shows up everywhere: in big-O / asymptotic analysis (proving n! grows super-exponentially), in information theory (entropy of distributions over n outcomes), in statistical mechanics (Boltzmann's H-theorem), and in any "log of a binomial coefficient" calculation. If you're going to remember one formula about factorials beyond the definition, Stirling is the one.
A more accurate version with a correction term is n! ≈ √(2πn) × (n/e)^n × (1 + 1/(12n)) — picks up the leading correction in the asymptotic series and shrinks the error to O(1/n²).
Quick reference — common factorials at a glance
| n | n! | Notes |
|---|---|---|
| 0 | 1 | by convention |
| 1 | 1 | trivial |
| 5 | 120 | 5 books on a shelf |
| 10 | 3,628,800 | 10-digit code, no repeats |
| 12 | 479,001,600 | last that fits in a 32-bit int |
| 18 | 6.4 × 10^15 | last exact in a 64-bit float |
| 20 | 2.4 × 10^18 | already approximate |
| 52 | 8.1 × 10^67 | deck of cards |
| 170 | 7.3 × 10^306 | last that fits in a double |
Frequently asked questions
What is a factorial?
▾
What is a factorial?
▾n! (read 'n factorial') is the product of every whole number from 1 to n. 5! = 5 × 4 × 3 × 2 × 1 = 120. It tells you the number of ways to arrange n distinct items in a row — the first slot has n choices, the next has n−1, and so on.
Why does 0! equal 1?
▾
Why does 0! equal 1?
▾By convention. There is exactly one way to arrange zero items (the empty arrangement), so 0! = 1. The convention also keeps formulas like C(n, r) = n! / (r! × (n−r)!) consistent at the boundaries: C(n, 0) = n!/(0! × n!) = 1, and C(n, n) = n!/(n! × 0!) = 1, which is what we want.
How big does n! get before JavaScript can't handle it exactly?
▾
How big does n! get before JavaScript can't handle it exactly?
▾Around n = 18. JavaScript represents numbers as 64-bit floats, which hold integers exactly up to 2^53 ≈ 9 × 10^15. 18! = 6,402,373,705,728,000 fits; 19! does not (19! ≈ 1.2 × 10^17, which is bigger than 2^53). For larger n the calculator still returns a value, but the LAST FEW DIGITS may drift. The MAGNITUDE is correct.
When does n! overflow entirely?
▾
When does n! overflow entirely?
▾At n = 171. 170! is about 7.3 × 10^306, which still fits in a double. 171! exceeds Number.MAX_VALUE and becomes Infinity. The calculator errors out for n > 170.
Why does factorial grow so fast?
▾
Why does factorial grow so fast?
▾Each new item gets to choose ANY remaining position — multiplicative growth, not additive. 5! = 120 but 10! = 3,628,800 (30,000× larger). 20! is over 2 quintillion. The log-scale visual on this page shows the explosion.
When do I actually use a factorial?
▾
When do I actually use a factorial?
▾Whenever you're counting arrangements where order matters AND you're using every item. Books on a shelf (5 books → 5! = 120 orders), people in a queue (7 people → 7! = 5,040 queues), letters in a word (anagrams of a word with all-distinct letters). When only some of the items are used, you want a permutation P(n, r) instead — see the Permutations calculator.
Where does factorial appear in other formulas?
▾
Where does factorial appear in other formulas?
▾Heavily. Combinations C(n, r) = n! / (r! × (n−r)!), permutations P(n, r) = n! / (n−r)!, the Taylor series for e^x = Σ x^n / n!, the binomial theorem coefficients, and many more. Factorial is the building block of combinatorics.
What is Stirling's approximation?
▾
What is Stirling's approximation?
▾Stirling's formula gives a closed-form estimate for n! that is astonishingly accurate: n! ≈ √(2πn) × (n/e)^n. The relative error shrinks as 1/(12n) — under 1% by n = 9, under 0.1% by n = 84. Mathematicians use it whenever they need the magnitude of n! without the last digits, especially in asymptotic analysis (big-O proofs, information theory, statistical mechanics).
How accurate is Stirling for, say, 50!?
▾
How accurate is Stirling for, say, 50!?
▾50! ≈ 3.041 × 10^64 exactly. Stirling gives 3.036 × 10^64 — about 0.17% low. By 170! the relative error is roughly 1/(12 × 170) ≈ 0.049%. For homework and most engineering work, Stirling is plenty.
How big is 52! (a deck of cards)?
▾
How big is 52! (a deck of cards)?
▾52! ≈ 8.07 × 10^67. To put that in perspective: it is more than the number of atoms on Earth (≈ 10^50), more than the number of atoms in our galaxy. Every reasonable shuffle of a deck of cards has almost certainly never occurred before in human history.
How do I compute n! by hand?
▾
How do I compute n! by hand?
▾For small n you can multiply: 6! = 6 × 5! = 6 × 120 = 720. For larger n, use Stirling for an estimate, or use a programming language that supports big integers (Python's int, Java's BigInteger). Spreadsheets like Excel have a FACT(n) function but error out around n = 170 for the same float-overflow reason.
What's the difference between factorial, permutation, and combination?
▾
What's the difference between factorial, permutation, and combination?
▾Factorial n! arranges all n items where order matters. Permutation P(n, r) arranges r-out-of-n items where order matters. Combination C(n, r) chooses r-out-of-n items where order does NOT matter. P(n, r) = n! / (n−r)! and C(n, r) = P(n, r) / r! — both build on factorial.
Why is the result called "approximate" for large n?
▾
Why is the result called "approximate" for large n?
▾JavaScript uses IEEE 754 double-precision numbers, which are exact for integers up to 2^53 ≈ 9.007 × 10^15. 19! is the first factorial that exceeds this, so from there on the integer is rounded to the nearest representable double. The magnitude (how many digits) and the leading digits are right — only the trailing digits drift. The 'approximate' badge tells you when you've crossed that line.
Where to next?
Factorial is one of three counting tools — combinations and permutations build on it.