Factorial Calculator
Calculate the factorial of any integer with step-by-step multiplication.
Factorial (n!)
Permutations (nPr) & Combinations (nCr)
What is a factorial?
A factorial, written as n!, is the product of every positive integer from 1 up to n. It is one of the fundamental building blocks of combinatorics and probability, because it counts the number of ways to arrange a set of distinct items. For example, five books can be arranged on a shelf in 5! = 120 different orders.
Factorials grow extremely quickly. 10! is already 3,628,800 and 20! passes two quintillion, which is why they are usually written in scientific notation or computed with arbitrary-precision arithmetic. A standard 64-bit integer overflows after 20!, so this calculator uses JavaScript's BigInt type to keep every digit exact.
Beyond plain factorials, this page also computes permutations (nPr) and combinations (nCr). Permutations count ordered arrangements, while combinations count unordered selections. The two appear constantly in statistics, lottery odds, card-game probabilities, and password-strength estimates.
Key Properties of Factorials
- Recurrence — every factorial is built from the one before it: n! = n × (n − 1)!. This is what makes iterative computation so cheap.
- Super-exponential growth — n! eventually outgrows any fixed exponential an, which is why factorials blow up faster than almost any function you will meet in everyday maths.
- Divisibility — n! is divisible by every integer from 1 to n by construction, a fact that underpins many number-theory proofs.
- Combinatorial meaning — n! counts the number of distinct orderings (permutations) of n distinct objects.
- Extension beyond integers — through the Gamma function, n! = Γ(n + 1), so factorials can be generalised to non-integer values.
- Exactness — because the values are whole numbers, they can be computed exactly with big-integer arithmetic rather than approximated in floating point.
How to Use
- Calculate factorial — Enter a non-negative integer (max 5000) and click Calculate.
- View steps — See the step-by-step multiplication for smaller numbers.
- Permutations & Combinations — Enter n and r values to calculate nPr and nCr instantly.
Common Factorial Values
| n | n! | Digits |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 1 |
| 4 | 24 | 2 |
| 5 | 120 | 3 |
| 6 | 720 | 3 |
| 10 | 3628800 | 7 |
| 20 | 2432902008176640000 | 19 |
Worked Examples
- 5! — 5 × 4 × 3 × 2 × 1 = 120.
- 0! — by definition the empty product, which equals 1.
- 10P3 — 10 × 9 × 8 = 720 ordered arrangements.
- 10C3 — 720 / 3! = 120 unordered selections.
- 52C5 — 2,598,960, the number of distinct five-card poker hands.
Tips and Common Mistakes
- 0! equals 1 — this is a definition, not an error; it keeps combination formulas consistent.
- r must not exceed n — nPr and nCr are undefined when r > n.
- Step-by-step output is capped — the running multiplication is shown only for n ≤ 100 to keep the display readable.
- Input is limited to 5000 — 5000! has more than 16,000 digits and would be impractical to render in full.
- Permutations vs combinations — an ordered arrangement is nPr; an unordered selection is nCr. Mixing them up is the most common mistake.
- Precision matters — ordinary floating-point numbers lose accuracy for large factorials, so this tool uses exact big integers.
Common Use Cases
Factorials sit underneath a surprising number of everyday calculations. Whenever you need to count the ways something can be arranged or chosen, a factorial is usually not far away.
- Counting arrangements — the number of ways to order n distinct items is exactly n!. Seating guests, ordering a playlist, or arranging books on a shelf are all factorial problems.
- Selections and groups — choosing a committee or a poker hand uses combinations (nCr), which are built from factorials divided by other factorials.
- Probability — event probabilities in games, lotteries, and the classic birthday problem are computed with factorial ratios.
- Keyspace estimation — the number of orderings of a character set gives an upper bound on brute-force attempts, which is useful for assessing password and PIN strength.
- Series and calculus — the Taylor series for ex, sine, and cosine all use factorials in their denominators, so they appear throughout numerical analysis.
- Algorithm analysis — brute-force algorithms over permutations, such as a naive travelling-salesman search, have a factorial running time that grows explosively with n.
How This Calculator Computes Factorials
The calculator multiplies 1 × 2 × 3 × … × n step by step, but instead of ordinary numbers it uses JavaScript's BigInt type. That means every digit of the result is stored exactly — including 1000!, which has 2,568 digits — with no rounding or scientific notation.
For permutations and combinations the tool reuses those exact big integers. Permutations use nPr = n! / (n − r)! and combinations use nCr = n! / (r! (n − r)!). Because both values are exact, the displayed results are correct to the last digit, even for inputs such as 52C5.
For a rough estimate of how large a factorial will be, you can use Stirling's approximation or the digit count formula. The number of digits in n! is approximately n × log10(n) − n × log10(e) + …, which is why the calculator reports the exact digit count alongside each result.
Frequently Asked Questions
What is a factorial?
The factorial of a non-negative integer n, denoted n!, is the product of all positive integers less than or equal to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. It counts the number of distinct ways to order a set of n items, which is why factorials are the foundation of permutations, combinations, and probability.
What is 0! ?
By convention, 0! = 1. This is defined as an empty product — multiplying zero numbers together leaves the multiplicative identity — and it keeps combinatorial formulas such as nCr consistent when r is 0 or r equals n. Without this definition, many probability formulas would need awkward special cases.
What is the difference between nPr and nCr?
nPr (permutations) counts ordered arrangements where order matters, such as the finishing order of a race. nCr (combinations) counts unordered selections where order does not matter, such as which five cards you hold. The formulas are nPr = n!/(n-r)! and nCr = n!/(r!(n-r)!). For example, 10P3 = 720 but 10C3 = 120, because the same three people can be ordered six different ways.
Where are factorials used in real life?
Factorials count arrangements and selections, so they appear in probability, statistics, lottery and card-game odds, scheduling and seating problems, and password or PIN strength estimation. Combinations such as 52C5 give the number of five-card poker hands, while factorial ratios drive the birthday-problem calculation.
Why does the calculator limit input to 5000?
Factorials grow astronomically. 1000! already has 2,568 digits and 5000! has more than 16,000 digits, so a higher limit would produce output that is slow to compute and impossible to display comfortably in a browser. The cap keeps the tool responsive while still covering every realistic use case.
What is the difference between a factorial and an exponent?
An exponent like 5^3 means 5 multiplied by itself three times, giving 125. A factorial like 5! means multiplying every integer from 1 up to 5 together, giving 120. The operations look superficially similar but behave completely differently: exponents have a fixed number of factors, while factorials add one more factor each time.
What is the factorial of a negative or non-integer number?
The ordinary factorial is only defined for non-negative whole numbers; negative integers have no factorial. For non-integer values the factorial is extended through the Gamma function, where n! = Γ(n + 1). This calculator intentionally accepts only integers from 0 to 5000 so that every result stays exact.
How many digits does n! have?
The number of digits grows quickly: 10! has 7 digits, 20! has 19, 100! has 158, and 1000! has 2,568. The calculator reports the exact digit count next to each result, and you can estimate it in advance with Stirling's approximation, which is accurate to within a digit or two for large n.