Article

Factorial: How to Calculate n! (Formula, 0! = 1 and Examples)

The factorial of a natural number n, written n!, is the product of all whole numbers from 1 to n. By convention 0! = 1. This article gives the formula, the recursion n! = n · (n − 1)!, a chart of values, the reason why 0! = 1, how factorials are used in combinations and four worked examples. You can check your own number in the factorial calculator. For n = 10 the result is 3,628,800.

Last updated:

Find the factorial of a number in the factorial calculator. The number of arrangements is in the permutations calculator.

The factorial formula

The factorial of a natural number n is the product of all whole numbers from 1 to n. It can also be defined recursively: each factorial is the number n times the factorial of the number one smaller.

n! = 1 · 2 · 3 · … · n
example: 5! = 1 · 2 · 3 · 4 · 5 = 120
n! = n · (n − 1)!
0! = 1

nn!Recursion
01by convention
111 · 0! = 1
222 · 1
363 · 2
4244 · 6
51205 · 24
67206 · 120
75,0407 · 720
840,3208 · 5,040
9362,8809 · 40,320
103,628,80010 · 362,880
12479,001,60012 · 39,916,800
151,307,674,368,00015 · 87,178,291,200
202,432,902,008,176,640,00020 · 121,645,100,408,832,000

The factorial is defined for nonnegative whole numbers. Negative integers and fractions have no ordinary factorial, and for fractions the gamma function is used.

The fast growth of factorials from 1! to 10!Ten horizontal bars for 1! to 10!. The length of a bar matches the number of digits of the result, from 1 digit for 1! to 7 digits for 10!, which is 3,628,800.1!12!23!64!245!1206!7207!5,0408!40,3209!362,88010!3,628,800
The bar length is the number of digits in the result. The first ten factorials grow from 1 to 3,628,800, and 20! already has 19 digits.

Try it with an example

Example: n = 10. The value is already stored in the link to the calculator.

Number n
10
Result
10! = 3,628,800

Open the calculator with these numbers

The calculator reads the values from the page address and shows the result right away. You can change them freely.

How the calculator works

The calculator takes the integer part of the number you enter, multiplies the numbers from 2 to n and shows the result. For n up to 18 the result is exact, and from 19! on it exceeds the range of integers that the browser can represent exactly (2^53), so it is shown in the approximate form ≈ m × 10^e. For n up to 20 it also shows the product path, and for n up to 12 bars of the successive factorials. The largest number is n = 170, which is 7.2574 × 10^306. A negative number is treated as 0, so the result is 1. The calculator does not compute fractional factorials or the gamma function.

Why 0! = 1

The statement 0! = 1 is a convention that follows from the recursion and from counting. From n! = n · (n − 1)! for n = 1 we get 1! = 1 · 0!, and since 1! = 1, 0! has to be 1. The empty product, the product of zero factors, equals 1 by definition.

This convention keeps the formulas of combinatorics valid. The number of ways to choose zero items from n is C(n, 0) = n! ÷ (0! · n!) = 1, and there is one way to arrange an empty set. The combinations formula is described in Combinations: Formula and Examples, and you can compute your own values in the combinations calculator.

How fast the factorial grows

The factorial grows faster than a power and faster than an exponential. Already 10! = 3,628,800, and 20! = 2,432,902,008,176,640,000 has 19 digits. The number of possible orders of a deck of 52 cards is 52! ≈ 8.0658 × 10^67, a number with 68 digits, so almost every proper shuffle gives an order that has never occurred before.

The calculator shows results from 19! on in approximate form, because such large integers do not fit exactly in a floating-point number, and for n greater than 170 the result exceeds the range. You can compare the growth of powers in the exponent calculator.

Factorials in permutations and combinations

The factorial counts the ways to put n different items in a row. For 5 people that is 5! = 120 arrangements, which the permutations calculator computes. The number of ways to choose k items from n without regard to order is C(n, k) = n! ÷ (k! · (n − k)!). For n = 8 and k = 3 that is 8! ÷ (3! · 5!) = 40,320 ÷ (6 · 120) = 56.

When you divide factorials you do not have to compute the large values: 8! ÷ 6! = 8 · 7 = 56, because the common factors cancel. A choice in which order matters is counted in the variations calculator, and the common divisors of numbers in the GCD calculator and the article GCD: Greatest Common Divisor.

Four worked examples

You can repeat each example in the factorial calculator.

1. The factorial of 5

The basic calculation.

  1. Enter n = 5.
  2. Multiply 1 · 2 · 3 · 4 · 5.
  3. The result is 120.
  4. Check: 5 · 4! = 5 · 24 = 120.

2. The factorial of 10

Ten consecutive numbers.

  1. Enter n = 10.
  2. Multiply 1 · 2 · … · 10.
  3. The result is 3,628,800.
  4. Check: 10 · 9! = 10 · 362,880.

3. The factorial of 20

A result beyond the exact range of the calculator.

  1. Enter n = 20.
  2. The exact value is 2,432,902,008,176,640,000.
  3. The calculator shows it in the approximate form ≈ 2.432902 × 10^18.
  4. The number has 19 digits.

4. Choosing 3 items from 8

A factorial in combinations.

  1. Compute 8! = 40,320, 3! = 6 and 5! = 120.
  2. Divide 8! ÷ (3! · 5!).
  3. The denominator is 6 · 120 = 720.
  4. The result is 56 ways.

Common mistakes when calculating factorials

  • Assuming 0! = 0 — by convention 0! = 1, because the empty product equals 1.
  • Multiplying by 0 — the product starts at 1, so the factor 0 does not appear in n! for n ≥ 1.
  • Confusing n! with n² — for n = 5 we have 5! = 120, while 5² = 25.
  • Leaving out the last factor — 5! has five factors from 1 to 5, not from 1 to 4.
  • Taking the factorial of a negative number — the ordinary factorial is not defined for negative numbers.
  • Computing big factorials in full when dividing — cancel the common factors instead, for example 8! ÷ 6! = 56.
  • Assuming the result is always exact — from 19! the calculator shows an approximation, and exact values need big-integer arithmetic.

Frequently asked questions

How do you calculate a factorial?

Multiply all whole numbers from 1 to n. For n = 5 the result is 1 · 2 · 3 · 4 · 5 = 120.

What is 0 factorial?

By convention 0! = 1. It follows from the recursion 1! = 1 · 0! and from the fact that the empty product equals 1.

What is 10 factorial?

The factorial of 10 is 10! = 3,628,800.

How do you simplify 8! ÷ 6!?

Cancel the common factors from 1 to 6. What remains is 8 · 7 = 56, so you do not have to compute both factorials in full.

What does 5! = 120 mean?

The exclamation mark denotes a factorial. The statement 5! = 120 says that the product 1 · 2 · 3 · 4 · 5 equals 120.

Why is 52 factorial such a big number?

The factorial grows very fast. The number 52! is about 8.0658 × 10^67, which is how many orders a deck of 52 cards can be in.

What is the largest factorial the calculator handles?

It handles n up to 170, which is 7.2574 × 10^306. For a larger n the result exceeds the range, and from 19! on it is shown in approximate form.

What does the calculator do with a fraction or a negative number?

For a fraction it takes the integer part, so 5.7 gives 5!. It treats a negative number as 0, so the result is 1.

Find the factorial of your own number

Enter a number n in the factorial calculator and read n!, the previous factorial and the product path.

The number of arrangements is in the permutations calculator, and a choice without order in the combinations calculator.