Factorial Calculator
- 12! means 12 × 11 × … × 2 × 1. Factorials count arrangements: 12 distinct objects can be ordered in exactly 12! ways.
- The exact result has 9 digits. A standard 52-card deck has 52! ≈ 8.07 × 10^67 shuffles, more than atoms in the galaxy.
- Trailing zeros come from factors of 10 = 2 × 5; fives are the scarce ingredient. Legendre's formula counts them: ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ … = 2 for n = 12.
Use this factorial calculator to find n! for any non-negative integer n. The factorial n! is the product of all positive integers up to n, and it counts the arrangements of n distinct objects. By definition, 0! equals 1 (the empty product), which keeps combination formulas consistent. This calculator computes factorials exactly using arbitrary-precision integers, so it works well beyond standard limits. For reference, 5! equals 120 (3 digits, 1 trailing zero), 20! equals 2,432,902,008,176,640,000 exactly (19 digits, 4 trailing zeros) and is beyond the exact range of double-precision arithmetic, and 52! is about 8.07 x 10^67 (68 digits, 12 trailing zeros) — the number of shuffles of a standard deck, more than the atoms in the Milky Way. Note that 170! is the largest factorial representable as a standard double.
The underlying method is the accepted standard for this kind of calculation because arbitrary-precision arithmetic avoids the rounding errors that affect floating-point approaches, delivering an exact integer result every time. Trailing zeros are counted by Legendre's formula: floor(n/5) + floor(n/25) + floor(n/125) + ..., because factors of 5 are scarcer than factors of 2. This page shows the formula, step-by-step workings, worked examples and sources so you can verify every result with confidence.
Worked examples
5! — five objects in a row
120 arrangements, 3 digits, 1 trailing zero. (5)
| 5! exact value | 120 |
| Digits | 3 |
| Trailing zeros | 1 |
| Scientific notation | 1.20 × 10^2 |
20! — beyond ordinary calculator precision
2,432,902,008,176,640,000 exactly — 19 digits and 4 trailing zeros. Double-precision arithmetic quietly rounds the last digits; this page does not. (20)
| 20! exact value | 2,432,902,008,176,640,000 |
| Digits | 19 |
| Trailing zeros | 4 |
| Scientific notation | 2.4329 × 10^18 |
52! — every possible shuffle of a deck
About 8.07 × 10^67 orderings, 68 digits, 12 trailing zeros — more shuffles than atoms in the Milky Way. (52)
| 52! exact value | 8.0658 × 10^67 |
| Digits | 68 |
| Trailing zeros | 12 |
| Scientific notation | 8.0658 × 10^67 |
What a factorial counts
A factorial counts the number of distinct arrangements, or permutations, of a set of objects. When you line up 5 distinct objects, there are 120 possible orders to arrange them in, because 5! equals 120. A factorial calculator makes this relationship immediate: enter n, and you see exactly how many ways n distinct items can be ordered.
The scale grows astonishingly fast. A standard 52-card deck has about 8.07 x 10^67 possible shuffles, because 52! is a 68-digit number with 12 trailing zeros. That count exceeds the number of atoms in the Milky Way, which means virtually every shuffle you produce has never existed before and never will again. Moving to 20 objects, 20! equals 2,432,902,008,176,640,000 exactly, a 19-digit value with 4 trailing zeros that already lies beyond the exact range of double-precision arithmetic.
Trailing zeros arise because factors of 5 are scarcer than factors of 2, so every factor of 5 pairs with a factor of 2 to produce a zero at the end. Legendre's formula counts them: floor(n/5) + floor(n/25) + floor(n/125) + ..., summing the powers of 5 that divide n!. This is why 52! has 12 trailing zeros and 20! has 4.
Two conventions keep the math consistent. First, 0! is defined as 1, the empty product, so combination formulas work without special cases. Second, 170! is the largest factorial representable as a standard double-precision value; beyond that, ordinary floating-point math overflows. This page computes factorials exactly using arbitrary-precision integers, so even 52! and far larger values are returned in full.
Worked examples: 5!, 20! and 52!
A factorial calculator should show not just the final number but also the scale of the result, because factorials grow faster than almost any other common function. The table below pairs each exact value with its digit count and the number of trailing zeros at the end. Remember that n! is the product of all positive integers up to n, and counts the arrangements of n distinct objects, so these numbers describe real combinatorial quantities rather than abstract curiosities.
The jump from 5! to 20! already takes you beyond the exact range of double-precision arithmetic. A standard double can only represent 170! as the largest factorial before overflowing, yet 20! already needs arbitrary-precision integers to display every digit correctly. This page computes factorials exactly with arbitrary-precision integers, so the value shown for 20! is not an approximation or a rounded estimate — it is the precise integer.
The 52! entry demonstrates why exact computation matters. This value, about 8.07 x 10^67, is the number of possible shuffles of a standard 52-card deck. That figure exceeds the number of atoms in the Milky Way, which is why a well-shuffled deck is overwhelmingly likely to be in an order that has never occurred before. Only an arbitrary-precision factorial calculator can display all 68 digits without loss.
Trailing zeros arise because factors of 5 are scarcer than factors of 2, so every factor of 5 pairs with an available factor of 2 to produce a 10. Legendre's formula counts them: floor(n/5) + floor(n/25) + floor(n/125) + ..., summing the powers of 5 that divide the factorial. For 5!, the formula gives floor(5/5) = 1 zero. For 20!, it gives floor(20/5) + floor(20/25) = 4 + 0 = 4 trailing zeros. For 52!, it gives floor(52/5) + floor(52/25) = 10 + 2 = 12 trailing zeros, matching the verified count. Note that 0! is defined as 1, the empty product, which keeps combination formulas consistent even though it produces neither digits nor trailing zeros.
| n | n! value | Digits | Trailing zeros |
|---|---|---|---|
| 5 | 120 | 3 | 1 |
| 20 | 2,432,902,008,176,640,000 | 19 | 4 |
| 52 | ≈ 8.07 × 10^67 | 68 | 12 |
Why exactness matters (and where calculators lie)
A factorial calculator might seem like a straightforward tool, but many calculators quietly produce wrong answers for large inputs. The reason is double-precision arithmetic. Doubles hold integers exactly only to 2^53, and 20! already exceeds that. The exact value of 20! is 2,432,902,008,176,640,000 — 19 digits with 4 trailing zeros — but a standard double cannot represent it without rounding. This page uses arbitrary-precision multiplication, so every factorial shown is exact, not an approximation.
The problem only grows. 52! is about 8.07 × 10^67, a 68-digit number with 12 trailing zeros. It is the number of possible shuffles of a standard deck — more than the atoms in the Milky Way. A calculator that relies on double-precision arithmetic will not even attempt values past 170!, which is the largest factorial representable as a standard double. Beyond that, the result overflows and the calculator returns infinity or an error. Arbitrary-precision integers have no such ceiling, which is why this page computes factorials exactly rather than approximating them.
Exactness also matters for smaller inputs that still trip up floating-point logic. Consider trailing zeros. They are counted by Legendre's formula: floor(n/5) + floor(n/25) + floor(n/125) + ..., because factors of 5 are scarcer than factors of 2. For 5!, the answer is 120 — 3 digits, 1 trailing zero. A calculator that rounds intermediate results may report the wrong digit count even when the overall magnitude looks right. Arbitrary-precision multiplication preserves every digit, so the trailing zeros you see are the trailing zeros that actually exist.
Finally, exactness starts at the base case. 0! is defined as 1, the empty product, which keeps the combination formulas consistent. A calculator that treats 0! as 0 or undefined breaks every formula that depends on it. This factorial calculator handles 0! correctly and carries that exactness through every larger value, using arbitrary-precision integers instead of floating-point approximations.
Trailing zeros and Legendre's formula
When you use a factorial calculator on larger inputs, one of the first things you may notice is a string of zeros at the end of the result. These trailing zeros come from factors of 10, and each 10 is built from one factor of 2 paired with one factor of 5. Since even numbers appear far more often than multiples of 5, the supply of factors of 2 always outpaces the supply of factors of 5. That makes factors of 5 the bottleneck, so counting them tells you exactly how many trailing zeros a factorial has.
Legendre's formula gives the precise method. You add up floor(n/5) + floor(n/25) + floor(n/125) + ..., continuing until the division yields zero. Each term counts multiples of a higher power of 5, ensuring every extra factor contributed by numbers like 25 or 125 is included. The formula works because n! is the product of all positive integers up to n, and each multiple of 5 contributes at least one factor of 5, each multiple of 25 contributes a second one, and so on.
Take 20! as a worked example. Applying Legendre's formula gives floor(20/5) + floor(20/25) = 4 + 0 = 4, so 20! has exactly 4 trailing zeros. The verified value confirms this: 20! = 2,432,902,008,176,640,000, which has 19 digits and ends in 4 zeros. Note that 20! already exceeds the exact range of double-precision arithmetic, so a calculator that relies on doubles will silently lose accuracy before reaching this point.
A larger example is 52!, which Legendre's formula evaluates as floor(52/5) + floor(52/25) + floor(52/125) = 10 + 2 + 0 = 12 trailing zeros. The verified value is about 8.07 x 10^67, a 68-digit number ending in 12 zeros. This is the number of possible shuffles of a standard 52-card deck, a figure larger than the number of atoms in the Milky Way. For reference, 170! is the largest factorial representable as a standard double, while this page computes factorials exactly with arbitrary-precision integers.
How fast factorials explode
Factorials grow faster than exponential functions. Because n! is the product of all positive integers up to n, each step multiplies by an ever-larger factor, so the climb from one factorial to the next gets steeper rather than staying constant. The jump from 5! = 120 (a 3-digit number with 1 trailing zero) to 20! = 2,432,902,008,176,640,000 (a 19-digit number with 4 trailing zeros) already pushes past what standard double-precision arithmetic can represent exactly. By the time you reach 52!, the result is about 8.07 x 10^67 — a 68-digit number with 12 trailing zeros that counts the arrangements of a standard 52-card deck. That figure exceeds the number of atoms in the Milky Way, which illustrates why a factorial calculator must handle arbitrary-precision integers to remain useful for anything beyond modest inputs.
Because exact values become unwieldy so quickly, Stirling's approximation serves as the standard estimation tool for large factorials. It provides a practical way to approximate the logarithm of n! without computing every intermediate product, which matters in fields ranging from statistics to statistical mechanics. The approximation becomes increasingly accurate as n grows, though it never replaces an exact computation when precision is required.
One consequence of this explosive growth is that 170! is the largest factorial representable as a standard double-precision floating-point number. Beyond that threshold, the magnitude overflows the format entirely. This page computes factorials exactly with arbitrary-precision integers, so it is not bound by that floating-point ceiling and can return full results for inputs well above 170.
Trailing zeros in factorials arise from paired factors of 2 and 5 among the integers being multiplied. Because factors of 5 are scarcer than factors of 2, the count of trailing zeros is determined entirely by how many multiples of 5, 25, 125, and higher powers of 5 appear. Legendre's formula captures this as floor(n/5) + floor(n/25) + floor(n/125) + ..., giving a quick way to predict how many zeros a factorial will end with before computing the full number.
Where factorials show up
The most familiar use of a factorial calculator is in counting arrangements. Because n! is the product of all positive integers up to n, it counts the arrangements of n distinct objects. This is the foundation of permutations: if you want to seat 5 people in 5 chairs, there are 5! = 120 possible orderings. Scale up to a standard deck of 52 cards, and 52! is about 8.07 x 10^67 (68 digits, 12 trailing zeros) — the number of possible shuffles, a figure larger than the number of atoms in the Milky Way.
Factorials also drive combinations, where order does not matter. The formula for choosing k items from n is n! divided by the product of k! and (n - k)!. Here 0! plays a key role: 0! is defined as 1 (the empty product), which keeps the combination formulas consistent. Without that definition, choosing all n items or choosing none would break the algebra. Probability theory leans on these same formulas for binomial distributions, hypergeometric counts, and similar problems.
In calculus, factorials appear in the Taylor series for functions such as e^x, where each term's denominator is a factorial. The series grows quickly in the numerator but the factorial in the denominator keeps it manageable, which is why the expansion converges for every real number. Larger factorials become unwieldy fast: 20! = 2,432,902,008,176,640,000 exactly (19 digits, 4 trailing zeros), already beyond the exact range of double-precision arithmetic. In fact, 170! is the largest factorial representable as a standard double; this page computes factorials exactly with arbitrary-precision integers.
When you need factorials for non-integer values, the gamma function provides a continuous extension. It generalizes the factorial so that the curve is defined across the real line (with some gaps), not just at whole numbers. Trailing zeros are a related curiosity: they are counted by Legendre's formula, floor(n/5) + floor(n/25) + floor(n/125) + ..., because factors of 5 are scarcer than factors of 2.
FAQs
What is 20!?
20! equals 2,432,902,008,176,640,000 exactly. It is a 19-digit number with 4 trailing zeros. Factorials grow extremely fast, so 20! is already in the quintillions.
Why is 0! equal to 1?
0! equals 1 by definition as the empty product. This keeps formulas like C(n,0) = 1 consistent. Treating zero factorial as one avoids breaking combinatorial identities and ensures mathematical rules work smoothly.
How many trailing zeros does 52! have?
52! has 12 trailing zeros. Legendre's formula gives the count: floor(52/5) + floor(52/25) = 10 + 2 = 12. Trailing zeros come from factors of 10, which arise from pairs of 5 and 2 in the prime factorization.
What is the largest factorial?
There is no largest factorial, since n! grows without bound. However, 170! is the largest a standard double can hold. This page computes exact values up to 170!.
How many ways can a deck be shuffled?
52! is approximately 8.07 x 10^67. That enormous number means every shuffle ever performed has almost certainly been unique in history. A standard 52-card deck can be arranged in more ways than atoms in the galaxy.
What is the difference between n! and a permutation?
n! counts arrangements of all n objects. P(n,r) = n!/(n-r)! arranges only r of them. Factorial handles complete orderings, while permutations handle partial orderings from a larger set.