Number Theory & Bases

Factorial Calculator

This factorial calculator finds n! exactly, with steps, for any whole number n from 0 to 10,000. n factorial is the product n!=n⋅(n−1)⋯2⋅1n! = n \cdot (n - 1) \cdots 2 \cdot 1, so 5! = 120.

Try

A whole number from 0 to 10,000.

Result

100!: 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

100!

93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

158 digits

Number of digits
158
Scientific notation
9.332621544×101579.332621544 \times 10^{157}
Trailing zerosLegendre: ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4
24
Double factorial n!!100 × 98 × 96 × ⋯ × 2
≈ 3.42432247×10⁷⁹ (80 digits)
Stirling’s approximation
≈ 9.324847625×10¹⁵⁷
Stirling relative errorClose to 1/(12n) = 0.08333%; the approximation is always a little too small
0.0833%
Sum of digits
648
log₁₀(n!)
157.9700037

100! has 158 digits and ends in 24 zeros. Stirling’s formula gets within 0.0833% of it.

Step-by-step working (5 steps)
  1. Multiply the whole numbers from n down to 1

    Exact big-integer arithmetic multiplies all 100 factors without rounding.

    100!=100⋅99⋅98⋯2⋅1=100⋅99!100! = 100 \cdot 99 \cdot 98 \cdots 2 \cdot 1 = 100 \cdot 99!
  2. Count the digits

    A positive integer x has ⌊log₁₀ x⌋ + 1 digits.

    ⌊log10⁡100!⌋+1=⌊157.97⌋+1=158\lfloor \log_{10} 100! \rfloor + 1 = \lfloor 157.97 \rfloor + 1 = 158
  3. Count the trailing zeros (Legendre’s formula)

    Each trailing zero needs a factor 10 = 2 × 5. Factors of 2 are far more common, so count the factors of 5: one for each multiple of 5, one more for each multiple of 25, and so on.

    Z=⌊1005⌋+⌊10025⌋=20+4=24Z = \left\lfloor \frac{100}{5} \right\rfloor + \left\lfloor \frac{100}{25} \right\rfloor = 20 + 4 = 24
  4. Compare with Stirling’s approximation

    The approximation is 0.0833% too small, close to the predicted 1/(12n) = 0.08333%.

    100!≈2π⋅100(100e)100≈9.324847625×10157100! \approx \sqrt{2\pi \cdot 100}\left(\frac{100}{e}\right)^{100} \approx 9.324847625 \times 10^{157}
  5. Double factorial

    For even n, n!! multiplies the even numbers and equals 2^(n/2) × (n/2)!.

    100!!=100⋅98⋯2=250⋅50!100!! = 100 \cdot 98 \cdots 2 = 2^{50} \cdot 50!

Every digit is shown up to 3000!, along with the digit count, trailing zeros, double factorial n!! and Stirling’s approximation.

By Hira Noor, mathematicianLast reviewed Free, no sign-up, runs in your browserReport a problem

How to use this calculator

  1. Type a whole number n from 0 to 10,000, such as 5 or 100. Decimals and negative numbers are not accepted, because n! is defined for whole numbers. For fractions, see the FAQ on the gamma function.
  2. Read n! at the top. Up to 500 digits it is shown in full there. Larger results appear in scientific notation, with every digit listed below for n up to 3,000.
  3. Check the digit count, trailing zeros, double factorial and digit sum in the results list.
  4. Open the steps to see the multiplication (for n up to 12), the digit count, Legendre’s formula for the trailing zeros and how close Stirling’s approximation comes.
  5. For n up to 25 the results also include a table of every factorial from 0! to n!.

Formulas

Factorial

n!=∏k=1nk=n⋅(n−1)!,0!=1n! = \prod_{k=1}^{n} k = n \cdot (n - 1)!,\qquad 0! = 1

Plain-text formula: n! = ∏_{k = 1}^n k = n · (n − 1)!, 0! = 1

n! counts the ways to arrange n distinct objects in a row. It grows faster than any exponential function.

Legendre’s formula (trailing zeros)

Z(n)=∑k≥1⌊n5k⌋Z(n) = \sum_{k \ge 1} \left\lfloor \frac{n}{5^{k}} \right\rfloor

Plain-text formula: Z(n) = ∑_{k ≥ 1} ⌊n/5^k⌋

