ToolNimba

โ— Factorial Calculator

Shihab Mia By Shihab Mia ยท Updated 2026-07-13

n!
-
Expansion
-

Enter a whole number n from 0 to 10000 to compute n!. By definition 0! = 1.

The factorial of a non-negative integer n, written n!, is the product of every whole number from 1 up to n, so 5! = 5 x 4 x 3 x 2 x 1 = 120. This factorial calculator does that multiplication for you: type any whole number from 0 upward and it returns n! computed exactly (no rounding), tells you how many digits the answer has, and writes out the full expansion for small values. Factorials grow faster than any exponential, which is exactly why a dedicated tool helps once you pass 20 or so. Everything runs in your browser using BigInt arithmetic, so every digit is precise and nothing you type is sent anywhere.

What is the Factorial Calculator?

A factorial counts the number of ways to arrange n distinct objects in a row. With 3 books there are 3! = 6 possible orderings; with 5 books there are 5! = 120. That single idea, the number of arrangements (permutations), is why the factorial shows up all over probability, combinatorics, statistics and algebra. The formal definition is recursive: n! = n x (n - 1)!, with the base case 0! = 1. Each value is just the previous value multiplied by the next integer, which is also the fastest way to build a factorial table by hand.

The reason 0! is defined as 1 trips a lot of people up. There is exactly one way to arrange zero objects (the empty arrangement), so the count is 1, not 0. Mathematically it is an empty product, and an empty product is defined to equal 1 for the same reason an empty sum equals 0. That value also keeps the recursive rule and formulas like the binomial coefficient consistent, so treat 0! = 1 as a definition that makes everything else work, not as something you derive by multiplying.

Factorials grow faster than any exponential. 10! is already 3,628,800, 20! has 19 digits, and 100! has 158 digits. That explosive growth is exactly why ordinary floating-point arithmetic fails: a normal JavaScript number cannot represent integers above about 9 quadrillion (2 to the power 53) without losing precision, so 21! onward comes back rounded and often shown in scientific notation. This calculator uses BigInt, an arbitrary-precision integer type, so every digit of the answer is exact no matter how large n is, up to the input cap that keeps the page responsive.

When n gets large enough that the exact digits stop being useful, mathematicians reach for Stirling approximation, n! is approximately the square root of (2 x pi x n) times (n / e) to the power n. It does not give the exact integer, but it nails the order of magnitude and the number of digits, and it is the standard tool for estimating factorials in physics, information theory and the analysis of sorting algorithms. For example, Stirling puts 100! at about 9.33 times 10 to the power 157, which matches the exact 158-digit value.

Two other properties competitors often skip are worth knowing. First, the number of trailing zeros at the end of n! is easy to count without computing the whole number: every trailing zero comes from a factor of 10, which is 2 times 5, and fives are the scarce factor, so the count is floor(n/5) + floor(n/25) + floor(n/125) + ... (Legendre formula). Second, the plain factorial is only defined on non-negative integers, but the gamma function extends it smoothly to fractions and even negative and complex numbers, with the identity n! = gamma(n + 1). Both ideas are covered in the tables and FAQ below.

When to use it

  • Counting permutations: how many ways n distinct items can be ordered (n!).
  • Working out combinations and binomial coefficients, where factorials appear in the formula C(n, k) = n! / (k! x (n - k)!).
  • Computing probabilities in statistics, such as those built on the binomial or Poisson distributions.
  • Checking homework or exam answers in algebra, discrete math and probability courses.
  • Estimating very large factorials with Stirling approximation in physics, information theory and algorithm analysis.
  • Exploring how fast factorials grow compared with squares, cubes and powers of two.

How to use the Factorial Calculator

  1. Type a non-negative whole number into the n field (for example 5, 10 or 100).
  2. Read n! in the result box; the answer is computed exactly, with no rounding.
  3. Check the digit count shown beneath the result to see how large the number is.
  4. For small n, read the expansion (for example 5! = 5 x 4 x 3 x 2 x 1 = 120) to see how it is built.
  5. Use Copy to grab the full result, or the quick-pick buttons to try common values.

Formula & method

