Factorial Calculator (n!)
Calculate the factorial of any non-negative integer. See results for large values too.
Enter a non-negative integer (0–170). Note: 170! is the largest factorial JavaScript can represent.
Results update as you type.
How it works
The factorial function, denoted n!, multiplies a positive integer n by every positive integer smaller than itself down to 1. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. By mathematical convention, 0! = 1. This might seem counterintuitive, but it follows from the empty product rule (a product of no numbers equals the multiplicative identity, 1) and ensures that formulas for combinations and permutations work correctly for edge cases. Factorials grow astonishingly fast — 10! is already 3,628,800, and 20! exceeds 2.4 quintillion. This explosive growth is directly responsible for how difficult it becomes to win lotteries or brute-force cryptographic keys. The number 52! (possible shuffles of a standard deck of cards) is approximately 8 × 10^67 — a number larger than the number of atoms in the observable universe, meaning every shuffle in history has almost certainly been unique. Factorials appear everywhere in mathematics: in combinatorics (counting arrangements), in Taylor series expansions (sin x = x − x³/3! + x⁵/5! − ...), in the Gamma function (which extends factorials to non-integers), and in statistics. This mix of a one-line definition and explosive growth is what makes the factorial one of the first big ideas students meet in combinatorics and one of the most useful tools for counting arrangements.
n! = n × (n−1) × (n−2) × ... × 2 × 1; 0! = 1
A factorial counts how many ways n distinct items can be arranged in order: the first slot has n choices, the next n−1, and so on down to the last, so the choices multiply together. That is why the definition is a running product from n down to 1. Setting 0! = 1 keeps the empty-product rule consistent and lets combination and permutation formulas stay correct at their edge cases.
Source:Standard mathematical definition
We review all our tools from time to time to ensure accuracy.
Worked example
How to use this calculator
- 1
Enter your values
Enter n.
- 2
Adjust the options
Fine-tune any options to match your situation.
- 3
Read your result
n! updates instantly as you type — no button to press.
Frequently asked questions
Why does 0! equal 1?
Zero factorial equals 1 by definition, and there are several ways to understand why this makes sense. Mathematically, it follows the 'empty product' convention: a product containing no factors equals 1 (just as a sum of no terms equals 0). Practically, it ensures the combination formula C(n, 0) = 1 works correctly — there is exactly one way to choose nothing from a set. It also satisfies the recurrence relation n! = n × (n−1)!: plugging in n=1 gives 1! = 1 × 0!, so 0! must be 1.
What is the largest factorial a calculator can compute?
This depends on the numerical precision of the calculator. Standard double-precision floating-point numbers (used in most computing, including JavaScript) can represent factorials up to 170! (≈7.26 × 10^306) before exceeding the maximum representable value and becoming 'Infinity.' For exact integer results of larger factorials, you need big-integer arithmetic. Python's built-in integers handle arbitrarily large factorials. 171! ≈ 1.24 × 10^309, which exceeds the IEEE 754 double-precision maximum of about 1.80 × 10^308.
How are factorials used in combinations and permutations?
Factorials are the building blocks of counting arrangements. Permutations (ordered arrangements) of r items from n: P(n, r) = n! / (n−r)!. Combinations (unordered selections) of r items from n: C(n, r) = n! / (r! × (n−r)!). For example, arranging 3 books from a shelf of 5 in different orders: P(5,3) = 5!/2! = 60. Choosing any 3 books from 5 regardless of order: C(5,3) = 5!/(3!×2!) = 10. Factorials also appear in probability distributions like the Poisson distribution.
What is the Gamma function and how does it relate to factorial?
The Gamma function Γ(n) is an extension of the factorial function to non-integer and complex numbers. For positive integers, Γ(n) = (n−1)!. So Γ(5) = 4! = 24. The Gamma function is defined through an integral formula that works for all positive real numbers and complex numbers with a positive real part. This allows us to compute 'factorials' of non-integers: for example, Γ(1.5) = 0.5! × 2 ≈ 0.886. The Gamma function appears throughout statistics, physics, and engineering.
Why do factorials grow so incredibly fast?
Factorials grow super-exponentially because each additional factor is larger than the previous one. Exponential growth (like 2^n) multiplies by the same factor each time. Factorial growth multiplies by an ever-increasing factor. By Stirling's approximation, n! ≈ √(2πn) × (n/e)^n, which grows much faster than any exponential function. This rapid growth is why the number of possible arrangements of large sets is astronomically large — 52 playing cards can be shuffled into more unique arrangements than there are atoms in the observable universe.
Related calculators
Combinations Calculator (nCr)
Calculate the number of ways to choose r items from a set of n items, where order doesn't matter.
Probability Calculator
Calculate the probability of an event occurring given favorable and total outcomes.
Exponent Calculator
Calculate base raised to a power (bⁿ). Handles any real exponent including fractions and negatives.