Skip to content

Factorial Calculator

Calculate factorial with instant, accurate results and clear step-by-step output.

By CalcGenius Editorial TeamLast reviewed August 28, 20253 min read
Factorial Calculator (n!)

Enter an integer from 0 to 170. For n > 170 the result overflows IEEE 754 (171! ≈ 1.24×10³⁰⁹). The calculator shows Stirling's approximation and digit count even when overflow occurs.

📊
Enter your values and click Calculate

About

The factorial of a non-negative integer n, written n!, is the product of all positive integers from 1 to n: n! = n × (n−1) × (n−2) × … × 1. By convention 0! = 1 (the empty product equals the multiplicative identity). So 5! = 5×4×3×2×1 = 120, 10! = 3,628,800, and 20! ≈ 2.43×10¹⁸. Factorial grows super-exponentially — faster than any exponential aⁿ.

Factorials count arrangements. The number of permutations (orderings) of n distinct items is n!. The number of combinations (subsets of size k) is "n choose k" = n! / (k!(n−k)!) — the binomial coefficient. This makes factorial the foundation of combinatorics, the binomial theorem, Pascal's triangle, and the binomial distribution in probability theory. The binomial coefficient "n choose k" appears in everything from Pascal's triangle to the expansion of (a+b)^n to the probability of k successes in n Bernoulli trials.

In analysis, the factorial is extended to all complex numbers via the gamma function: Γ(n) = (n−1)! for non-negative integers, and more generally Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt for Re(z) > 0. The gamma function lets you take "factorials" of non-integer arguments — for example, Γ(½) = √π, so (−½)! = √π. This extension is essential in statistics (chi-squared distribution, beta distribution) and in the residue theorem of complex analysis.

Stirling's approximation n! ≈ √(2πn) × (n/e)ⁿ is the workhorse for large factorials. The relative error goes to 0 as n → ∞, and the logarithmic form log(n!) ≈ n·log(n) − n + 0.5·log(2πn) gives the number of digits directly without computing the value. This is the basis for the chi-squared approximation to the binomial, the Poisson limit, and the saddle-point method in asymptotic analysis.

JavaScript numbers are 64-bit IEEE 754 doubles, which overflow at about 1.8×10³⁰⁸. Since 171! ≈ 1.24×10³⁰⁹, the factorial overflows to Infinity for n ≥ 171. For larger n, use BigInt (arbitrary precision integers) or compute log factorials directly. This calculator detects the overflow and shows the Stirling approximation and digit count, which remain finite. For exact large-n factorials, switch to a computer algebra system like Mathematica, Maple, or SymPy.

How to Use

  1. 1
    Enter a non-negative integer
    Type any integer from 0 to 170. 0! = 1 by convention. For n > 170 the result overflows IEEE 754; the calculator shows the Stirling approximation and digit count instead.
  2. 2
    Read the factorial value
    The hero shows n! computed iteratively. For large n (typically ≥ 15), the result is shown in scientific notation for readability.
  3. 3
    Check the number of digits
    The breakdown shows how many digits n! has — useful for understanding factorial growth. Computed via log10(n!) = Σ log10(k).
  4. 4
    Compare with Stirling's approximation
    The Stirling's formula approximation is shown for comparison. For large n it is very accurate; for small n it is an overestimate.
  5. 5
    Use the comparison table
    The table lists common factorials (0!, 1!, 5!, 10!, 20!, 50!) so you can recognize the growth pattern.

Formula

Factorial definition:

n! = n × (n−1) × (n−2) × … × 1 (for n ≥ 1)
0! = 1 (by convention — empty product)
Example: 5! = 5×4×3×2×1 = 120

Binomial coefficient (n choose k):

C(n, k) = n! / (k! × (n−k)!)
Example: C(5, 2) = 5! / (2! × 3!) = 120 / (2 × 6) = 10

Stirling's approximation:

n! ≈ √(2πn) × (n/e)ⁿ
log10(n!) ≈ n·log10(n) − n·log10(e) + 0.5·log10(2πn)

Number of digits:

digits = ⌊log10(n!)⌋ + 1 = ⌊Σ log10(k) for k=1..n⌋ + 1

Worked Example

Example 1 — Compute 5!:

  • 5! = 5 × 4 × 3 × 2 × 1 = 120.
  • Number of digits: 3.
  • Stirling: √(2π·5) × (5/e)⁵ ≈ 2.5066 × 7.3345 × 21.027 ≈ 118.02 (close to 120).

Example 2 — Compute 10!:

  • 10! = 10 × 9 × … × 1 = 3,628,800.
  • Number of digits: 7.
  • Stirling: √(20π) × (10/e)¹⁰ ≈ 7.927 × 1632.7 ≈ 3.599×10⁶ (within 1%).

Example 3 — Compute 50!:

  • 50! ≈ 3.04 × 10⁶⁴ (a 65-digit number).
  • Stirling: very accurate at this size — within 0.2%.
  • This is the number of distinct orderings of a 50-card deck — vastly more than the number of atoms in the observable universe (~10⁸⁰).

Tips

  • 0! = 1 by convention (the empty product). This makes the binomial coefficient and many combinatorial formulas work correctly at the boundary.
  • Factorial grows super-exponentially — faster than any exponential a^n. 10! is 7 digits, 20! is 19 digits, 50! is 65 digits, 100! is 158 digits. Each new multiple adds log(n) digits.
  • For n > 170, IEEE 754 overflows to Infinity. Use BigInt in JavaScript or compute log10(n!) directly: log10(n!) = Σ log10(k) for k = 1 to n. This gives the digit count without computing the value.
  • Stirling's approximation: n! ≈ √(2πn) × (n/e)^n. The relative error goes to 0 as n → ∞. Useful for estimation and asymptotic analysis in statistics.
  • The binomial coefficient "n choose k" = n! / (k!(n-k)!) gives the number of ways to choose k items from n. For large n and small k, this is approximately n^k / k!.

