Calculate n! for any non-negative integer with exact BigInt arithmetic, Stirling's approximation, digit count, logββ(n!), and full step-by-step multiplication β works for USA and UK math curricula.
The factorial function is one of the most fundamental operations in mathematics. Written as n! (read "n factorial"), it represents the product of every positive integer from 1 up to n. Despite its simple definition, factorials grow at a breathtaking rate β faster than any exponential function β and appear in combinatorics, probability, calculus, computer science, and physics. This free factorial calculator computes exact results using JavaScript BigInt arithmetic, provides Stirling's approximation for very large n, shows logββ(n!) for scale comparison, and displays full step-by-step multiplication so you can follow every product.
The factorial of a non-negative integer n is defined as the product of all positive integers less than or equal to n:
n! = n Γ (n β 1) Γ (n β 2) Γ β¦ Γ 2 Γ 1
For example:
The factorial function is defined for all non-negative integers. By convention β and by a deeper mathematical argument involving empty products β 0! = 1.
The fact that 0! = 1 surprises many students when they first encounter it, but there are several excellent reasons why this is the only mathematically consistent definition.
The most intuitive argument uses the recursive definition of factorial: n! = n Γ (nβ1)! for all positive integers n. Setting n = 1: 1! = 1 Γ 0!. Since 1! = 1, we get 0! = 1/1 = 1.
Another argument: 0! counts the number of ways to arrange zero objects. There is exactly one way to arrange nothing β do nothing. So 0! = 1 by combinatorial interpretation.
A third argument comes from the gamma function (discussed below): Ξ(1) = 0! = 1, which is confirmed by the integral definition of gamma.
Factorial growth is superexponential β it eventually outpaces any exponential function a^n for any fixed base a. Here are some key values to illustrate the explosive growth:
| n | n! | Number of Digits |
|---|---|---|
| 1 | 1 | 1 |
| 5 | 120 | 3 |
| 10 | 3,628,800 | 7 |
| 20 | 2,432,902,008,176,640,000 | 19 |
| 50 | ~3.04 Γ 10^64 | 65 |
| 100 | ~9.33 Γ 10^157 | 158 |
| 170 | ~7.26 Γ 10^306 | 307 |
| 171 | Overflow (64-bit float) | 309+ |
Notice that 170! is the last value that fits in a standard 64-bit floating-point double (IEEE 754). Attempting to compute 171! with regular JavaScript numbers produces Infinity. This is why our calculator uses BigInt for n β€ 170 β it delivers exact integer results with no loss of precision.
Standard computer arithmetic uses 64-bit floating-point numbers (IEEE 754 doubles), which have a maximum representable value of approximately 1.8 Γ 10^308. Since 170! β 7.26 Γ 10^306, it fits within this range. But 171! β 1.24 Γ 10^309 exceeds the maximum and evaluates to Infinity.
JavaScript's BigInt type removes this constraint entirely. BigInt stores integers as arbitrary-precision sequences of bits β there is no theoretical maximum. The only limit is your computer's available memory. Using BigInt, our calculator can compute 200!, 500!, or even 1000! as exact integers with hundreds of digits.
In practice, for n > 170, displaying the full exact integer (which can have hundreds of digits) is unwieldy. For these large values we show the result in scientific notation using Stirling's approximation, plus the exact digit count from the formula floor(logββ(n!)) + 1.
For large n, computing n! exactly is computationally expensive. Stirling's approximation provides an excellent estimate:
ln(n!) β nΒ·ln(n) β n + Β½Β·ln(2Οn)
Or equivalently in terms of log base 10:
logββ(n!) β nΒ·logββ(n) β nΒ·logββ(e) + Β½Β·logββ(2Οn)
Stirling's approximation is remarkably accurate even for small n. For n = 10, the exact value is 3,628,800 while Stirling gives approximately 3,598,696 β an error of less than 0.84%. For n = 100 the relative error is under 0.083%, and for n = 1000 it is under 0.0083%. The approximation gets more accurate as n increases.
The formula is named after Scottish mathematician James Stirling who published it in 1730, though Abraham de Moivre made related discoveries around the same time.
The factorial function is defined only for non-negative integers, but mathematicians have extended it to all real (and complex) numbers except negative integers using the gamma function Ξ(z).
The key relationship is: Ξ(n) = (nβ1)! for any positive integer n.
The gamma function is defined by the integral: Ξ(z) = β«β^β t^(zβ1) Β· e^(βt) dt
This allows us to compute factorial-like values for fractions. For example: Ξ(1/2) = βΟ, which means (β1/2)! = βΟ. Similarly, Ξ(3/2) = βΟ/2, which can be interpreted as (1/2)! = βΟ/2 β 0.886.
The gamma function appears throughout advanced mathematics, physics, and statistics β in the beta distribution, the chi-squared distribution, Bessel functions, and the Riemann zeta function.
The most common application of factorials in school mathematics is counting arrangements and selections.
The number of ways to arrange r objects chosen from n distinct objects (where order matters) is:
P(n, r) = n! / (nβr)!
Example: How many ways can 3 students be chosen from a class of 10 to win 1st, 2nd, and 3rd prize?
P(10, 3) = 10! / 7! = 10 Γ 9 Γ 8 = 720 ways.
The number of ways to choose r objects from n without regard to order is:
C(n, r) = n! / (r! Γ (nβr)!)
This is also written as "n choose r" or C(n,r) or βΏCα΅£ (UK notation) or (n choose r) using binomial coefficient notation.
Example: How many ways can a 5-card hand be dealt from a standard 52-card deck?
C(52, 5) = 52! / (5! Γ 47!) = 2,598,960 possible hands.
In the UK, combinations and permutations are taught in A-Level Mathematics (Year 12β13) under the Statistics and Pure units. In the US, these topics appear in Algebra 2, Precalculus, and AP Statistics.
Factorials underpin the binomial distribution, which models the number of successes in a fixed number of independent trials:
P(X = k) = C(n,k) Γ p^k Γ (1βp)^(nβk)
Where C(n,k) = n! / (k! Γ (nβk)!). The binomial distribution is central to statistics courses in both the UK (A-Level Statistics) and the US (AP Statistics).
Factorials also appear in the Poisson distribution's formula, in multinomial coefficients for multi-category problems, and in the calculation of hypergeometric probabilities.
Factorials appear naturally in Taylor series and Maclaurin series expansions of functions. The Taylor series for e^x is:
e^x = 1 + x + xΒ²/2! + xΒ³/3! + xβ΄/4! + β¦ = Ξ£ xβΏ/n!
Similarly for sin(x), cos(x), and ln(1+x). The n! in the denominator of each term is essential β it ensures the series converges and that the nth derivative of the series at x=0 equals the nth derivative of the original function.
This is covered in A-Level Further Mathematics in the UK and in AP Calculus BC and university Calculus II in the United States.
Factorials are the classic example for teaching recursion in programming. The recursive definition n! = n Γ (nβ1)! translates directly into code in any language. The iterative version using a loop is equally straightforward.
However, recursive factorial implementations are vulnerable to stack overflow for large n in languages that don't optimise tail calls. Iterative implementations are preferred in production code.
Factorials also appear in the analysis of sorting algorithms (n! is the number of possible orderings of n elements), in cryptography (key space calculations), and in Big O notation analysis.
To compute n! by hand, simply multiply the integers from 1 to n in sequence. For n = 7:
Therefore 7! = 5,040. Our calculator shows these steps for any n β€ 20 when the "Show Steps" option is enabled.
In the United Kingdom, factorial notation appears first in A-Level Mathematics, specifically in the Binomial Theorem section where students learn to expand (1+x)^n using Pascal's triangle and combinatorial coefficients. Further Mathematics A-Level extends this to series and the gamma function.
In the United States, factorial notation appears in Algebra 2 and Precalculus (combinations and permutations), in AP Statistics (binomial distribution), and in AP Calculus BC (Taylor series). College-level Combinatorics courses go much deeper into factorial identities and asymptotic analysis.
GCSE students in England may encounter simple arrangements and selections using factorial concepts without the formal notation, while Scottish Higher Mathematics introduces factorials in the context of probability calculations.
A factorial (written n!) is the product of all positive integers from 1 up to n. For example, 5! = 5 Γ 4 Γ 3 Γ 2 Γ 1 = 120. The factorial function appears in combinatorics, probability, Taylor series, and many other branches of mathematics.
0! = 1 by mathematical convention. The most intuitive reason: using the recursive definition n! = n Γ (nβ1)!, setting n=1 gives 1! = 1 Γ 0!, so 0! = 1. Combinatorially, there is exactly one way to arrange zero objects, so 0! = 1 makes sense.
Standard 64-bit floating-point arithmetic (IEEE 754) overflows at 171!, producing Infinity. The largest exact factorial in this format is 170! β 7.26 Γ 10^306. Our calculator uses JavaScript BigInt for n β€ 170 to give exact results, and Stirling's approximation for larger values.
Stirling's approximation is a formula for estimating large factorials: ln(n!) β nΒ·ln(n) β n + Β½Β·ln(2Οn). It is highly accurate even for moderately small n β within 1% for n β₯ 10, and the relative error decreases as n grows. It was published by James Stirling in 1730.
The number of ways to choose r items from n without regard to order is C(n,r) = n! / (r! Γ (nβr)!). For example, the number of 5-card poker hands from 52 cards is 52! / (5! Γ 47!) = 2,598,960.
Not with the standard factorial definition, but the gamma function extends factorials to all real and complex numbers. The relationship is Ξ(n) = (nβ1)! for positive integers. For example, (1/2)! = Ξ(3/2) = βΟ/2 β 0.886.
The nth term of a Taylor series for f(x) around x=0 is fβ½βΏβΎ(0) Γ xβΏ / n!. The n! in the denominator cancels with the nth derivative of xβΏ, ensuring each term of the series matches the corresponding derivative of the original function. For e^x, this gives e^x = Ξ£ xβΏ/n!.
Factorials are used in lottery odds calculations, card game hand counts (poker, bridge), scheduling problems (how many ways to order a list of tasks), password security analysis, cryptographic key space estimation, and statistical distributions like the binomial and Poisson distributions.
Results are provided for educational purposes only. Exact BigInt results are mathematically precise. Stirling's approximation for large n is an estimate. Always verify critical calculations independently.