Factorial Calculator (n!)
n! = 1 × 2 × … × n. Computes exactly up to 21! (number limit); approximate via Stirling for larger.
Result
General calculation reads
Amazon affiliateAs 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
- 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.
Frequently asked
Why does it overflow at 21!?+
Is 0! defined?+
Stirling accuracy?+
What is n! used for?+
Beyond integers?+
Related calculators
More tools you might like
Hand-picked tools that pair well with this one — same audience, same intent.
lcm(a,b) = |a × b| / gcd(a,b). Smallest number that both a and b divide evenly.
Euclidean algorithm: gcd(a,b) = gcd(b, a mod b). Supports 2-6 integers.
Is n prime? Trial division up to √n; identifies smallest divisor and nearest primes if composite.
n = p₁^a₁ × p₂^a₂ × … Trial division to find all prime factors with multiplicity.
Convert decimal ↔ scientific notation. Standard form a × 10^b with 1 ≤ |a| < 10.
Insert page numbers in the footer or header — choose position, format, and starting number.