Math πŸ‡ΊπŸ‡Έ USA πŸ‡¬πŸ‡§ UK Live Results BigInt Precision
Calculate

Factorial Calculator

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.

Factorial Inputs

Live
Enter any non-negative integer. Exact results use JavaScript BigInt (unlimited precision). For n > 170, only Stirling's approximation and log₁₀(n!) are shown (64-bit float limit). Steps shown for n ≀ 20.
0 to 170 for exact result; up to 1000 for Stirling approximation

Your Factorial Results

β€”
n! Result
β€”
Enter a value above to calculate
Factorial Growth (n = 1 to 12)
log₁₀(n!) Growth

Factorial Calculator Guide

Guide

Factorial Calculator – n! with Steps, Large Numbers & Stirling's Approximation

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.

What Is a Factorial?

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:

  • 5! = 5 Γ— 4 Γ— 3 Γ— 2 Γ— 1 = 120
  • 10! = 10 Γ— 9 Γ— 8 Γ— 7 Γ— 6 Γ— 5 Γ— 4 Γ— 3 Γ— 2 Γ— 1 = 3,628,800
  • 20! = 2,432,902,008,176,640,000

The factorial function is defined for all non-negative integers. By convention β€” and by a deeper mathematical argument involving empty products β€” 0! = 1.

Why Does 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 Rate β€” Why Factorials Get So Large So Fast

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:

nn!Number of Digits
111
51203
103,628,8007
202,432,902,008,176,640,00019
50~3.04 Γ— 10^6465
100~9.33 Γ— 10^157158
170~7.26 Γ— 10^306307
171Overflow (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.

Computational Limits β€” IEEE 754 and BigInt

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.

Stirling's Approximation

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 Gamma Function β€” Extending Factorials to Non-Integers

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.

Factorials in Combinations and Permutations

The most common application of factorials in school mathematics is counting arrangements and selections.

Permutations β€” Ordered Arrangements

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.

Combinations β€” Unordered Selections

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 in Probability

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 in Calculus β€” Taylor and Maclaurin Series

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 in Computer Science

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.

How to Calculate Factorials Manually

To compute n! by hand, simply multiply the integers from 1 to n in sequence. For n = 7:

  • Step 1: 1 Γ— 2 = 2
  • Step 2: 2 Γ— 3 = 6
  • Step 3: 6 Γ— 4 = 24
  • Step 4: 24 Γ— 5 = 120
  • Step 5: 120 Γ— 6 = 720
  • Step 6: 720 Γ— 7 = 5,040

Therefore 7! = 5,040. Our calculator shows these steps for any n ≀ 20 when the "Show Steps" option is enabled.

UK and US School Context

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.

FAQ – Factorial Calculator

What is a factorial in mathematics?

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.

What is 0! and why does it equal 1?

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.

What is the largest factorial a standard calculator can compute exactly?

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.

What is Stirling's approximation?

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.

How are factorials used in combinations?

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.

Can you compute factorial for non-integers?

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.

Why do factorials appear in Taylor series?

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!.

What are factorials used for in everyday applications?

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.

⚠️ Disclaimer

Important

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.

n!
β€”