What Is a Factorial (n!)? Formula, Growth & Why 0! = 1

In mathematics, the factorial of a non-negative integer n, written n! (pronounced "n factorial"), equals the product of every positive whole number from n down to 1. First symbolized with the exclamation mark by French mathematician Christian Kramp in 1808, factorials lie at the heart of permutations, combinations, Maclaurin power series, statistical distributions, and algorithm complexity bounds.

Standard Integer Factorial: n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 (with 0! = 1)
Stirling's Asymptotic Formula: n! ≈ √(2πn) × (n ÷ e)^n
Legendre Trailing Zeros: Z(n!) = floor(n/5) + floor(n/25) + floor(n/125) + ...
Continuous Gamma Extension: x! = Γ(x + 1) = Integral_0^Inf (t^x · e^(−t)) dt (for x > −1)

Why does 0! strictly equal 1 rather than zero? Three separate proofs force 0! = 1: first, dividing down the recurrence (n − 1)! = n! ÷ n at n = 1 gives 0! = 1! ÷ 1 = 1; second, there is exactly 1 way to arrange an empty set of zero items; and third, setting 0! = 1 keeps combinatorial formulas like C(n, n) = n! ÷ (n! · 0!) = 1 and Taylor coefficients x⁰ ÷ 0! = 1 free of division by zero.

Super-exponential scaling chart comparing factorial n! against exponential 2^n and quadratic n^2 up to n=15, alongside 12! = 479,001,600, 52! card shuffles, and Stirling error shrinkage from -1.65% down to -0.08%
Diagram 1: Super-exponential growth of n! relative to 2^n and n^2, plus asymptotic convergence of Stirling's approximation.

Super-Exponential Growth & Stirling's Asymptotic Approximation

Because every increment of n multiplies the entire previous product by a larger integer rather than a fixed base, n! overtakes any constant exponential c^n cleanly once n grows past e × c. While 2¹² = 4,096 takes four digits, 12! = 479,001,600 already reaches nine digits, and shuffling a standard 52-card deck spans 52! ≈ 8.0658 × 10⁶⁷ (68 decimal digits)!

Because standard IEEE-754 floating-point numbers overflow to Infinity once n >= 171, our Factorial Calculator evaluates integer inputs all the way to n = 5,000 using exact BigInt multiplication while simultaneously showing James Stirling's famous asymptotic estimate √(2πn) · (n / e)^n. Stirling's relative error shrinks inversely proportional to 1 / (12n): from -1.65% at n = 5 to -0.69% at n = 12, and less than 0.083% by n = 100.

n Exact Factorial n! Digits Trailing Zeros Stirling Error
0! and 1! 1 1 0 -7.79% (at n=1)
5! 120 3 1 -1.651%
12! 479,001,600 9 2 -0.692%
20! 2,432,902,008,176,640,000 19 4 -0.416%
52! (Cards) 8.065818 × 10^67 68 12 -0.160%
100! 9.332622 × 10^157 158 24 -0.083%

Legendre's Formula: Counting Trailing Zeros in Any Factorial n!

How many zeros sit at the right-hand end of 100! without computing all 158 digits by hand? Every trailing zero represents one multiplication by 10 = 2 × 5. Because prime factors of 2 occur far more frequently than factors of 5 in sequential integers (100! contains 97 factors of 2), the bottleneck is strictly the number of prime factors of 5 inside n!.

Adrien-Marie Legendre proved that the exact multiplicity of any prime p inside n! equals the integer floor series sum_{k >= 1} floor(n / p^k). For p = 5 and n = 100, single multiples of 5 contribute floor(100 / 5) = 20 fives, while squares 25, 50, 75, 100 each hide a bonus second factor of 5 (floor(100 / 25) = 4), producing 20 + 4 = 24 trailing zeros instantly!

Legendre trailing zeros breakdown for 100 factorial counting 97 twos versus 20 multiples of 5 plus 4 bonus multiples of 25 totaling 24 zeros, alongside benchmarks for 5!, 12!, 25!, 52!, and 100!
Diagram 2: Deriving 24 trailing zeros in 100! via Legendre's factor-of-5 floor formula and benchmarking 5! through 100!.

Double Factorials (n!!), Derangements (!n) & Continuous Gamma (x! = Γ(x + 1))

