Factorial Calculator

The factorial of n, written n!, multiplies every whole number from n down to 1: 5! = 5 × 4 × 3 × 2 × 1 = 120 (see the steps). It counts the ways to put n things in order. Type any number to get its factorial exactly, with every digit up to 10,000!, the digit count and the trailing zeros.

Find a factorial

Type a whole number, or a fraction such as 1/2 for the gamma function. Results update as you type.

Optional. For programming tasks, such as n! mod 10⁹+7.
Examples:

How to Use This Calculator

  1. Type a number

    A whole number such as 5 or 52, or a fraction such as 1/2. You can also type 5!, 9!! or !4.

  2. Pick the kind

    n! for a factorial, n!! for a double factorial, !n for a subfactorial. Add m to get the remainder mod m.

  3. Read the answer

    You get the exact value, the multiplication, the digit count, trailing zeros and the choices behind it.

What is a factorial?

The factorial of a whole number n is the product of all whole numbers from 1 to n. It is written with an exclamation mark, n!, and read "n factorial". So 4! = 4 × 3 × 2 × 1 = 24. The notation comes from the French mathematician Christian Kramp, who introduced it in 1808.

A factorial counts orderings. To line up 4 different books, you have 4 choices for the first place, 3 for the second, 2 for the third and 1 for the last, so there are 4 × 3 × 2 × 1 = 24 possible rows. The calculator draws those choices as slots, and for up to 4 items it lists every ordering.

Show all 24 orderings of 4 items

The factorial formula

n! = n × (n − 1) × (n − 2) × … × 2 × 1
n! = n × (n − 1)!,  0! = 1

The first line multiplies everything at once. The second builds each factorial from the one before, which is the quick way to fill a table: 6! = 6 × 5! = 6 × 120 = 720. On a scientific calculator use the x! or n! key. In Excel and Google Sheets, type =FACT(6).

Why 0! equals 1

0! = 1 is a definition, and it is the only one that keeps the rest of the maths working. A product of no numbers is 1, just as a sum of no numbers is 0. The rule n! = n × (n − 1)! gives 1! = 1 × 0!, which only works if 0! = 1. And there is exactly one way to arrange nothing: leave it as it is. Formulas such as the number of combinations also break without it.

Show 0! in the calculator

Factorial table

Factorials grow faster than powers. 10! is already over 3 million, and 20! is the largest one that fits in a 64-bit integer, which is why many programs stop there.

Factorials from 0! to 20!
n n!
0! 1
1! 1
2! 2
3! 6
4! 24
5! 120
6! 720
7! 5,040
8! 40,320
9! 362,880
10! 3,628,800
11! 39,916,800
12! 479,001,600
13! 6,227,020,800
14! 87,178,291,200
15! 1,307,674,368,000
16! 20,922,789,888,000
17! 355,687,428,096,000
18! 6,402,373,705,728,000
19! 121,645,100,408,832,000
20! 2,432,902,008,176,640,000

Larger factorials are easier to read in scientific notation. The digits and trailing zeros below are exact, and each row opens with every digit in the calculator.

Large factorials with their size, number of digits and trailing zeros
n About Digits Trailing zeros
25! 1.5511 × 10²⁵ 26 6
50! 3.0414 × 10⁶⁴ 65 12
52! 8.0658 × 10⁶⁷ 68 12
100! 9.3326 × 10¹⁵⁷ 158 24
1,000! 4.0239 × 10²⁵⁶⁷ 2,568 249

52 factorial and a deck of cards

A deck of 52 cards can be shuffled into 52! different orders, about 8.0658 × 10⁶⁷. That number has 68 digits. The universe is about 13.8 billion years old, roughly 4.4 × 10¹⁷ seconds. Shuffling once a second for all that time would reach a tiny fraction of the possible orders, so a properly shuffled deck is almost certainly in an order no deck has been in before.

Show all 68 digits of 52!

Permutations and combinations

Most counting problems use factorials. When order matters (a podium, a password, a seating plan) you want permutations. When it does not (a team, a hand of cards, lottery numbers) you want combinations.

nPr = n! ÷ (n − r)!
nCr = n! ÷ (r! × (n − r)!)
  • Gold, silver and bronze among 8 runners: 8P3 = 8! ÷ 5! = 8 × 7 × 6 = 336 ways.
  • Picking 3 of those 8 runners for a relay, order ignored: 8C3 = 336 ÷ 3! = 56 ways.
  • Choosing 6 numbers from 49 in a lottery: 49C6 = 13,983,816, so one ticket has a 1 in 13,983,816 chance.

Trailing zeros and the number of digits

Every trailing zero of n! comes from a factor 10 = 2 × 5. There are always more 2s than 5s, so counting the 5s is enough. This is Legendre's formula: add ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + … until the terms reach 0. For 100!, that is 20 + 4 = 24 trailing zeros.

