Skip to content

Factorial Calculator

Enter a whole number n to get n! exactly, digit for digit, along with its double factorial n!!, the number of digits and trailing zeros, and Stirling's approximation with its error. Decimals are handled with the gamma function. Free, no sign-up, and nothing is rounded.

A whole number from 0 to 10,000. A decimal such as 4.5 uses the gamma function.

Results

2,432,902,008,176,640,000

n!

19

Digits in n!

4

Trailing zeros

3,715,891,200

Double factorial, n!!

≈ 2.4227868 × 10^18

Stirling’s approximation

0.416%

How far below n! it falls

0.000831%

Error with the 1/(12n) correction

The working

  • 20! = 20 × 19 × … × 2 × 1 = 20 × 19!, so each factorial is the one before it multiplied by 20.
  • Each trailing zero comes from a factor of 10 = 2 × 5, and fives are scarcer than twos. Counting them: ⌊20/5⌋ + ⌊20/25⌋ + … = 4.
  • The double factorial multiplies every second number: 20!! = 20 × 18 × 16 × 14 × 12 × 10 × 8 × 6 × 4 × 2 = 3,715,891,200.
  • Stirling’s formula √(2πn) (n/e)ⁿ gives about 2.4227868 × 10^18, which is 0.416% below the exact value.

How to Use the Factorial Calculator

  1. 1. Enter n. Any whole number from 0 to 10,000. The result updates as you type.
  2. 2. Read the exact value. Small factorials appear with digit grouping. Larger ones show a headline in scientific notation and every digit in a scrollable box with a copy button.
  3. 3. Check the extras. You also get the number of digits, the trailing zeros, the double factorial n!!, and Stirling’s approximation with how far below n! it falls.
  4. 4. Try a decimal. For a value such as 4.5 the calculator returns Γ(5.5) = 4.5!, since the gamma function extends the factorial to every number except the negative whole numbers.

What a Factorial Is

The factorial of a non-negative whole number n, written n!, is the product of all the whole numbers from 1 up to n: 5! = 5 × 4 × 3 × 2 × 1 = 120. It counts the ways to arrange n distinct things in a row — three books can be shelved in 3! = 6 orders — and it is the building block of permutations, combinations and the binomial theorem. Each factorial is the previous one times n: n! = n × (n − 1)!.

Why is 0! equal to 1? Following the rule n! = n × (n − 1)! down to n = 1 gives 1! = 1 × 0!, which only works if 0! = 1. It also fits the counting meaning (there is exactly one way to arrange nothing) and the fact that an empty product is 1 by convention.

Factorials worth knowing
nn!Trailing zeros
010
110
220
360
4240
51201
67201
75,0401
840,3201
9362,8801
103,628,8002
151,307,674,368,0003
202,432,902,008,176,640,0004

Trailing Zeros: Legendre’s Formula

A zero at the end of n! comes from a factor of 10 = 2 × 5. There are always more factors of 2 than of 5, so the number of trailing zeros equals the number of 5s in 1 × 2 × … × n. Count the multiples of 5, add the multiples of 25 (each hides a second 5), then of 125, and so on: zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …. For 100!, that is 20 + 4 = 24 trailing zeros. 100! has 158 digits in all.

Stirling’s Approximation

For large n, n! is approximated by √(2πn) (n/e)ⁿ. It always falls slightly below the true value, by a relative amount of about 1/(12n): 0.83% at n = 10 (3.5986956 × 10⁶ against 3,628,800) and 0.083% at n = 100 (9.3248476 × 10¹⁵⁷ against 9.3326215 × 10¹⁵⁷). Multiplying by (1 + 1/(12n)) removes most of the error. The approximation is what lets you estimate the size of huge factorials from logarithms alone.

Double Factorial and the Gamma Function

The double factorial n!! multiplies every second number down from n: 9!! = 9 × 7 × 5 × 3 × 1 = 945, and 8!! = 8 × 6 × 4 × 2 = 384. It is not (n!)!. By convention 0!! = 1, and n!! × (n − 1)!! = n!. The gamma function Γ(x) generalises the factorial: Γ(n + 1) = n! for whole n, and it is defined for decimals too, such as (½)! = Γ(1½) = √π / 2 ≈ 0.8862. It has no value at zero or the negative whole numbers, so (−1)! and (−2)! do not exist.

How big can factorials get on a computer?

20! = 2,432,902,008,176,640,000 is the largest factorial that fits in a signed 64-bit integer, and 170! ≈ 7.26 × 10³⁰⁶ is the largest that fits in a double-precision number. This calculator uses arbitrary-size integers, so 10,000! is computed exactly, with 35,660 digits.

Frequently Asked Questions

Why is 0! equal to 1?
Because the factorial rule n! = n × (n − 1)! must hold at n = 1, which gives 1 = 1 × 0!. It also matches the counting meaning: there is exactly one way to arrange zero objects, and the empty product of no numbers is 1.
How many zeros does 100! end with?
24. Count the factors of 5: ⌊100/5⌋ = 20 multiples of 5 plus ⌊100/25⌋ = 4 multiples of 25 gives 24, and there are plenty of 2s to pair with them.
Can you take the factorial of a negative number or a decimal?
Not of a negative whole number, where the gamma function has poles. Decimals and negative non-integers work through Γ(n + 1): 4.5! ≈ 52.34 and (−0.5)! = √π ≈ 1.7725.
What is a double factorial?
n!! is the product of the numbers from n down to 1 or 2 in steps of two, so 7!! = 7 × 5 × 3 × 1 = 105 and 10!! = 10 × 8 × 6 × 4 × 2 = 3,840. It is different from (n!)!, which would be an enormous number.
How many ways can 52 playing cards be arranged?
52! = 8.0658175… × 10⁶⁷, a 68-digit number. Any thoroughly shuffled deck is, for practical purposes, an arrangement nobody has ever held before.
How accurate is Stirling’s approximation?
Its relative error is about 1/(12n), so it is 0.83% low for n = 10 and 0.083% low for n = 100. The calculator shows the exact error for your n, and the error after adding the 1/(12n) correction.

Related Tools

More in Math Calculators

See all Math Calculators