Factorial Calculator

Calculate n! for any positive integer with full expansion shown. Supports double factorial, subfactorial, and Stirling's approximation.

Calculate n! for any non-negative integer with exact BigInt results up to 1000! (numbers with thousands of digits). The calculator also supports double factorial (n!!), subfactorial (!n) for counting derangements, and Stirling's approximation for estimating huge factorials. The full multiplication expansion is shown for smaller values so you can see the working, not just the answer.

Ad
Ad

About Factorial Calculator

What Is a Factorial?

A factorial counts the number of ways to arrange n distinct objects in order. Written n!, it is the product of every positive integer from 1 up to n: n! = n × (n-1) × (n-2) × ... × 2 × 1. By convention 0! = 1, which keeps formulas like the binomial coefficient and permutation count consistent at the boundary.

Worked example: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720. There are exactly 720 different orders in which six books can be arranged on a shelf. Each additional book multiplies the total by a larger number, which is why factorials grow so fast: 7! jumps to 5,040, and 10! is already 3.6 million.

The notation n! was introduced by the French mathematician Christian Kramp in 1808. Before then, mathematicians wrote it out longhand or used a symbol like a sideways capital pi. Euler had been working with the idea since the 1720s, which is why the gamma function Γ(n) = (n-1)! that extends factorials to non-integers bears his name.

Factorial Values Reference

Factorials outpace every exponential function. By n = 100 the value has 158 digits, whereas 2^100 has only 31 digits. The table below, cross-referenced with the OEIS sequence A000142, shows how quickly the numbers scale.

nn!Digits
011
111
221
361
4242
51203
67203
75,0404
840,3205
9362,8806
103,628,8007
12479,001,6009
151,307,674,368,00013
202,432,902,008,176,640,00019
25~1.551 × 10^2526
50~3.041 × 10^6465
100~9.333 × 10^157158
1000~4.024 × 10^25672,568

For scale, 52! - the number of possible shuffles of a standard deck of cards - is roughly 8.07 × 10^67. That exceeds the estimated number of atoms on Earth (about 10^50) by seventeen orders of magnitude, which is why statisticians say every well-shuffled deck has almost certainly never existed before in the history of card games.

Why Does 0! Equal 1?

0! equals 1 because it represents the single way to arrange nothing. Four complementary arguments all point to the same answer:

  • Combinatorial: There is exactly one arrangement of zero items - the empty arrangement. So 0! = 1.
  • Recursive: The rule n! = n × (n-1)! must hold at n = 1. That gives 1! = 1 × 0!, so 0! must equal 1.
  • Binomial coefficient: nC0 = n! / (0! × n!) must equal 1 for every n, which forces 0! = 1.
  • Empty product: In mathematics a product of no factors equals the multiplicative identity, which is 1.

Students often assume 0! should be 0, reasoning that zero multiplied by anything is zero. The mistake is treating 0! as a product that includes zero as a factor, but the definition only multiplies positive integers from 1 to n. When n = 0 there are no positive integers to multiply, so the result is the empty product.

How Does Double Factorial Work?

A double factorial n!! multiplies every other integer down from n, stopping at either 1 (for odd n) or 2 (for even n). It is not the same as (n!)!. Writing 4!! means 4 × 2 = 8, while (4!)! means 24!, which is about 6.2 × 10^23.

  • Odd n: n!! = n × (n-2) × (n-4) × ... × 3 × 1
  • Even n: n!! = n × (n-2) × (n-4) × ... × 4 × 2
nn!! (odd)nn!! (even)
1122
3348
515648
71058384
9945103,840
1110,3951246,080

Double factorials show up in the volume formula for n-dimensional spheres, in the Wallis product for pi, and in the series expansions of trigonometric and Bessel functions. In quantum mechanics they appear in the normalisation constants of spherical harmonics. For a quick physics reference, the volume of a 2k-dimensional unit ball is π^k / k!, and the odd-dimensional version uses the double factorial (2k+1)!!.

What Is a Subfactorial (Derangement)?

The subfactorial !n counts derangements, which are permutations where no element sits in its original position. For the set {1, 2, 3}, only {2, 3, 1} and {3, 1, 2} qualify, so !3 = 2. The closed-form formula is !n = n! × (1 - 1/1! + 1/2! - 1/3! + ... + (-1)^n/n!), and there is also a tidy recurrence: !n = (n-1) × (!(n-1) + !(n-2)).

