CCalculate.Studio

Factorial Calculator

The factorial of a non-negative whole number n, written n!, is the product of all positive whole numbers from 1 up to n. This calculator computes n! exactly for n up to 18 (the largest exact factorial representable without floating-point rounding in standard double-precision arithmetic), and in scientific notation for n up to 170, along with the count of trailing zeros and the natural logarithm of n!.

Last reviewed: 2026-07-07

Understanding how fast factorials grow

Factorial growth quickly outpaces exponential growth, as shown in the table below of exact and approximate values.

nn!Approx. magnitude
011
51201.2 × 10²
103,628,8003.6 × 10⁶
151,307,674,368,0001.3 × 10¹²
186,402,373,705,728,0006.4 × 10¹⁵
202,432,902,008,176,640,0002.4 × 10¹⁸
  • 18! (≈6.40 × 10¹⁵) is the largest factorial exactly representable as a standard double-precision integer without rounding error, since JavaScript's Number.MAX_SAFE_INTEGER is 2⁵³ − 1 ≈ 9.007 × 10¹⁵; this calculator therefore shows an exact value only up to n = 18.
  • For n from 19 to 170, only the scientific-notation approximation (and ln(n!)) is shown, since the exact integer would require more precision than standard floating-point arithmetic supports without a big-integer library.
  • Beyond n = 170, n! exceeds the largest value representable by standard double-precision floating-point numbers (roughly 1.8 × 10³⁰⁸) and overflows to infinity, so this calculator caps n at 170.

What is a factorial?

The factorial of a non-negative integer n, denoted n!, is defined as the product of all positive integers from 1 to n: n! = n × (n − 1) × (n − 2) × ... × 2 × 1. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. By definition, 0! = 1 (an empty product, the multiplicative identity), which is a standard convention used throughout combinatorics.

Factorials grow extremely quickly — far faster than exponential functions of n. 10! = 3,628,800, while 20! already exceeds 2.4 quintillion (2.43 × 10¹⁸), larger than the number of seconds since the Big Bang. This explosive growth is why factorials are typically shown in scientific notation for larger n, and why exact integer values become impractical to display beyond a certain point.

Factorials are foundational to combinatorics: they count the number of ways to arrange n distinct objects in order (permutations), and they appear as the denominators in the binomial coefficient formula used to count unordered selections (combinations). They also appear in probability theory, calculus (Taylor series coefficients), and many closed-form combinatorial identities.

How to use this factorial calculator

  1. Enter a whole number n between 0 and 170 (170! is close to the largest factorial that standard double-precision floating-point numbers can represent before overflowing to infinity).
  2. Read the result in scientific notation, which is always shown regardless of the size of n.
  3. For n ≤ 18, the exact integer value of n! is also shown, since larger factorials exceed the range of exactly-representable integers in standard double-precision arithmetic (2⁵³ ≈ 9.007 × 10¹⁵).
  4. Review the natural logarithm of n! (useful for working with very large factorials without overflow) and the number of trailing zeros in the exact decimal representation of n!.

How factorials, trailing zeros and ln(n!) are calculated

n! = n × (n − 1) × (n − 2) × ... × 2 × 1, with 0! = 1
ln(n!) = Σ ln(k) for k = 1 to n
Trailing zeros (Legendre's formula) = Σ ⌊n / 5ⁱ⌋ for i = 1, 2, 3, ...
Example: 10! = 3,628,800 (2 trailing zeros)

The defining recursive relationship is n! = n × (n − 1)!, with the base case 0! = 1. Worked example: 5! = 5 × 4! = 5 × 4 × 3! = 5 × 4 × 3 × 2! = 5 × 4 × 3 × 2 × 1! = 5 × 4 × 3 × 2 × 1 × 0! = 120 × 1 = 120.

For large n, the natural logarithm ln(n!) is computed as the sum Σ ln(k) for k = 2 to n, which avoids the overflow that would occur from multiplying the raw factorial directly. Scientific notation is then derived from this sum via the base-10 logarithm: log₁₀(n!) = ln(n!) ÷ ln(10), with the integer part giving the exponent and the fractional part (converted back with 10^x) giving the mantissa.

The number of trailing zeros in n! equals the number of times 10 divides n! evenly, which — since 10 = 2 × 5 and factors of 2 are always more abundant than factors of 5 in a factorial — reduces to counting factors of 5 using Legendre's formula: trailing zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ... Worked example for 10!: ⌊10/5⌋ = 2, ⌊10/25⌋ = 0, so 10! has 2 trailing zeros — confirmed by 10! = 3,628,800.

Common mistakes

  • Forgetting that 0! = 1, not 0 — this is a standard mathematical convention (an empty product equals 1), essential for combinatorial formulas to work correctly at their boundary cases.
  • Assuming factorials can be computed exactly for arbitrarily large n in standard arithmetic — beyond n = 18, exact integer values exceed what double-precision floating-point numbers can represent without rounding.
  • Confusing n! (factorial) with nⁿ (n to the power of n) — factorial multiplies a decreasing sequence of integers down to 1, while exponentiation multiplies n by itself n times; the two grow at different rates and diverge quickly (5! = 120 vs. 5⁵ = 3125).
  • Entering a negative number or a non-whole number — factorial is only defined for non-negative integers in this elementary sense (the Gamma function extends the concept to non-integers, but that is a separate, more advanced formula).

Frequently asked questions

What is n factorial?

n factorial (n!) is the product of all positive whole numbers from 1 up to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. By definition, 0! = 1.

Why is 0! equal to 1?

0! is defined as 1 by mathematical convention, representing an 'empty product' (a product of zero factors), which by convention equals the multiplicative identity, 1. This definition keeps combinatorial formulas like permutations and combinations consistent at their boundary cases — for example, there is exactly 1 way to arrange zero objects.

How fast do factorials grow?

Factorials grow faster than exponential functions of n. 10! is about 3.6 million, but 20! already exceeds 2.4 × 10¹⁸ (2.4 quintillion). This superexponential growth rate is why factorials appear in scientific notation for even moderately large n and why they are commonly cited as an example of extremely rapid growth in mathematics.

How many trailing zeros does 100! have?

Using Legendre's formula (summing ⌊100/5ⁱ⌋), 100! has ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24 trailing zeros. Trailing zeros come from factors of 10 = 2 × 5 in the product, and since factors of 2 are always more plentiful than factors of 5 in a factorial, counting factors of 5 alone gives the trailing zero count.

What is the largest factorial a calculator can compute exactly?

In standard double-precision floating-point arithmetic (used by JavaScript and most calculators), 18! is the largest factorial that can be represented as an exact integer, because 18! ≈ 6.40 × 10¹⁵ is below the safe-integer limit of 2⁵³ − 1 ≈ 9.007 × 10¹⁵, while 19! exceeds it. Larger factorials are typically shown in scientific notation.

References

  1. NIST Digital Library of Mathematical Functions (DLMF), §5.1 Gamma Function: Factorial Function. dlmf.nist.gov.
  2. Rosen KH. Discrete Mathematics and Its Applications. 8th ed. McGraw-Hill, 2018. (Factorials and combinatorics.)
  3. Graham RL, Knuth DE, Patashnik O. Concrete Mathematics. 2nd ed. Addison-Wesley, 1994. (Legendre's formula for factors in n!.)

Number Theory · All calculators

Related calculators

Guides & articles