Factorial Calculator (n!)
n! = 1 × 2 × … × n. Computes exactly up to 21! (number limit); approximate via Stirling for larger.
Result
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
- Inputs:
- n = 5
- Output:
- 5! = 5·4·3·2·1 = 120
- Inputs:
- n = 52 (deck shuffles)
- Output:
- 52! ≈ 8.066 × 10⁶⁷
- 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.