Common Mistakes

Warning

The most common mistake is forgetting that 0! = 1, not 0. The empty-product convention is essential for the binomial coefficient to work at k=0 and k=n. A second error is expecting factorial to be computable for large n in regular numbers — IEEE 754 overflows at n = 171. A third error is confusing n! with the gamma function Γ(n) = (n−1)!, which is the analytic extension to non-integers.

Frequently Asked Questions

What is 0 factorial (0!)?
By convention, 0! = 1. This is the empty-product convention — there are no factors to multiply, and the empty product equals 1 (the multiplicative identity). This definition makes the binomial coefficient and many combinatorial formulas work correctly at the boundary.
Why does 171! overflow IEEE 754?
JavaScript numbers are 64-bit IEEE 754 doubles, with a maximum value of about 1.8×10³⁰⁸. Since 171! ≈ 1.24×10³⁰⁹, it overflows to Infinity. For n > 170, you need BigInt (arbitrary precision) or Stirling's approximation in logarithmic form: log10(n!) = Σ log10(k) for k=1..n.
What is Stirling's approximation?
Stirling's approximation is n! ≈ √(2πn) × (n/e)ⁿ. It is asymptotically accurate — the relative error goes to 0 as n → ∞. For practical use, log10(n!) ≈ n·log10(n) − n·log10(e) + 0.5·log10(2πn) gives a good estimate of the number of digits in n!.
How fast does factorial grow?
Factorial grows faster than any exponential aⁿ (for fixed a) and faster than any polynomial n^k. It is roughly (n/e)ⁿ, so each new multiple adds log(n) digits to the result. 10! = 3,628,800 (7 digits), 20! ≈ 2.43×10¹⁸ (19 digits), 50! ≈ 3.04×10⁶⁴ (65 digits), 100! ≈ 9.33×10¹⁵⁷ (158 digits).
How is factorial used in probability and statistics?
Factorials count permutations (n! arrangements of n distinct items) and combinations (n choose k = n! / (k!(n-k)!)). The binomial distribution, the Poisson distribution, the Taylor series for e^x, and many Taylor/Maclaurin series all involve factorials in their coefficients.
How does this calculator compute factorial for large n?
For n ≤ 170, it uses an iterative loop with regular JavaScript numbers. The result is exact up to IEEE 754 precision limits (about 15-17 significant digits). For n > 170, the result overflows to Infinity — the calculator shows the Stirling approximation and digit count instead, which remain finite.

Factorial definition

The factorial of a non-negative integer n, written n!, is the product of all positive integers from 1 to n: n! = n × (n−1) × (n−2) × … × 1. By convention 0! = 1 (the empty product). So 5! = 5×4×3×2×1 = 120, 10! = 3,628,800, and 20! ≈ 2.43×10¹⁸. Factorial grows super-exponentially.

Permutations and combinations

Factorials count arrangements. The number of permutations (orderings) of n distinct items is n!. The number of combinations (subsets) of k items from n is "n choose k" = n! / (k!(n−k)!). The binomial coefficient is the heart of the binomial distribution, the binomial theorem, and Pascal's triangle.

Stirling's approximation

Stirling's formula approximates large factorials: n! ≈ √(2πn) × (n/e)ⁿ. The relative error goes to 0 as n → ∞. For practical use, the logarithmic form log(n!) ≈ n·log(n) − n + 0.5·log(2πn) gives a good estimate of the number of digits and is the basis for many statistical approximations (Laplace, large deviations).

Factorial growth rate

Factorial grows faster than any exponential aⁿ (for fixed a) and faster than any polynomial n^k. It is roughly (n/e)ⁿ, so each new multiple adds log(n) digits. 10! = 7 digits, 20! = 19 digits, 50! = 65 digits, 100! = 158 digits, 1000! = 2568 digits. This super-exponential growth makes factorial computation a classic benchmark in computer science.

Common factorial values. Note the super-exponential growth: 50! is already a 65-digit number.
n!Factorial valueDigits
0!11
1!11
5!1203
10!3,628,8007
20!2.4329e+1819
50!3.0414e+6465
Info

Factorials count permutations — the number of distinct orderings of n distinct items. A standard 52-card deck has 52! ≈ 8×10⁶⁷ distinct orderings, which is more than the number of atoms in the observable universe. Every shuffle of a well-mixed deck is almost certainly a permutation that has never existed before.

Pro tip

For large n (n > 170), compute log10(n!) = Σ log10(k) for k=1..n directly. This gives the number of digits without computing the (overflowing) value. Stirling's logarithmic form log10(n!) ≈ n·log10(n) − n·log10(e) + 0.5·log10(2πn) is faster and accurate to within 0.1% for n ≥ 10.

Authoritative References

  • Wikipedia — Factorial— wikipedia.org
    Comprehensive treatment of factorial, including history, the empty-product convention 0! = 1, the gamma function extension to complex numbers, and Stirling's approximation.
  • Khan Academy — Counting, permutations, and combinations— khanacademy.org
    Khan Academy's full course on combinatorics including factorials, permutations, and the binomial coefficient.
  • Wolfram MathWorld — Factorial— wolfram.com
    Eric Weisstein's reference covering the analytic properties of factorial, the gamma function Γ(n) = (n−1)!, and asymptotic expansions including Stirling's series.

Try our other free calculators

CalcGenius has 1,200+ free, ad-free, browser-based calculators for finance, health, math, science, and everyday life. No sign-up required.

Factorial Calculator — Permutations & n! Step-by-Step