n! = n x (n - 1) x (n - 2) x ... x 2 x 1, defined recursively as n! = n x (n - 1)! with the base case 0! = 1. For large n, Stirling approximation gives n! roughly equal to sqrt(2 x pi x n) x (n / e) to the power n. The plain factorial is only defined for non-negative integers.
How fast n! grows (digits in the answer)n! = n x (n - 1) x (n - 2) x ... x 2 x 1, with 0! = 135!710!1920!6550!158100!Each bar is the digit count of n!, computed exactly with BigInt

Worked examples

Compute 5! by hand to see how the product is built up.

  1. Start from the definition: 5! = 5 x 4 x 3 x 2 x 1.
  2. Multiply step by step: 5 x 4 = 20.
  3. 20 x 3 = 60.
  4. 60 x 2 = 120.
  5. 120 x 1 = 120 (multiplying by 1 changes nothing).

Result: 5! = 120

Use the recursive rule to get 6! from 5! without starting over.

  1. The rule is n! = n x (n - 1)!, so 6! = 6 x 5!.
  2. You already know 5! = 120.
  3. Multiply: 6! = 6 x 120 = 720.
  4. Check against the full product: 6 x 5 x 4 x 3 x 2 x 1 = 720. It matches.

Result: 6! = 720

Count how many ways 4 people can stand in a queue.

  1. Ordering 4 distinct people is a permutation, so the count is 4!.
  2. There are 4 choices for the first spot, then 3 left, then 2, then 1.
  3. Multiply the choices: 4 x 3 x 2 x 1.
  4. 4 x 3 = 12, then 12 x 2 = 24, then 24 x 1 = 24.

Result: 4! = 24 different queues

Count the trailing zeros of 25! without computing the whole number.

  1. Every trailing zero comes from a factor of 10 = 2 x 5, and 5s are rarer than 2s, so count the 5s.
  2. Use Legendre formula: add floor(25 / 5) + floor(25 / 25) + floor(25 / 125) + ...
  3. floor(25 / 5) = 5 and floor(25 / 25) = 1; higher terms are 0.
  4. Add them: 5 + 1 = 6.

Result: 25! ends in 6 zeros (25! = 15,511,210,043,330,985,984,000,000)

Factorials of 0 through 15 (and how quickly they grow)

nn!Number of digits
011
111
221
361
4242
51203
67203
75,0404
840,3205
9362,8806
103,628,8007
1139,916,8008
12479,001,6009
136,227,020,80010
1487,178,291,20011
151,307,674,368,00013

How big larger factorials get

nNumber of digits in n!Starts with
20192,432,902,008,176,640,000
252615,511,210,043...
506530,414,093,201...
10015893,326,215,443...
10002,5684,023,872,600...

Trailing zeros at the end of n! (Legendre formula)

nTrailing zeros in n!Computed as
51floor(5/5) = 1
102floor(10/5) = 2
2565 + 1
501210 + 2
1002420 + 4
1000249200 + 40 + 8 + 1

Common mistakes to avoid

  • Thinking 0! equals 0. By definition 0! = 1, not 0. There is exactly one way to arrange nothing (the empty arrangement), and this value keeps formulas like combinations consistent. It is a definition (an empty product), not a multiplication, so do not try to compute it as a product.
  • Taking the factorial of a negative number or a fraction. The plain factorial is only defined for non-negative integers. There is no value for (-3)! or 2.5! in ordinary arithmetic. The gamma function extends factorials to other numbers, but that is a different, more advanced tool.
  • Trusting a normal calculator for large factorials. Standard floating-point numbers lose precision above about 9 quadrillion, so many calculators return 21! and beyond as rounded approximations in scientific notation. This tool uses exact BigInt arithmetic, so every digit is correct.
  • Confusing n! with n squared or with multiplication by n. A factorial multiplies every integer down to 1, so it grows far faster than squaring. 5! = 120 but 5 squared = 25, and the gap widens explosively as n rises.
  • Mixing up the factorial (n!) and the double factorial (n!!). The double factorial n!! multiplies only every other integer, so 7!! = 7 x 5 x 3 x 1 = 105, which is not the same as (7!)!. The double bang is a distinct function, not a factorial applied twice.
  • Assuming a programming language factorial never overflows. In many languages a plain integer factorial silently overflows or returns Infinity past a certain size (for example past 170! in double precision). Use an arbitrary-precision type like BigInt, as this tool does, when you need the exact value.

