Factorial Calculator
20! = 2,432,902,008,176,640,000. It has 19 digits and ends in 4 zeros, because ⌊20 ÷ 5⌋ = 4 counts the factors of 5 (Legendre’s formula). The factorial n! is the product 1 × 2 × 3 × … × n, with 0! = 1. This calculator works it out exactly for any whole n up to 10,000: 100! has 158 digits and 24 trailing zeros, and 10,000! has 35,660 digits and 2,499 trailing zeros. You also get the first and last digits, scientific notation, every digit behind a button, the double factorial n!!, the subfactorial !n (derangements), and Stirling’s approximation with its relative error. Factorials of negative numbers, decimals and fractions need the gamma function, which this calculator does not compute.
Updated Runs in your browser: nothing you enter is uploadedHow this tool works
20! = 20 × 19 × 18 × … × 2 × 1
20! = 2,432,902,008,176,640,000
19 digits, 4 trailing zeros
- Number of digits
- 19
- Scientific notation
- 2.43290200818 × 10¹⁸
- Trailing zeros
- 4
- Stirling’s approximation
- ≈ 2.42279 × 10¹⁸
- Stirling’s relative error
- 0.416% below 20!
- Rule of thumb 1 ÷ (12n)
- 0.417%
All digits
The working
- 20! = 20 × 19 × 18 × … × 2 × 1 = 2,432,902,008,176,640,000.
- The result has 19 digits: ⌊log₁₀(20!)⌋ + 1 = 18 + 1.
- Every trailing zero is a factor 10 = 2 × 5, and n! has far more 2s than 5s, so count the 5s with Legendre’s formula: ⌊20 ÷ 5⌋ = 4 trailing zeros.
- Stirling’s approximation √(2π·20) × (20 ÷ e)^20 ≈ 2.42279 × 10¹⁸, which is 0.416% below the exact 20!; the error is close to 1 ÷ (12n) = 0.417%.
Factorials from 0! to 25!
| n | n! | Digits | Trailing zeros |
|---|---|---|---|
| 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 0 |
| 2 | 2 | 1 | 0 |
| 3 | 6 | 1 | 0 |
| 4 | 24 | 2 | 0 |
| 5 | 120 | 3 | 1 |
| 6 | 720 | 3 | 1 |
| 7 | 5,040 | 4 | 1 |
| 8 | 40,320 | 5 | 1 |
| 9 | 362,880 | 6 | 1 |
| 10 | 3,628,800 | 7 | 2 |
| 11 | 39,916,800 | 8 | 2 |
| 12 | 479,001,600 | 9 | 2 |
| 13 | 6,227,020,800 | 10 | 2 |
| 14 | 87,178,291,200 | 11 | 2 |
| 15 | 1,307,674,368,000 | 13 | 3 |
| 16 | 20,922,789,888,000 | 14 | 3 |
| 17 | 355,687,428,096,000 | 15 | 3 |
| 18 | 6,402,373,705,728,000 | 16 | 3 |
| 19 | 121,645,100,408,832,000 | 18 | 3 |
| 20 | 2,432,902,008,176,640,000 | 19 | 4 |
| 21 | 51,090,942,171,709,440,000 | 20 | 4 |
| 22 | 1,124,000,727,777,607,680,000 | 22 | 4 |
| 23 | 25,852,016,738,884,976,640,000 | 23 | 4 |
| 24 | 620,448,401,733,239,439,360,000 | 24 | 4 |
| 25 | 15,511,210,043,330,985,984,000,000 | 26 | 6 |
Trailing zeros of n! for powers of 10
| n | Terms ⌊n ÷ 5ᵏ⌋ added | Trailing zeros of n! | Digits of n! | n! in scientific notation |
|---|---|---|---|---|
| 10 | 2 | 2 | 7 | 3.6288 × 10⁶ |
| 100 | 20 + 4 | 24 | 158 | 9.33262 × 10¹⁵⁷ |
| 1,000 | 200 + 40 + 8 + 1 | 249 | 2,568 | 4.02387 × 10²⁵⁶⁷ |
| 10,000 | 2000 + 400 + 80 + 16 + 3 | 2,499 | 35,660 | 2.84626 × 10³⁵⁶⁵⁹ |
Smallest n whose factorial ends in k zeros
| Zeros k | Smallest n with at least k zeros | Zeros n! actually has | Does a factorial end in exactly k zeros? |
|---|---|---|---|
| 1 | 5 | 1 | Yes |
| 2 | 10 | 2 | Yes |
| 3 | 15 | 3 | Yes |
| 4 | 20 | 4 | Yes |
| 5 | 25 | 6 | No: the count skips k |
| 6 | 25 | 6 | Yes |
| 7 | 30 | 7 | Yes |
| 10 | 45 | 10 | Yes |
| 24 | 100 | 24 | Yes |
| 25 | 105 | 25 | Yes |
| 100 | 405 | 100 | Yes |
| 1000 | 4005 | 1000 | Yes |
Stirling’s approximation against the exact factorial
| n | Exact n! | Stirling’s estimate | Relative error | 1 ÷ (12n) |
|---|---|---|---|---|
| 1 | 1 | 0.922137 | 7.79% | 8.33% |
| 2 | 2 | 1.919 | 4.05% | 4.17% |
| 3 | 6 | 5.83621 | 2.73% | 2.78% |
| 5 | 120 | 118.019 | 1.65% | 1.67% |
| 10 | 3,628,800 | 3.5987 × 10⁶ | 0.83% | 0.833% |
| 20 | 2.4329 × 10¹⁸ (19 digits) | 2.42279 × 10¹⁸ | 0.416% | 0.417% |
| 50 | 3.04141 × 10⁶⁴ (65 digits) | 3.03634 × 10⁶⁴ | 0.167% | 0.167% |
| 100 | 9.33262 × 10¹⁵⁷ (158 digits) | 9.32485 × 10¹⁵⁷ | 0.0833% | 0.0833% |
| 1,000 | 4.02387 × 10²⁵⁶⁷ (2,568 digits) | 4.02354 × 10²⁵⁶⁷ | 0.00833% | 0.00833% |
| 10,000 | 2.84626 × 10³⁵⁶⁵⁹ (35,660 digits) | 2.84624 × 10³⁵⁶⁵⁹ | 0.000833% | 0.000833% |
Where factorials count arrangements
| Situation | Expression | Count |
|---|---|---|
| Three books on a shelf | 3! | 6 |
| Five people in a row for a photo | 5! | 120 |
| Finishing orders of an 8-runner race, no ties | 8! | 40,320 |
| Anagrams of LISTEN (six different letters) | 6! | 720 |
| Ten guests in a row of ten seats | 10! | 3,628,800 |
| Ten guests at a round table, rotations counted once | (10 − 1)! | 362,880 |
| Arrangements of the letters of MISSISSIPPI | 11! ÷ (1! × 4! × 4! × 2!) | 34,650 |
| Round trips through 10 cities, a route and its reverse counted once | (10 − 1)! ÷ 2 | 181,440 |
| Four people each leave with someone else’s coat | !4 | 9 |
| Orderings of a 52-card deck | 52! | 8.06582 × 10⁶⁷ (68 digits) |
Double factorial n!! and subfactorial !n for n = 0 to 15
| n | n!! | Trailing zeros of n!! | !n |
|---|---|---|---|
| 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 |
| 2 | 2 | 0 | 1 |
| 3 | 3 | 0 | 2 |
| 4 | 8 | 0 | 9 |
| 5 | 15 | 0 | 44 |
| 6 | 48 | 0 | 265 |
| 7 | 105 | 0 | 1,854 |
| 8 | 384 | 0 | 14,833 |
| 9 | 945 | 0 | 133,496 |
| 10 | 3,840 | 1 | 1,334,961 |
| 11 | 10,395 | 0 | 14,684,570 |
| 12 | 46,080 | 1 | 176,214,841 |
| 13 | 135,135 | 0 | 2,290,792,932 |
| 14 | 645,120 | 1 | 32,071,101,049 |
| 15 | 2,027,025 | 0 | 481,066,515,734 |
How to calculate a factorial
- Multiply the whole numbers from 1 up to n. n! = n × (n − 1) × … × 2 × 1. For example 20! = 20 × 19 × 18 × … × 2 × 1 = 2,432,902,008,176,640,000. The special case is 0! = 1.
- Use the previous factorial to save work. Each factorial is n times the one before it: 10! = 10 × 9!, so 10! = 3,628,800 and 11! = 11 × 3,628,800 = 39,916,800.
- Count the digits. The number of digits is ⌊log₁₀(n!)⌋ + 1, which Stirling’s formula estimates well for large n. 100! has 158 digits and 1,000! has 2,568; the calculator reads the digit count from the exact value.
- Count the trailing zeros with Legendre’s formula. Each zero is a factor 10 = 2 × 5, and factors of 2 are never the shortage, so add ⌊n ÷ 5⌋ + ⌊n ÷ 25⌋ + ⌊n ÷ 125⌋ + … until the division gives 0. For 100! that is 20 + 4 = 24.
- Switch mode for n!! or !n. Choose the double factorial for n × (n − 2) × (n − 4) × … (9!! = 945) or the subfactorial for the count of derangements (!4 = 9).
Frequently asked questions
- What is a factorial?
- The factorial of a whole number n, written n!, is the product of all whole numbers from 1 to n. 20! is 20 × 19 × 18 × … × 2 × 1 = 2,432,902,008,176,640,000. It counts the ways to put n different things in order, and it appears in permutations, combinations, probability and the Taylor series of eˣ.
- What are 5 factorial, 10 factorial and 100 factorial?
- 5! = 120, 10! = 3,628,800, and 100! is about 9.33262154439 × 10¹⁵⁷, a 158-digit number that starts 933262154439… and ends in 24 zeros. 25! = 15,511,210,043,330,985,984,000,000 already has 26 digits.
- Why is 0! equal to 1?
- Because the rule n! = n × (n − 1)! must also hold for n = 1: 1! = 1 × 0! only works if 0! = 1. It also fits the idea of counting arrangements: there is exactly one way to arrange nothing, the empty arrangement, and an empty product is 1. The gamma function, which extends the factorial, gives Γ(1) = 1 for the same reason.
- Can you take the factorial of a negative number?
- Not of a negative whole number. n! = n × (n − 1)! would need (−1)! = 0! ÷ 0, a division by zero, and the gamma function that extends the factorial has no value at 0, −1, −2 and so on. This calculator therefore rejects negative input with a message instead of an answer.
- What about the factorial of a decimal or a fraction such as 4.5 or ½?
- They exist, but through the gamma function: x! = Γ(x + 1). For example (½)! = Γ(3/2) = √π ÷ 2 ≈ 0.886227. The gamma function is out of scope for this calculator, which handles whole numbers from 0 to 10,000 and says so when you type a decimal or fraction.
- How fast does n! grow?
- Faster than any fixed power or exponential. n! passes 2ⁿ at n = 4 and 10ⁿ at n = 25. 20! is the largest factorial that fits a signed 64-bit integer (2,432,902,008,176,640,000), and 170! is the largest that a standard double-precision number can hold (about 7.25742 × 10³⁰⁶); 171! overflows it. Beyond that you need big integers, which is why this calculator uses BigInt.
- How many digits does n! have?
- The digit count is ⌊log₁₀(n!)⌋ + 1. Stirling’s formula turns that into ⌊n × log₁₀(n ÷ e) + ½ × log₁₀(2πn)⌋ + 1, which matches the exact count for every n from 2 to 1,200 that was checked. 100! has 158 digits, 1,000! has 2,568 and 10,000! has 35,660. The calculator counts the digits of the exact value instead of estimating them.
- How many trailing zeros does n! have?
- Add ⌊n ÷ 5⌋ + ⌊n ÷ 25⌋ + ⌊n ÷ 125⌋ + … (Legendre’s formula for the number of factors of 5). Every zero needs a 2 and a 5, and n! has many more 2s than 5s. 100! has 20 + 4 = 24 zeros, 1,000! has 249 and 10,000! has 2,499. The count jumps at multiples of 5 and by 2 at 25, so no factorial ends in exactly 5 zeros: 24! has 4 and 25! has 6.
- What is a double factorial (n!!)?
- n!! multiplies every second number down from n: 9 × 7 × 5 × 3 × 1 = 945 for 9!!, and 10 × 8 × 6 × 4 × 2 = 3,840 for 10!!. It is not the factorial of a factorial: (3!)! = 6! = 720, while 3!! = 3. For even n, n!! = 2^(n/2) × (n/2)!, and n!! × (n − 1)!! = n!. An odd n!! ends in no zeros; an even one has the zeros of (n/2)!.
- What is a subfactorial (!n) and what are derangements?
- !n counts the rearrangements of n items in which no item stays in its original place, such as n guests each taking someone else’s coat. !4 = 9, !10 = 1,334,961, and !n = n × !(n − 1) + (−1)ⁿ starting from !0 = 1. The share of orderings with no fixed point is 37.50% for 4 items and settles near 1 ÷ e ≈ 36.79% (36.79% for 100 items). Because of that, !n is the whole number nearest to n! ÷ e.
- How accurate is Stirling’s approximation?
- Stirling’s formula n! ≈ √(2πn) (n ÷ e)ⁿ is always below the true value and its relative error is close to 1 ÷ (12n): 7.79% at n = 1, 0.83% at n = 10, 0.0833% at n = 100 and 0.000833% at n = 10,000. So it is good for the size of a huge factorial, but it never gives the exact digits. The calculator shows the estimate and its error beside the exact result for comparison.
- How is n! related to permutations and combinations?
- Arranging n different items in order can be done in n! ways, and arranging r of them gives nPr = n! ÷ (n − r)!. For example P(10, 3) = 10! ÷ 7! = 720. Combinations divide further by r!. This page is about n! itself; for nPr, nCr and repetition use the permutation and combination calculator.
- Why does the calculator stop at n = 10,000?
- 10,000! already has 35,660 digits, and each larger step makes the page slower and the result harder to read or copy. The calculation itself uses a product tree, which multiplies the factors in balanced halves, so even the largest value you can enter is computed quickly. For bigger n use the leading digits and digit count from Stirling’s formula.
How it works
Input: a whole number from 0 to 10,000, typed with digits only. Thousands separators ("1,000"), a trailing "!" and a zero fraction ("5.0") are accepted; negatives, other decimals, fractions, E notation and larger values are rejected with a message. Factorials of non-integers are values of the gamma function, x! = Γ(x + 1), which is out of scope here. Exact arithmetic: n! = 1 × 2 × … × n is computed in BigInt with a product tree, multiplying the factors in balanced halves (three factors at a time as plain numbers at the leaves) so that large products multiply numbers of similar size. n!! is the same product over every second factor, and the subfactorial uses !0 = 1 and !n = n × !(n − 1) + (−1)ⁿ, which gives the exact count of derangements. Digits: the digit count, the first and last 20 digits and the scientific notation (12 significant digits, rounded half up) are read from the decimal string of the exact value. Trailing zeros of n! are the exponent of 5 in n! by Legendre’s formula, ⌊n ÷ 5⌋ + ⌊n ÷ 25⌋ + …, because n! always has at least as many factors of 2; for n!! they are 0 when n is odd and those of (n ÷ 2)! when n is even, and for !n they are counted from the digits. Stirling: the estimate √(2πn) (n ÷ e)ⁿ is computed in logarithms, ln = ½ ln(2πn) + n ln n − n, with the exact ln n! taken from the leading 17 digits and the digit count of n!. The relative error (n! − estimate) ÷ n! is shown with three significant digits; it is accurate to well below the displayed precision for every n up to 10,000, and the estimate is shown with six significant digits. It is an approximation and is labelled as one; everything else on this page is exact. The full number is written out only on request (“Show all digits”) and is never part of the page HTML; it is grouped in tens for reading, and “Copy all digits” copies it without separators. Everything runs in your browser.
Sources
More free tools
- Exponent CalculatorCalculate b to the power x for whole, negative and fractional exponents with exact answers, huge powers in full, and solve for the exponent or base.
- Scientific CalculatorFree online scientific calculator with live results: trig in DEG, RAD or GRAD, logs, powers, factorial, nPr, nCr, memory and history.
- Factor CalculatorList every factor of a number with its factor pairs, count and sum, and whether it is prime, perfect or abundant. Plus common factors of 2 or 3 numbers.
- Long Division CalculatorLong division with remainder and the decimal worked out step by step, the repeating block marked (1/7 = 0.(142857)). Exact for decimals and big numbers.
- Prime Number CheckerTest whether a number up to 3.3 × 10^24 is prime, find the next and previous prime, list primes in a range, count primes up to N, and see twin primes.
- Fibonacci CalculatorFind F(n) exactly for n up to 10,000, list the first N terms, test whether a number is Fibonacci, get its index, the sum of terms and the golden ratio.
More: Algebra and number theoryAll math & numbersAll toolsHome & DIY calculators