Beyond ordinary factorials, three classic generalizations appear regularly across calculus, physics, and probability:

  • Double Factorial (n!!): Skips every second factor rather than multiplying consecutive integers. For odd integers, 9!! = 9 × 7 × 5 × 3 × 1 = 945; for even integers, 8!! = 8 × 6 × 4 × 2 = 384 = 2⁴ · 4!. Notice carefully that (n!)! (taking factorial twice) differs completely from double factorial n!!!
  • Subfactorial / Derangements (!n): Counts permutations of n items where zero objects remain in their original position (for instance, drawing Secret Santa names where nobody pulls their own name). Recurrence !n = (n − 1)(!(n−1) + !(n−2)) gives !4 = 9 (out of 24) and !9 = 133,496, and the fraction !n ÷ n! rapidly converges to 1/e ≈ 36.7879%.
  • Continuous Gamma Extension (x! = Γ(x + 1)): Leonhard Euler extended factorials smoothly to real and decimal arguments via the Gamma integral Γ(z). Using Lanczos coefficients in Mode 4, fractional half-integers connect directly to π: (-0.5)! = Γ(0.5) = √π = 1.772454, 0.5! = √π ÷ 2 = 0.886227, and 4.5! = (945 / 32)√π = 52.342778!
Continuous Gamma factorial curve x! = Gamma(x+1) passing smoothly through (-0.5)!=1.77, 0!=1, 0.5!=0.89, 3!=6, 4!=24, and 4.5!=52.34, alongside cards for 9!!=945, 8!!=384, and derangements !9=133,496
Diagram 3: Continuous Gamma interpolation across non-integer inputs (left) paired with double factorials n!! and Secret Santa derangements !n (right).

2 Worked Examples

Example 1: Computing 100! Trailing Zeros, 12! Stirling Error & Ratio 12! ÷ 8!

Part A (Exact 12! & Factorial Ratio in Modes 1 & 3): Evaluate 12!, check Stirling's estimate, and simplify the division 12! ÷ 8! without full expansion:

  1. Evaluate 12!: Multiplying 12 × 11 × ... × 1 yields 479,001,600 (9 decimal digits, ending in 2 trailing zeros from factors 5 and 10).
  2. Compare Stirling estimate: √(24π) · (12 / e)¹² ≈ 8.6832 × 54,782,360 = 475,687,486.47, within -0.692% of exact 12!.
  3. Cancel 12! ÷ 8! via Mode 3: Rather than dividing 479,001,600 ÷ 40,320, cancel 8! directly: 12 × 11 × 10 × 9 = 11,880!

Part B (Trailing Zeros of 100!): Apply Legendre's formula cleanly: floor(100/5) + floor(100/25) + floor(100/125) = 20 + 4 + 0 = 24 trailing zeros at the end of all 158 digits of 100!.

Example 2: Odd/Even Double Factorials, Secret Santa Derangements & Decimal Gamma 4.5!

Part A (Double & Subfactorial in Mode 2 with n = 9): Nine coworkers draw names from a hat. Find 9!!, the exact number of ways nobody draws their own name (!9), and the probability of zero self-draws:

  1. Odd double factorial 9!!: Multiply odd steps only: 9 × 7 × 5 × 3 × 1 = 945 (whereas even 8!! = 8 × 6 × 4 × 2 = 384).
  2. Compute derangements !9: Total orders equal 9! = 362,880. Dividing 362,880 ÷ e ≈ 133,496.09 gives exact integer !9 = 133,496! Dividing 133,496 ÷ 362,880 gives a 36.7879% chance of a clean gift exchange with zero self-assignments.

Part B (Decimal Gamma 4.5! in Mode 4): Compute 4.5! = Γ(5.5) by repeatedly applying the recurrence Γ(z + 1) = z · Γ(z) down to Γ(0.5) = √π ≈ 1.77245385: 4.5 × 3.5 × 2.5 × 1.5 × 0.5 × √π = (945 ÷ 32) × 1.77245385 = 52.342778!

Where Factorials Appear in Calculus, Statistics & Computer Science

Beyond counting arrangements, factorials serve as the foundational scaling denominator in continuous calculus and algorithm analysis. Every smooth function's Maclaurin and Taylor polynomial expansion scales each higher derivative term by 1 ÷ k! so infinite sums converge rapidly across all real inputs: Euler's constant equals e = 1/0! + 1/1! + 1/2! + 1/3! + ..., while sin(x) and cos(x) alternate powers over odd and even factorials (x³ ÷ 3!, x² ÷ 2!).

