Skip to main content
ponderloop

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

What to calculate

A whole number from 0 to 10,000. Decimals, fractions and negatives are not supported: they need the gamma function.

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%

The working

  1. 20! = 20 × 19 × 18 × … × 2 × 1 = 2,432,902,008,176,640,000.
  2. The result has 19 digits: ⌊log₁₀(20!)⌋ + 1 = 18 + 1.
  3. 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.
  4. 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!

Each row is the calculator’s own answer for n from 0 to 25: the exact value, its digit count and its trailing zeros.
nn!DigitsTrailing zeros
0110
1110
2210
3610
42420
512031
672031
75,04041
840,32051
9362,88061
103,628,80072
1139,916,80082
12479,001,60092
136,227,020,800102
1487,178,291,200112
151,307,674,368,000133
1620,922,789,888,000143
17355,687,428,096,000153
186,402,373,705,728,000163
19121,645,100,408,832,000183
202,432,902,008,176,640,000194
2151,090,942,171,709,440,000204
221,124,000,727,777,607,680,000224
2325,852,016,738,884,976,640,000234
24620,448,401,733,239,439,360,000244
2515,511,210,043,330,985,984,000,000266

Trailing zeros of n! for powers of 10

Legendre’s formula adds ⌊n ÷ 5⌋ + ⌊n ÷ 25⌋ + ⌊n ÷ 125⌋ + …; the sum equals the zeros at the end of the exact n!.
nTerms ⌊n ÷ 5ᵏ⌋ addedTrailing zeros of n!Digits of n!n! in scientific notation
102273.6288 × 10⁶
10020 + 4241589.33262 × 10¹⁵⁷
1,000200 + 40 + 8 + 12492,5684.02387 × 10²⁵⁶⁷
10,0002000 + 400 + 80 + 16 + 32,49935,6602.84626 × 10³⁵⁶⁵⁹

Smallest n whose factorial ends in k zeros

Trailing zeros jump by more than one at every power of 5, so some counts of zeros never occur.
Zeros kSmallest n with at least k zerosZeros n! actually hasDoes a factorial end in exactly k zeros?
151Yes
2102Yes
3153Yes
4204Yes
5256No: the count skips k
6256Yes
7307Yes
104510Yes
2410024Yes
2510525Yes
100405100Yes
100040051000Yes

Stirling’s approximation against the exact factorial

Stirling’s estimate √(2πn) (n ÷ e)ⁿ is always a little low; the relative error is (n! − estimate) ÷ n!, next to the rule of thumb 1 ÷ (12n).
nExact n!Stirling’s estimateRelative error1 ÷ (12n)
110.9221377.79%8.33%
221.9194.05%4.17%
365.836212.73%2.78%
5120118.0191.65%1.67%
103,628,8003.5987 × 10⁶0.83%0.833%
202.4329 × 10¹⁸ (19 digits)2.42279 × 10¹⁸0.416%0.417%
503.04141 × 10⁶⁴ (65 digits)3.03634 × 10⁶⁴0.167%0.167%
1009.33262 × 10¹⁵⁷ (158 digits)9.32485 × 10¹⁵⁷0.0833%0.0833%
1,0004.02387 × 10²⁵⁶⁷ (2,568 digits)4.02354 × 10²⁵⁶⁷0.00833%0.00833%
10,0002.84626 × 10³⁵⁶⁵⁹ (35,660 digits)2.84624 × 10³⁵⁶⁵⁹0.000833%0.000833%

Where factorials count arrangements

Each count is computed with the calculator’s own factorial and subfactorial functions. For partial arrangements nPr and nCr, use the permutation and combination calculator.
SituationExpressionCount
Three books on a shelf3!6
Five people in a row for a photo5!120
Finishing orders of an 8-runner race, no ties8!40,320
Anagrams of LISTEN (six different letters)6!720
Ten guests in a row of ten seats10!3,628,800
Ten guests at a round table, rotations counted once(10 − 1)!362,880
Arrangements of the letters of MISSISSIPPI11! ÷ (1! × 4! × 4! × 2!)34,650
Round trips through 10 cities, a route and its reverse counted once(10 − 1)! ÷ 2181,440
Four people each leave with someone else’s coat!49
Orderings of a 52-card deck52!8.06582 × 10⁶⁷ (68 digits)

Double factorial n!! and subfactorial !n for n = 0 to 15

The double factorial multiplies every second number down from n; the subfactorial counts the rearrangements of n items that leave none in its place.
nn!!Trailing zeros of n!!!n
0101
1100
2201
3302
4809
515044
6480265
710501,854
8384014,833
99450133,496
103,84011,334,961
1110,395014,684,570
1246,0801176,214,841
13135,13502,290,792,932
14645,120132,071,101,049
152,027,0250481,066,515,734

How to calculate a factorial

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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: Algebra and number theoryAll math & numbersAll toolsHome & DIY calculators