The power of a prime p in n! is the sum of ⌊n/pᵏ⌋. With p = 5 it counts the trailing zeros, since every 5 pairs with one of the more plentiful factors of 2.

Stirling’s approximation

n!≈2πn(ne)n,n!2πn(n/e)n≈1+112nn! \approx \sqrt{2\pi n}\left(\frac{n}{e}\right)^{n},\qquad \frac{n!}{\sqrt{2\pi n}\,(n/e)^{n}} \approx 1 + \frac{1}{12n}

Plain-text formula: n! ≈ √(2πn)(n/e)^n, (n!)/(√(2πn) (n/e)^n) ≈ 1 + 1/(12n)

The relative error shrinks like 1/(12n): about 0.83% at n = 10 and 0.083% at n = 100. The approximation is always slightly too small.

Double factorial

n!!=n(n−2)(n−4)⋯,(2k)!!=2kk!n!! = n (n - 2)(n - 4) \cdots,\qquad (2k)!! = 2^{k} k!

Plain-text formula: n!! = n(n − 2)(n − 4)⋯, (2k)!! = 2^k k!

The product stops at 2 for even n and at 1 for odd n. It is not the factorial of a factorial.

Reading the result

Factorials count arrangements: 52! ≈ 8.066 × 10⁶⁷ is the number of ways to shuffle a standard deck, so any well-shuffled order has almost certainly never occurred before. They also appear in combinations, (nk)=n!k!(n−k)!\binom{n}{k} = \frac{n!}{k!(n-k)!}, which the combinations and permutations calculator works out, and in Taylor series and probability.

Because factorials grow so quickly, most software stores them as floating-point numbers and loses digits beyond about 16 significant figures; 171! already overflows double precision. Handheld scientific calculators usually stop at 69!, because 70! ≈ 1.198 × 10¹⁰⁰ is past their 10¹⁰⁰ limit. This calculator uses exact integer arithmetic, so the digits, the digit count, the trailing zeros and the digit sum are all exact.

What is a factorial?

The factorial of a whole number n, written n! and read “n factorial”, is the product of every whole number from 1 up to n. So 4! = 4 × 3 × 2 × 1 = 24 and 5! = 5 × 4 × 3 × 2 × 1 = 120. The exclamation mark is the factorial symbol.

n! is the number of ways to put n different things in order. Four books can stand on a shelf in 4! = 24 orders: 4 choices for the first place, 3 for the second, 2 for the third and 1 for the last.

By definition 0! = 1. Factorials of negative numbers are undefined, and fractions need the gamma function, n!=Γ(n+1)n! = \Gamma(n + 1).

How to calculate a factorial

By hand: start at n and multiply by each smaller whole number down to 1. For 6!: 6 × 5 = 30, × 4 = 120, × 3 = 360, × 2 = 720, × 1 = 720.

Faster, from the one before: each factorial is n times the previous one, n!=n⋅(n−1)!n! = n \cdot (n - 1)!. If you know 9! = 362,880, then 10! = 10 × 362,880 = 3,628,800.

Ratios without the full product: cancel before you multiply. 10!8!=10⋅9=90\frac{10!}{8!} = 10 \cdot 9 = 90, because every factor from 8 down to 1 cancels. This is how permutation counts such as 10P2 are worked out.

Large n: past about 20! the numbers are too long to multiply comfortably, and a phone or spreadsheet loses digits. Use exact arithmetic, as this calculator does, or estimate with Stirling’s approximation.

Factorial table: 0! to 20!

Values of n! for n from 0 to 20, with the number of digits and trailing zeros. 12! is the largest that fits in a signed 32-bit integer and 20! the largest that fits in a signed 64-bit integer.

Factorials from 0! to 20!
n!ValueDigitsTrailing zeros
0!110
1!110
2!210
3!610
4!2420
5!12031
6!72031
7!5,04041
8!40,32051
9!362,88061
10!3,628,80072
11!39,916,80082
12!479,001,60092
13!6,227,020,800102
14!87,178,291,200112
15!1,307,674,368,000133
16!20,922,789,888,000143
17!355,687,428,096,000153
18!6,402,373,705,728,000163
19!121,645,100,408,832,000183
20!2,432,902,008,176,640,000194

Worked example

Digits and trailing zeros of 25!

