Factorial Calculator (n!)

n! = 1 × 2 × … × n. Computes exactly up to 21! (number limit); approximate via Stirling for larger.

Inputs

Result

Loading calculator…

General calculation reads

Amazon affiliate

As an Amazon Associate we may earn from qualifying purchases. This does not add cost for you.

How to use this calculator

  • Enter n (0 to 200 or so).
  • Read exact value or Stirling approximation.

About this calculator

n! ("n factorial") is the product of all positive integers up to n. 5! = 120; 10! = 3,628,800; 21! = 51,090,942,171,709,440,000 (last one fitting in JS Number). For larger n, this calculator uses Stirling's approximation: ln(n!) ≈ n ln n − n + ½ ln(2πn), accurate to <1% for n > 5. Factorials grow superexponentially: 100! has 158 digits, 1000! has 2568. Used in combinatorics (permutations), Taylor series, probability.

How it works — the formula

n! = n · (n − 1) · (n − 2) · … · 1 0! = 1 (empty product) Stirling: n! ≈ √(2πn) · (n / e)ⁿ

The factorial of a non-negative integer n is the product of all positive integers up to n. By convention 0! = 1 (the empty product). Factorials grow super-exponentially — n! beats every fixed exponential aⁿ for sufficiently large n. Stirling's approximation gives a tight asymptotic estimate that is accurate to within 1% by n = 10 and 0.01% by n = 100. Beyond integer arguments, the gamma function Γ(n) = (n − 1)! generalizes the factorial to real and complex numbers.

Worked examples

Example 1
Small factorial
Inputs:
n = 5
Output:
5! = 5·4·3·2·1 = 120
Example 2
Combinatorics: card permutations
Inputs:
n = 52 (deck shuffles)
Output:
52! ≈ 8.066 × 10⁶⁷
Example 3
Stirling vs exact
Inputs:
n = 10
Output:
10! = 3,628,800; Stirling ≈ 3,598,696 (error ≈ 0.83%)

Limitations

  • Factorial is only defined here for non-negative integers; use the gamma function for non-integer or negative-real inputs.
  • IEEE 754 double precision overflows around 170! ≈ 7.3 × 10³⁰⁶; results above this are returned as Infinity.
  • For exact arbitrary-precision factorials, use a BigInt or symbolic-computation engine.
  • Stirling's approximation diverges as a series — taking too many terms makes accuracy worse.

Computed via the standard recursive product up to ~21!, then via lgamma+exp for larger inputs to avoid intermediate overflow.

Frequently asked

Why does it overflow at 21!?+
JavaScript Number is IEEE 754 double — 53-bit precision. 21! = 5.1 × 10^19, just past 2^53. Larger values lose precision.
Is 0! defined?+
Yes, 0! = 1 by convention (empty product). Important for the formula nCk to work for k=0.
Stirling accuracy?+
For n=10: 0.83% error. For n=100: 0.083%. For n=1000: 0.0083%. Each 10× n improves accuracy ~10×.
What is n! used for?+
Permutations: how many ways to arrange n items = n!. Combinations nCk = n!/(k!(n−k)!). Taylor series. Probability.
Beyond integers?+
Gamma function Γ(n) = (n−1)! generalizes to all real and complex numbers (except non-positive integers).

Related calculators

More tools you might like

Hand-picked tools that pair well with this one — same audience, same intent.