In probability theory, factorials power the discrete Poisson distribution (e^(−λ) · λ^k ÷ k!) for rare event arrivals, the Binomial and Multinomial PMFs, and hypergeometric likelihood tests. In computer science, algorithms with O(n!) factorial time complexity, such as brute-force Traveling Salesman route enumeration, become computationally intractable past n = 15 cities because 15! already exceeds 1.3 trillion paths, motivating dynamic programming and heuristic approximations instead.

Factorial Formulas in Excel, Google Sheets & Python

Evaluate integer factorials, double factorials, and continuous Gamma extensions in spreadsheets or Python:

Excel / Sheets Standard n!: =FACT(n)
Excel / Sheets Double Factorial n!!: =FACTDOUBLE(n)
Excel / Sheets Gamma Extension x!: =GAMMA(x + 1) [or =EXP(GAMMALN(x + 1))]
Python Standard Exact Integer n!: math.factorial(n)
Python Continuous Decimal x!: math.gamma(x + 1)

5 Common Factorial Mistakes to Avoid

  1. Confusing Double Factorial n!! With Nested Factorial (n!)!: For n = 4, double factorial skips by 2 (4!! = 4 × 2 = 8), whereas applying factorial twice gives (4!)! = 24! ≈ 6.2 × 10²³!
  2. Thinking Factorials Are Undefined at Zero: Setting 0! = 1 is algebraically required by n! = n × (n − 1)! and preserves every combinatorial and calculus identity.
  3. Forgetting Multiples of 25, 125, and 625 in Trailing Zeros: Stopping at floor(n / 5) undercounts zeros whenever n >= 25 because 25 carries two fives and 125 carries three fives.
  4. Trying Negative Integers Inside Gamma: While decimals like -0.5! = √π are completely finite, negative integers (-1, -2, -3...) hit vertical poles where Γ(0), Γ(-1), etc. diverge to infinity.
  5. Computing 12! ÷ 8! by Expanding Both Numbers First: Even modest ratios like 200! ÷ 197! = 200 × 199 × 198 = 7,880,400 overflow regular 64-bit floats if not canceled algebraically beforehand.

Related Combinatorics & Probability Tools

Use factorials as building blocks inside our other discrete math and statistics solvers in the Math & Statistics hub:

Verify how Staticnexa tests BigInt multiplication and Lanczos Gamma accuracy in our Editorial & Mathematical Accuracy Policy.

Frequently Asked Questions

Why does 0 factorial (0!) equal 1?

Using the backward recurrence (n - 1)! = n! / n at n = 1 forces 0! = 1! / 1 = 1. It also matches the empty product rule (multiplying zero numbers yields the multiplicative identity 1) and keeps C(n, 0) = 1 valid.

How do you find the number of trailing zeros in n!?

Use Legendre's formula for factors of 5: floor(n/5) + floor(n/25) + floor(n/125) + ... stopping once 5^k > n. For 100!, floor(100/5) + floor(100/25) = 20 + 4 = 24 trailing zeros.

What is the difference between n!! (double factorial) and (n!)!?

Double factorial n!! steps down by 2 (e.g., 8!! = 8*6*4*2 = 384 and 9!! = 9*7*5*3*1 = 945), whereas (n!)! computes the factorial of n! itself (e.g., (4!)! = 24!).

Can you take the factorial of a decimal or fraction like 0.5! or 4.5!?

Yes! The continuous Gamma function extends factorials via x! = Gamma(x + 1) for any real number x > -1. In particular, (-0.5)! = sqrt(pi) = 1.77245, 0.5! = sqrt(pi)/2 = 0.88623, and 4.5! = 52.34278.

What is a subfactorial (!n) or derangement?

Subfactorial !n counts permutations of n items where NO item ends up in its original position. For n >= 1, !n equals the nearest integer to n! / e (~36.79% of all n! permutations).

What is the largest factorial a standard 64-bit calculator can hold?

Standard IEEE-754 double-precision floating-point numbers overflow to Infinity at 171! (~1.24e309). Because this calculator uses arbitrary-precision BigInt math, it computes exact digits cleanly up to 5,000!.

Mathematical References & Standards