How many digits does 25! have, how many trailing zeros, and how good is Stirling’s approximation?

  1. Multiply 1 × 2 × ⋯ × 25 = 15,511,210,043,330,985,984,000,000.
  2. Count the digits: log10⁡25!≈25.19\log_{10} 25! \approx 25.19, so 25! has ⌊25.19⌋ + 1 = 26 digits.
  3. Trailing zeros: ⌊25/5⌋+⌊25/25⌋=5+1=6\lfloor 25/5 \rfloor + \lfloor 25/25 \rfloor = 5 + 1 = 6.
  4. Stirling: 50π(25/e)25≈1.546×1025\sqrt{50\pi}\,(25/e)^{25} \approx 1.546 \times 10^{25}, which is about 0.333% below the exact value, as the rule of thumb 1/(12n) = 1/300 predicts.

Answer: 25! = 15,511,210,043,330,985,984,000,000 has 26 digits and ends in exactly 6 zeros.

Frequently asked questions

Why is 0! equal to 1?

0! is an empty product, and an empty product is 1, just as x⁰ = 1. It also keeps the rule n! = n × (n − 1)! working at n = 1, and it makes formulas such as (n0)=1\binom{n}{0} = 1 come out right.

What is 10 factorial?

10! = 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 3,628,800. It has 7 digits and ends in 2 zeros, one from the factor 5 and one from the factor 10.

How do you divide factorials?

Cancel the shared factors instead of working out both factorials. Since n!=n(n−1)⋯(k+1)⋅k!n! = n(n - 1) \cdots (k + 1) \cdot k!, the quotient n!k!\frac{n!}{k!} is the product of the whole numbers from k + 1 to n. So 10!8!=10⋅9=90\frac{10!}{8!} = 10 \cdot 9 = 90 and 100!98!=100⋅99\frac{100!}{98!} = 100 \cdot 99 = 9,900. For n!k!(n−k)!\frac{n!}{k!(n-k)!}, use the combinations and permutations calculator.

How many digits does 100! have?

100! has 158 digits: 93,326,215,443,944,… ending in 24 zeros. It is about 9.333 × 10¹⁵⁷.

How many trailing zeros does 100! have?

24. By Legendre’s formula, ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4. Likewise 1000! ends in 249 zeros.

Why is 52! so special?

52! ≈ 8.066 × 10⁶⁷ is the number of orders a 52-card deck can be in. That is so many that a properly shuffled deck is almost certainly in an order no deck has ever been in before.

What is a double factorial?

n!! multiplies every second number down from n: 7!! = 7 × 5 × 3 × 1 = 105 and 8!! = 8 × 6 × 4 × 2 = 384. It is not (n!)!, which would be astronomically larger.

Can I take the factorial of a negative number or a fraction?

Not with the ordinary definition. The gamma function extends it, with n! = Γ(n + 1), so (1/2)! = Γ(3/2) = √π/2 ≈ 0.8862. Γ has poles at 0 and the negative integers, so factorials of negative whole numbers stay undefined.

What is the largest factorial that fits in a 64-bit integer?

20! = 2,432,902,008,176,640,000 fits in a signed 64-bit integer (maximum about 9.22 × 10¹⁸). 21! ≈ 5.1 × 10¹⁹ does not, which is why programs overflow so early.

Scientific Notation Calculator

Convert to scientific, E and engineering notation, or add, subtract, multiply and divide, with steps.

Arithmetic & Numbers

LCM and GCF Calculator

LCM and GCF of up to 10 numbers with steps: multiples, prime factors, Euclid’s algorithm and a coprime check.

Number Theory & Bases

Scientific Calculator

Type or tap expressions with exact fractions, memory, variables, constants and complex mode.

Tools

Sources and further reading

  1. NIST Digital Library of Mathematical Functions, §5.4 Gamma function: special values (n! = Γ(n + 1)) (opens in a new tab), National Institute of Standards and Technology
  2. NIST Digital Library of Mathematical Functions, §5.11 Gamma function: asymptotic expansions (opens in a new tab), National Institute of Standards and Technology
  3. A000142: Factorial numbers (opens in a new tab), The On-Line Encyclopedia of Integer Sequences (OEIS)
  4. Concrete Mathematics (R. L. Graham, D. E. Knuth and O. Patashnik, 2nd ed., §4.4 Factorial factors), Addison-Wesley

Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?