Glossary

Factorial
The product of all positive integers up to and including n, written n!. For example 4! = 4 x 3 x 2 x 1 = 24.
n!
The notation for the factorial of n, read aloud as "n factorial".
Permutation
An ordered arrangement of objects. The number of permutations of n distinct objects is n!.
Empty product
The product of no factors, defined to equal 1, which is why 0! = 1.
BigInt
A data type for arbitrarily large whole numbers with no rounding, used here so even huge factorials are exact.
Combination
A selection of items where order does not matter, counted with factorials as C(n, k) = n! / (k! x (n - k)!).
Stirling approximation
A formula that estimates large factorials: n! is roughly sqrt(2 x pi x n) x (n / e) to the power n. It gives the order of magnitude, not the exact digits.
Gamma function
A continuous function that extends the factorial to fractions and complex numbers, with n! = gamma(n + 1) for whole numbers.

Frequently asked questions

What is a factorial?

A factorial of a non-negative integer n, written n!, is the product of every whole number from 1 up to n. For example 5! = 5 x 4 x 3 x 2 x 1 = 120. It counts the number of ways to arrange n distinct objects in order.

Why is 0! equal to 1?

0! is defined as 1 because there is exactly one way to arrange zero objects: the empty arrangement. Setting 0! = 1 also keeps the recursive rule n! = n x (n - 1)! and formulas like the binomial coefficient working correctly. It is a definition (an empty product) that makes everything else consistent.

How do you calculate a factorial by hand?

Multiply every integer from n down to 1. For 6! you compute 6 x 5 x 4 x 3 x 2 x 1, which builds up as 6 x 5 = 30, 30 x 4 = 120, 120 x 3 = 360, 360 x 2 = 720, 720 x 1 = 720. You can also use the shortcut n! = n x (n - 1)! if you already know the previous factorial.

Can you take the factorial of a negative number or a decimal?

No. The ordinary factorial is only defined for non-negative whole numbers, so values like (-3)! or 2.5! have no factorial in basic arithmetic. The gamma function generalizes factorials to other numbers, giving for instance 0.5! = gamma(1.5) which is about 0.886, but that is a separate, more advanced concept not covered by this calculator.

How large a factorial can this calculator handle?

It accepts any whole number n from 0 up to 10,000 and returns the exact result. The cap keeps the page responsive, since the digit count itself becomes enormous (10,000! has more than 35,000 digits). Because the tool uses BigInt, every digit it shows is precise, with no rounding.

Why does my phone calculator give a different, rounded answer?

Most calculators use floating-point numbers, which cannot store integers above roughly 9 quadrillion exactly, so they round large factorials and often display them in scientific notation. This tool computes with BigInt, an exact integer type, so it returns the full, correct value digit for digit.

How do you estimate a very large factorial quickly?

Use Stirling approximation: n! is roughly sqrt(2 x pi x n) x (n / e) to the power n. It does not give the exact integer but nails the order of magnitude and the digit count, which is often all you need. For example, Stirling estimates 100! as about 9.33 x 10 to the power 157, matching the exact 158-digit value.

How many zeros are at the end of a factorial?

Count the factors of 5 in n!, because each trailing zero needs a 5 paired with a more common 2. Using Legendre formula, the count is floor(n/5) + floor(n/25) + floor(n/125) + ... So 100! ends in 20 + 4 = 24 zeros, and 1000! ends in 249 zeros. You never have to compute the full number to get this.

What is a double factorial (n!!)?

A double factorial multiplies only every other integer down to 1, so it depends on whether n is odd or even. For odd n, 7!! = 7 x 5 x 3 x 1 = 105; for even n, 8!! = 8 x 6 x 4 x 2 = 384. It is a distinct function and is not the same as applying the factorial twice.

Where are factorials used in real life?

Factorials count arrangements and selections, so they appear in probability (card, lottery and dice odds), statistics (binomial and Poisson distributions), scheduling and routing problems, cryptography, and the analysis of algorithms, where n! bounds the number of orderings a comparison sort must distinguish. Anywhere you count how many ways things can be ordered or chosen, a factorial is usually involved.

Sources