Factorial Calculator
Compute n! exactly, plus double and multi-factorials, subfactorials and fractional factorials through the Gamma function — with trailing zeros, prime factorisation, digit count, and how close Stirling’s approximation gets.
Written by Suhaib Hassan. The identities are standard number theory and analysis, and each worked example is re-derived by hand. Our methodology.
It multiplies with arbitrary-size integers, so there is no overflow at 170!. Prime exponents come from Legendre’s formula, and the Gamma function from a Lanczos approximation.
Factorials grow astonishingly fast. This page shows the exact value, its size, and why approximations work.
—
How fast factorials grow
log₁₀ of n! (blue) against Stirling’s approximation (orange) and eⁿ (grey, dashed). Factorials overtake any exponential.
Step-by-step working
—
Factorial family reference
Related functions, with values for n = 10.
| Function | Notation | Definition | Value for n = 10 | Used for |
|---|---|---|---|---|
| Factorial | n! | n·(n−1)·…·2·1, 0! = 1 | 3,628,800 | Permutations, series |
| Double factorial | n!! | n·(n−2)·(n−4)·… | 3,840 | Integrals, spherical volumes |
| Subfactorial | !n | n!·Σ(−1)ᵏ/k! | 1,334,961 | Derangements (no fixed points) |
| Gamma function | Γ(z) | ∫₀^∞ t^(z−1) e^(−t) dt | Γ(11) = 3,628,800 | Fractional factorials, statistics |
| Falling factorial | (n)ₖ | n!/(n−k)! | (10)₃ = 720 | Ordered selections |
Worked examples
Shuffling a deck
How many orderings of a 52-card deck?
68 digits — far more than the number of seconds since the Big Bang, so a well-shuffled deck is almost surely in an order never seen before.
Trailing zeros of 100!
How many zeros end 100! ?
(there are always more factors of 2 than of 5)
Fractional factorial
What is (½)! ?
= 0.886227
What is a factorial?
The factorial n! is the product of all whole numbers from 1 to n, with 0! = 1 by convention (there is exactly one way to arrange nothing). It counts the ways to order n distinct objects and grows faster than any exponential: 10! = 3,628,800 and 20! ≈ 2.43 × 10¹⁸.
Useful facts
- Trailing zeros (Legendre): the number of factors of a prime p in n! is Σ ⌊n/pᵏ⌋. Zeros equal the number of factors of 5.
- Stirling’s approximation: n! ≈ √(2πn)(n/e)ⁿ, with relative error about 1/(12n).
- Ramanujan’s refinement: n! ≈ √π (n/e)ⁿ (8n³ + 4n² + n + 1/30)^(1/6), far more accurate.
- Gamma function: Γ(n + 1) = n!, extending factorials to real and complex numbers.
By Suhaib Hassan · Reviewed 28 September 2026 · How CalculatePilot verifies formulas →
Sources
- NIST Digital Library of Mathematical Functions, chapter 5 (Gamma function), including 5.11 on asymptotic expansions.
- Stirling, J. (1730). Methodus Differentialis. London.
- Legendre, A.-M. (1808). Essai sur la théorie des nombres, 2nd ed. Paris — the prime-exponent formula.
- Euler, L. (1729). Letter to Goldbach on the interpolation of factorials — origin of the Gamma function.
Frequently asked questions
Why is 0! equal to 1?
Because there is exactly one way to arrange zero objects (do nothing), and because it keeps the recurrence n! = n · (n − 1)! true at n = 1 (1 = 1 · 0!). It also makes formulas such as C(n, 0) = n! ÷ (0! n!) = 1 work.
How does Legendre’s formula count trailing zeros without multiplying everything?
Each trailing zero needs one factor 10 = 2 × 5. Factors of 2 are more plentiful than 5s, so zeros equal the number of 5s in n!. Multiples of 5 contribute one each, multiples of 25 one more, multiples of 125 one more, and so on: Σ ⌊n/5ᵏ⌋.
What is the difference between Stirling’s formula and Ramanujan’s correction?
Stirling’s leading term underestimates n! by roughly 1/(12n) in relative terms (0.83% at n = 10). Ramanujan’s version adds a cubic term under a sixth root, shrinking the relative error to about 9 × 10⁻⁸ at n = 10 (under 0.00001%).
How does this calculator avoid overflow?
Ordinary 64-bit floating point overflows at 171! (about 10³⁰⁸). This page uses arbitrary-size integers for exact results up to 3,000!, and logarithms for the Stirling comparisons, so nothing overflows.
Is the double factorial (n!!) the factorial of a factorial?
No. n!! multiplies every second number down from n (10!! = 10 · 8 · 6 · 4 · 2 = 3,840). The factorial of a factorial would be (n!)!, which is astronomically larger.
Can I take the factorial of a negative number or a fraction?
Not with the whole-number definition. The Gamma function extends it to all real numbers except the negative integers, where it has poles: (−1)!, (−2)!, … are undefined. Use the Gamma tab for fractional values.
Related calculators
Continue with counting.