Factorial Calculator
Compute the factorial n!, the product of all positive integers up to n. It is essential for permutations, combinations, and probability calculations.
Last updated: May 2026
Compare with similar
About this calculator
The factorial of a non-negative integer n, written n!, is the product of all positive integers from 1 up to n: n! = n × (n − 1) × (n − 2) × ... × 2 × 1. By definition 0! = 1 (an empty product), and 1! = 1. This calculator multiplies iteratively from 2 up to the input, and returns NaN for negative or non-integer inputs because the ordinary factorial is defined only on non-negative integers (the gamma function extends it elsewhere, but that is beyond this tool). The single input is the number n. Factorials count the number of ways to arrange n distinct objects in order, which is why they sit at the heart of combinatorics: permutations P(n, k) = n! / (n − k)! and combinations C(n, k) = n! / (k! (n − k)!) both build on them. They also appear throughout probability, Taylor series, and the definition of e. The defining recurrence is n! = n × (n − 1)!, with base case 0! = 1. A practical caveat is explosive growth: factorials increase faster than any exponential, so values like 13! already exceed two billion and large n quickly overflows standard number types, losing precision.
How to use
Example 1 — 5!. Enter Number = 5. Multiply step by step: 1 × 2 = 2, × 3 = 6, × 4 = 24, × 5 = 120. So 5! = 120. Verify the meaning: there are exactly 120 different orders in which five distinct books can be arranged on a shelf. Example 2 — 7!. Enter Number = 7. Continue from 5! = 120: × 6 = 720 (that is 6!), then × 7 = 5040. So 7! = 5040. Verify with the recurrence: 7! = 7 × 6! = 7 × 720 = 5040, and as a sanity check 7! / 5! = 5040 / 120 = 42 = 7 × 6, exactly the number of ordered ways to pick 2 items from 7.
Frequently asked questions
Why is 0! equal to 1 and not 0?
0! = 1 by convention, and it is the convention that makes the rest of combinatorics consistent. There is exactly one way to arrange an empty set — the empty arrangement — so counting arguments give 1, not 0. It also keeps key formulas valid: the recurrence n! = n × (n − 1)! gives 1! = 1 × 0!, which forces 0! = 1, and the combination formula C(n, n) = n! / (n! · 0!) only equals the correct value of 1 if 0! = 1. Treating 0! as 0 would make these formulas divide by zero or return wrong counts. So 0! = 1 is a definition chosen to keep mathematics coherent.
What is the difference between a permutation and a combination?
Both are built from factorials, but a permutation counts ordered arrangements while a combination counts unordered selections. The number of permutations of k items from n is P(n, k) = n! / (n − k)!, whereas the number of combinations is C(n, k) = n! / (k! (n − k)!), which is smaller by a factor of k!. For example, choosing 2 of 7 people for distinct roles (president, treasurer) is a permutation (42 ways), but choosing 2 for an unranked committee is a combination (21 ways). The most common mistake is using one when the problem calls for the other. Ask whether order matters: if it does, permutation; if not, combination.
Why does the calculator return NaN for negative or decimal inputs?
The ordinary factorial is defined only for non-negative integers, so negative numbers and non-integers have no standard factorial and the tool returns NaN. There is a generalization, the gamma function Γ(n + 1) = n!, that extends factorials to real and complex numbers, but it requires different machinery this calculator does not implement. For example, the gamma function gives (1/2)! = √π / 2, a result outside simple integer arithmetic. So if you need factorials of fractions or negative values, you need a gamma-function tool instead. For all whole-number counting problems, the integer factorial here is what you want.
How quickly do factorials grow, and why does that cause overflow?
Factorials grow faster than any exponential function, a rate captured by Stirling's approximation n! ≈ √(2πn) (n/e)^n. The practical consequence is rapid blow-up: 10! is already 3,628,800, 13! exceeds two billion, and 21! exceeds what a 64-bit integer can hold. Standard floating-point numbers lose exact precision well before that and eventually return Infinity. So for large n you should expect rounding or overflow rather than an exact value. When exact large factorials are needed, use arbitrary-precision (big-integer) arithmetic rather than ordinary number types.
When should I NOT use a factorial calculator?
Avoid feeding it large n if you need exact results, because ordinary number types overflow or lose precision past roughly 20!; use big-integer or logarithmic methods instead. Do not use it for negative numbers, fractions, or complex values — those require the gamma function, not the integer factorial. It is also the wrong tool when you actually want a permutation or combination count directly; while those use factorials, a dedicated combinatorics calculator avoids manual division and the risk of huge intermediate values. Finally, in probability work it is often better to compute ratios of factorials together (canceling terms) rather than evaluating each factorial separately, to keep numbers manageable. Choose the approach that preserves precision for your range of n.