nn!!n!n/n!
1100%
22150%
36233.3%
424937.5%
51204436.7%
103,628,8001,334,96136.8%

The ratio !n/n! converges extraordinarily fast to 1/e ≈ 0.36788. This is known as the "hat-check problem": if n people leave their hats at a cloakroom and the attendant returns them at random, the probability that nobody gets their own hat back approaches 36.8% regardless of whether there are ten guests or ten thousand. For combinatorics problems that need both arrangement and selection counts, the permutations and combinations calculator handles nPr and nCr in one step.

How Accurate Is Stirling's Approximation?

Stirling's approximation estimates n! as n! ≈ √(2πn) × (n/e)^n, and the relative error falls below 1% by n = 9 and below 0.1% by n = 100. It is invaluable in statistical mechanics and information theory, where the quantities of interest (entropy, log-likelihoods) depend on log(n!) for astronomical n.

nExact n!Stirling'sError
5120118.021.65%
103,628,8003,598,6950.83%
202.432 × 10^182.423 × 10^180.42%
503.041 × 10^643.036 × 10^640.17%
1009.333 × 10^1579.325 × 10^1570.08%

James Stirling published the formula in 1730 in his book Methodus Differentialis. Abraham de Moivre had also discovered a closely related version independently. For tighter accuracy, the Stirling series adds correction terms: n! ≈ √(2πn) × (n/e)^n × (1 + 1/(12n) + 1/(288n²) - ...). Just the first correction drops the error at n = 10 to under 0.008%.

Where Do Factorials Appear?

ApplicationFormulaWhy Factorials
PermutationsnPr = n!/(n-r)!Counting ordered arrangements
CombinationsnCr = n!/(r!(n-r)!)Counting unordered selections
Taylor seriese^x = Σ x^n/n!Denominators control convergence
ProbabilityPoisson, binomial distributionsCounting possible outcomes
Gamma functionΓ(n) = (n-1)!Extends factorials to non-integers
Wallis productπ/2 = Π (2n)²/((2n-1)(2n+1))Uses double factorials in closed form

Factorials and the Gamma Function

The gamma function extends factorials to non-integer values through the definition Γ(n) = (n-1)! for positive integers, and Γ(z) = ∫₀^∞ t^(z-1) e^(-t) dt for any complex z with positive real part. This lets you evaluate "1.5 factorial" or even "i factorial" - Γ(2.5) = 1.329, so 1.5! = Γ(2.5) ≈ 1.329.

Γ has poles at 0 and every negative integer, which is another reason factorials are not defined on negative integers: the natural continuation is undefined there. The function also satisfies Γ(1/2) = √π, a surprising identity that connects factorials to the Gaussian integral and ultimately to the normal distribution.

In programming languages, the gamma function is available as tgamma in C/C++, scipy.special.gamma in Python, Math.gamma in Julia, and as the logarithm lgamma everywhere (since Γ itself overflows quickly). JavaScript has no built-in gamma, which is why exact integer factorials up to 1000! use BigInt here while Stirling's approximation covers the rest.

Common Mistakes to Avoid

  • Assuming n! is defined for negatives. n! is only defined for non-negative integers. For negative integers the gamma function blows up to infinity. For fractional n, use Γ(n+1) instead.
  • Reading (n!)! as n!!. Double factorial only skips every other term. (3!)! = 6! = 720, whereas 3!! = 3.
  • Using floating-point factorials above 170. JavaScript's Number type tops out near 1.8 × 10^308, which 170! slightly exceeds. Anything higher needs BigInt (which this calculator uses). Python, Java BigInteger and Julia handle this natively.
  • Forgetting 0! = 1 in loops. A common off-by-one bug in Taylor series implementations is starting the loop at n = 1 instead of n = 0, which drops the constant term.

For very large exponents without a factorial step, the exponent calculator handles any base to any power. If you need to break a large factorial into its prime constituents, the prime factorisation tool is the partner you want - factorials have strikingly regular prime signatures given by Legendre's formula, which counts how many times a prime p divides n!.

All calculations run in your browser using BigInt for exact results. Nothing is sent to any server.

Sources

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.

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>