Factorial Calculator

Calculate the factorial of any non-negative integer

Enter a whole number from 0 to 170. The result shows n!, the number of digits, and values for n-1 and n+1 for context.

What is a factorial and why does it grow so fast

The factorial of a non-negative integer n, written as n!, is the product of all positive integers from 1 up to n. By definition, 0! = 1. So 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 10! = 3,628,800, and 20! = 2,432,902,008,176,640,000. Factorials grow extremely quickly — faster than any polynomial and faster than any exponential with a fixed base. By 100!, the number has 158 digits, and by 170!, it has 307 digits and is close to the maximum value representable in standard 64-bit floating-point arithmetic.

Factorials appear throughout mathematics, statistics, and computer science. The most common use is in counting permutations: n! is the number of ways to arrange n distinct items in a sequence. If you have 5 books, there are 5! = 120 different orders in which you can arrange them on a shelf. Factorials also appear in the formulas for combinations and permutations (C(n, r) and P(n, r)), in binomial coefficients used in probability and the binomial theorem, in Taylor and Maclaurin series expansions of functions like e^x and sin(x), and in the formulas for number theory results.

For results above n = 20, this calculator shows the value in scientific notation because the numbers become too large to read as integers. The number of digits in n! is shown using Stirling's approximation approach via summing logarithms of all factors, which is more numerically stable than direct multiplication for large n.

The maximum supported value is n = 170. This is because 171! exceeds the maximum finite value of a 64-bit double-precision floating-point number (approximately 1.8 x 10^308). Above this limit the result would be listed as Infinity in JavaScript, which is not useful. For values beyond 170, arbitrary-precision arithmetic libraries are needed.

Key factorial values for reference

0! = 1 (by definition). 1! = 1. 5! = 120. 10! = 3,628,800. 12! = 479,001,600. 15! = 1,307,674,368,000. 20! = 2.43 x 10^18. 52! is approximately 8.07 x 10^67, which is the number of ways to shuffle a standard 52-card deck (an astronomically large number, larger than the number of atoms in the observable universe). 100! is approximately 9.33 x 10^157. These values illustrate how factorials produce numbers of staggering size even for relatively small inputs.

Recursive definition and practical computation

Factorials can be defined recursively: n! = n x (n - 1)!. This means 5! = 5 x 4!, and 4! = 4 x 3!, and so on down to 0! = 1. This recursive structure is used in computer science to illustrate recursion as a concept, and in mathematical proofs where a result for n is derived from the result for n - 1. In practice, iterative computation (multiplying from 1 up to n in a loop) is more efficient and avoids the call-stack depth limitations of recursive code. This calculator uses the iterative approach for all values.

Last updated: 2026-05-06