The number of digits is ⌊log₁₀ n!⌋ + 1, and log₁₀ n! is the sum log₁₀ 1 + log₁₀ 2 + … + log₁₀ n. For 100! the sum is about 157.97, so it has 158 digits. The calculator uses the same idea to give exact digit counts and trailing zeros up to 10,000,000!, far past the point where writing the number out is practical.

Show 100! with its 24 zeros

Factorials in code

Factorials overflow ordinary number types quickly. A signed 64-bit integer holds up to 20!. A double-precision float, the number type in JavaScript and most spreadsheets, reaches 170! ≈ 7.2574 × 10³⁰⁶, and 171! is already past its largest value, about 1.8 × 10³⁰⁸. JavaScript then returns Infinity, and Excel's FACT shows #NUM!. For exact results use big integers: Python's math.factorial(100) works out of the box, and in JavaScript a loop over BigInt values does the same.

Programming problems usually ask for n! mod m, often with m = 10⁹ + 7, so the answer fits in an integer. Multiply step by step and take the remainder after every multiplication; the result is the same as reducing the full number at the end. Once n reaches m, m itself is one of the factors and the remainder is 0. For a prime p, Wilson's theorem gives a check: (p − 1)! mod p = p − 1, for example 6! = 720 and 720 mod 7 = 6.

Show 400! mod 10⁹+7

Stirling's approximation

n! ≈ √(2πn) · (n/e)ⁿ

Stirling's formula estimates n! without multiplying everything. For 10! it gives about 3,598,696 against the true 3,628,800, 0.83% too low, and the error keeps shrinking as n grows (it is close to 1/(12n)). Physicists and statisticians use it to work with factorials far too large to compute. The calculator shows the estimate and its error next to every answer.

Double factorials and subfactorials

The double factorial n!! multiplies every second number: 9!! = 9 × 7 × 5 × 3 × 1 = 945 and 10!! = 10 × 8 × 6 × 4 × 2 = 3,840. It is not (n!)!. Double factorials of odd numbers show up in integrals and in the values of the gamma function at halves.

Show 9!! in the calculator

The subfactorial !n counts derangements, the orderings where nothing stays in its original place. If 4 people put their hats in a pile and each takes one back at random, !4 = 9 of the 24 possible outcomes give nobody their own hat. For larger n, !n is n! ÷ e rounded, so about 36.8% of all orderings are derangements.

Show the 9 derangements of 4 items

Factorials of fractions and negative numbers

The gamma function extends the factorial to other numbers: x! = Γ(x + 1). It matches n! at every whole number and draws a smooth curve between them. At halves it gives exact values with √π, so (1/2)! = √π/2 ≈ 0.8862 and (3/2)! = 3√π/4 ≈ 1.3293.

Show (1/2)! in the calculator

Negative whole numbers have no factorial. Going backwards, (n − 1)! = n! ÷ n gives 0! = 1! ÷ 1 = 1, and the next step would divide by 0. The gamma function has a pole at each negative whole number for the same reason. Negative fractions are fine: (−1/2)! = √π.

Frequently Asked Questions

What is 0 factorial?

0! = 1. It is the empty product: nothing is multiplied, and a product of nothing is 1, the same way a sum of nothing is 0. It also keeps n! = n × (n − 1)! working for n = 1, and there is exactly one way to arrange zero objects.

Show 0! in the calculator

What is 5 factorial?

5! = 5 × 4 × 3 × 2 × 1 = 120. It is the number of ways to put 5 different things in a row: 5 choices for the first place, 4 for the second, and so on.

Show 5! in the calculator

How do you calculate a factorial?

Multiply every whole number from n down to 1. 10! = 10 × 9 × 8 × … × 1 = 3,628,800. Each factorial is the previous one times n, so if you know 9! = 362,880, then 10! = 10 × 362,880. In Excel or Google Sheets use =FACT(10).

Show 10! in the calculator

How big is 52 factorial?

52! is about 8.0658 × 10⁶⁷, a number with 68 digits. It is the number of ways to order a deck of 52 cards, so a well-shuffled deck is almost certainly in an order that has never existed before.

Show all 68 digits of 52!

What is 100 factorial?

100! is about 9.3326 × 10¹⁵⁷. It has 158 digits, and the last 24 of them are zeros. The calculator shows every digit.

Show every digit of 100!

Can you take the factorial of a negative number?

Not of a negative whole number. Working backwards with (n − 1)! = n! ÷ n gives 0! = 1, but the next step, (−1)! = 0! ÷ 0, divides by zero. Negative numbers that are not whole do have values through the gamma function, for example (−1/2)! = √π ≈ 1.7725.

Show (−1/2)! in the calculator

What is the factorial of 1/2?

(1/2)! = √π/2 ≈ 0.8862. Factorials of fractions come from the gamma function, x! = Γ(x + 1), which matches n! at every whole number. For halves the answer is always a fraction times √π.

Show (1/2)! in the calculator