Home › Blog › Why Does 20! Break a Regular Calculator?
Why Does 20! Break a Regular Calculator? A Practical Factorial Guide
If you have ever typed 25! into a phone calculator or a spreadsheet and gotten a suspiciously round-looking number, this is why — and how to get the exact answer instead, along with double factorial, subfactorial, and permutation results that don't quietly lose digits.
A factorial, written as n!, is the product of every whole number from n down to 1 — for example 5! = 5x4x3x2x1 = 120. It looks simple, but it is one of the fastest-growing operations in ordinary math, and that growth rate is exactly what trips up most calculators, spreadsheets, and even some programming languages once n passes about 18 or 20.
Why does factorial break a normal calculator around 18-20!?
Short answer: Most calculators, browsers, and spreadsheet apps store numbers using a fixed-precision floating-point format (JavaScript's Number type, for instance) that can only represent integers exactly up to about 2^53, roughly 9 quadrillion. Factorial crosses that line around 18!-19!, and by 171! the value is so large the format simply overflows to Infinity.
Below that threshold, everything looks fine — 15! and 17! come out exact and correct. But once the running product needs more precision than the format can hold, the calculator doesn't throw an error; it just quietly rounds to the nearest number it can represent, and the display shows you that rounded value with total confidence. Unless you already know where the cutoff is, there's no visual clue that anything was lost.
Key fact: 20! = 2,432,902,008,176,640,000 exactly. A standard double-precision calculator can still land on this one correctly, but by the time you reach 25! or 30!, silent rounding errors in the last several digits are common on tools that were never built for arbitrary-precision integers.
How does an exact factorial calculator avoid the overflow?
Short answer: By using an arbitrary-precision integer type — BigInt in JavaScript — for every multiplication step instead of the standard Number type, so no digit is ever dropped or rounded no matter how large the result gets.
Instead of multiplying with a format capped at 2^53, a BigInt-based calculator represents the running product as an arbitrary-length integer and multiplies it by the next whole number, one step at a time. This is slower per operation than ordinary floating-point math, but for a bounded input (say, n between 0 and 10000) it still finishes in milliseconds, and the result is exact down to the last digit — plus an accurate digit count, since that's just the length of the resulting integer's text form.
Example factorial results and digit counts (illustrative, calculated with exact BigInt arithmetic)
n
Approx. value
Exact digit count
10!
3,628,800
7
20!
2.43 × 10^18
19
50!
3.04 × 10^64
65
100!
9.33 × 10^157
158
1000!
4.02 × 10^2567
2568
Because the exact integer for something like 1000! can run to thousands of digits, a practical tool also converts the result to an approximate scientific-notation form (taking the leading digits and multiplying by 10 raised to digit-count-minus-1) so it's readable at a glance, while still keeping the full exact value available on request — often behind a "show full digits" toggle so the page doesn't get overwhelmed by a multi-thousand-digit number.
What are double factorial, multifactorial, and subfactorial?
Short answer:Double factorial (n!!) multiplies every other integer down from n (7!!=7x5x3x1=105). Multifactorial (n(k)!) generalizes that idea to any step size k. Subfactorial (!n), also called the derangement number, is a completely different count: the number of ways to shuffle n items so that none lands back in its original position.
Worked example: Say you're distributing 4 labeled letters into 4 labeled envelopes and want to know how many ways none of them ends up in its correct envelope — the classic "derangement" puzzle. That count is !4 = 9, out of the 4! = 24 total arrangements. Only 9 of those 24 shufflings leave every letter in the wrong envelope.
These variants matter because they follow different recursive rules than ordinary factorial: !n = (n-1) x (!(n-1) + !(n-2)), and double factorial simply skips by 2 instead of 1. A calculator that only knows plain n! can't shortcut its way to these — each has its own step-by-step formula, and getting them right (especially at larger n) again comes down to not losing precision partway through the calculation.
Where does factorial actually get used — permutations and combinations?
Short answer: The two most common practical uses are permutation (nPr = n!/(n-r)!, ordered arrangements) and combination (nCr = n!/(r!(n-r)!), unordered selections) — both are ratios of factorials, which is exactly why exact, non-rounded factorial values matter even when the final answer is a modest-looking number.
Example, hypothetical: Choosing 3 winners out of 10 raffle entries where order doesn't matter is a combination: 10C3 = 10!/(3!x7!) = 120 possible groups. Choosing 3 people out of 10 for 1st/2nd/3rd place, where order does matter, is a permutation: 10P3 = 10!/7! = 720 possible orderings. Same 10 and 3, six times more outcomes once order counts.
Because both formulas divide one factorial by another, the numerator and denominator can individually be enormous even when the final ratio is small — which is exactly the case where floating-point rounding in an intermediate step can silently corrupt the final answer. Computing each factorial exactly first, then dividing, avoids that failure mode entirely.
Ready to try it yourself — exact n! up to 10000!, double factorial, subfactorial, decimal (Gamma) factorial, permutations, and combinations, all free and instant?
Why does my phone calculator show a rounded answer for 25!?
Most calculators and spreadsheet apps store numbers in a fixed-precision floating-point format that keeps exact integer values only up to about 2^53 (roughly 9 quadrillion). Factorial passes that ceiling around 18!-19!, so anything from about 20! onward gets silently rounded to the nearest representable value, and the display just hides the lost digits.
What is 0 factorial and why isn't it 0?
0! = 1 by definition, from the "empty product" rule: multiplying zero numbers together gives 1, the multiplicative identity, the same way summing zero numbers gives 0. This also keeps the recursive rule n! = n x (n-1)! consistent at n = 1, since 1! = 1 x 0! = 1.
How many digits does 100 factorial have?
100! has exactly 158 digits, and its value is approximately 9.332621544x10^157. Entering 100 into a BigInt-based factorial calculator shows both the full 158-digit integer and this scientific-notation approximation side by side.
What is the difference between factorial, double factorial, and subfactorial?
Factorial (n!) multiplies every integer from n down to 1. Double factorial (n!!) skips every other integer, so it multiplies n, n-2, n-4, and so on. Subfactorial (!n), also called the derangement number, counts something different entirely: how many ways n items can be rearranged so that none stays in its original spot, for example !4 = 9.
How is factorial used in permutations and combinations?
Both formulas are built directly from factorial. Permutation nPr = n!/(n-r)! counts ordered arrangements of r items chosen from n, while combination nCr = n!/(r!(n-r)!) counts unordered selections. Because both formulas involve dividing one factorial by another, large intermediate values can appear even when the final answer is small, which is why exact BigInt arithmetic matters.
A note on this guide: The worked examples above (raffle entries, letters-and-envelopes, ranking scenarios) are illustrative and hypothetical, meant to show how the formulas behave — not records of an actual event. Numeric facts about factorial values and digit counts (e.g. 100! having 158 digits) are exact mathematical results, not estimates. This article is for general educational reference and isn't professional, financial, or statistical advice.