Factorial Calculator
Calculate n! for any positive integer with full expansion shown. Supports double factorial, subfactorial, and Stirling's approximation.
About Factorial Calculator
Calculate n! for any non-negative integer with exact BigInt results up to 1000! (numbers with thousands of digits). Also supports double factorial (n!!), subfactorial (!n), and Stirling's approximation. The full multiplication expansion is shown for smaller values.
What Is a Factorial?
The factorial of n (written n!) is the product of all positive integers from 1 to n:
n! = n × (n-1) × (n-2) × ... × 2 × 1
By convention, 0! = 1. This makes formulas for permutations, combinations, and the binomial theorem work consistently.
Factorial Values Reference
| n | n! | Digits |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 3 | 6 | 1 |
| 4 | 24 | 2 |
| 5 | 120 | 3 |
| 6 | 720 | 3 |
| 7 | 5,040 | 4 |
| 8 | 40,320 | 5 |
| 9 | 362,880 | 6 |
| 10 | 3,628,800 | 7 |
| 12 | 479,001,600 | 9 |
| 15 | 1,307,674,368,000 | 13 |
| 20 | 2,432,902,008,176,640,000 | 19 |
| 25 | ~1.551 × 10^25 | 26 |
| 50 | ~3.041 × 10^64 | 65 |
| 100 | ~9.333 × 10^157 | 158 |
| 1000 | ~4.024 × 10^2567 | 2,568 |
Factorials grow faster than exponential functions. 100! has 158 digits, while 2^100 has only 31 digits.
Why Does 0! Equal 1?
There are several ways to see why 0! must be 1:
- Combinatorial argument: There is exactly one way to arrange zero items - do nothing. So 0! = 1.
- Recursive definition: n! = n × (n-1)!. For this to work at n=1: 1! = 1 × 0!, so 0! = 1.
- Binomial coefficient: nC0 = n!/(0! × n!) = 1. This requires 0! = 1.
- Empty product: A product of no factors is defined as the multiplicative identity, which is 1.
Double Factorial (n!!)
The double factorial multiplies every other integer down from n:
- Odd n: n!! = n × (n-2) × (n-4) × ... × 3 × 1
- Even n: n!! = n × (n-2) × (n-4) × ... × 4 × 2
| n | n!! (odd) | n | n!! (even) |
|---|---|---|---|
| 1 | 1 | 2 | 2 |
| 3 | 3 | 4 | 8 |
| 5 | 15 | 6 | 48 |
| 7 | 105 | 8 | 384 |
| 9 | 945 | 10 | 3,840 |
| 11 | 10,395 | 12 | 46,080 |
Double factorials appear in physics (quantum mechanics, spherical harmonics) and in the formulas for the volume and surface area of n-dimensional spheres.
Subfactorial (!n) - Derangements
The subfactorial !n counts derangements - permutations where no element is in its original position.
Example: For {1, 2, 3}, the derangements are {2, 3, 1} and {3, 1, 2}. So !3 = 2.
!n = n! × (1 - 1/1! + 1/2! - 1/3! + ... + (-1)^n/n!)
| n | n! | !n | !n/n! |
|---|---|---|---|
| 1 | 1 | 0 | 0% |
| 2 | 2 | 1 | 50% |
| 3 | 6 | 2 | 33.3% |
| 4 | 24 | 9 | 37.5% |
| 5 | 120 | 44 | 36.7% |
| 10 | 3,628,800 | 1,334,961 | 36.8% |
The ratio !n/n! converges quickly to 1/e ≈ 0.3679. This means about 36.8% of all random permutations are derangements, regardless of the size of the set.
Stirling's Approximation
For large n, computing n! exactly is impractical. Stirling's formula provides a close approximation:
n! ≈ √(2πn) × (n/e)^n
| n | Exact n! | Stirling's | Error |
|---|---|---|---|
| 5 | 120 | 118.02 | 1.65% |
| 10 | 3,628,800 | 3,598,695 | 0.83% |
| 20 | 2.432 × 10^18 | 2.423 × 10^18 | 0.42% |
| 50 | 3.041 × 10^64 | 3.036 × 10^64 | 0.17% |
| 100 | 9.333 × 10^157 | 9.325 × 10^157 | 0.08% |
The approximation improves as n increases. By n = 100, the error is under 0.1%.
Where Factorials Appear
| Application | Formula | Why Factorials |
|---|---|---|
| Permutations | nPr = n!/(n-r)! | Counting ordered arrangements |
| Combinations | nCr = n!/(r!(n-r)!) | Counting unordered selections |
| Taylor series | e^x = Σ x^n/n! | Denominators control convergence |
| Probability | Poisson, binomial formulas | Counting possible outcomes |
| Gamma function | Γ(n) = (n-1)! | Extends factorials to non-integers |
For applying factorials in counting problems, the permutations and combinations calculator computes nPr and nCr directly. For exponentiation, the exponent calculator handles any base to any power.
All calculations run in your browser using BigInt for exact results. No data is sent to any server.
Frequently Asked Questions
How large can n be?
The calculator supports n up to 1000 for standard factorial using BigInt, which gives exact results with hundreds or thousands of digits. Double factorial and subfactorial support up to 500.
What is a double factorial?
Double factorial (n!!) multiplies every other integer down from n. For example, 7!! = 7 x 5 x 3 x 1 = 105. Even n uses even factors and odd n uses odd factors.
What is a subfactorial?
Subfactorial (!n) counts derangements - the number of permutations where no element appears in its original position. For example, !3 = 2 because for {1,2,3} only {2,3,1} and {3,1,2} have no element in place.
What is Stirling's approximation?
Stirling's formula approximates n! as sqrt(2*pi*n) * (n/e)^n. It becomes very accurate for large n and is useful when the exact factorial is too large to work with practically.
Why does 0! equal 1?
By convention, 0! = 1. This makes many formulas work consistently, including the binomial coefficient and the definition of permutations. It represents the one way to arrange zero items.
Related Tools
Link to this tool
Copy this HTML to link to this tool from your website or blog.
<a href="https://toolboxkit.io/tools/factorial-calculator/" title="Factorial Calculator - Free Online Tool">Try Factorial Calculator on ToolboxKit.io</a>