Factorial Calculator
Calculate the factorial of any number from 0 to 170 with exact results. See the step-by-step multiplication, trailing zero count, and a complete factorial reference table.
Factorial Calculator
Enter a non-negative integer to calculate its factorial (n!)
Enter a whole number from 0 to 170
Error
Step-by-Step Expansion
Factorial Values from 0! to n!
How to Use This Calculator
Enter a Number
Type any whole number from 0 to 170 into the input field, or click an example button to try a preset value
Click Calculate
Press the Calculate button or hit Enter on your keyboard to compute the factorial instantly
Explore the Results
View the exact result, step-by-step expansion, digit count, trailing zeros, and a factorial reference table
What Is a Factorial?
A factorial is a mathematical operation that multiplies a positive whole number by every positive integer below it, down to 1. If you pick any non-negative integer n, its factorial is written as n! (read aloud as "n factorial") and equals the product of all integers from 1 up to n. The exclamation mark is not there for emphasis — it is the universally accepted notation that mathematicians have used since the early 19th century, introduced by the French mathematician Christian Kramp in 1808.
To see what this means in practice, consider a small example. The factorial of 5 is written as 5! and equals 5 × 4 × 3 × 2 × 1 = 120. The factorial of 6 adds one more factor: 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720. Notice how adding a single step to the input multiplied the result by six. This explosive growth is one of the defining characteristics of factorials, and it is why they appear so often in counting problems involving arrangements and selections.
Factorials sit at the heart of combinatorics, the branch of mathematics concerned with counting possibilities. Whenever you need to count how many ways a set of objects can be arranged or chosen, you almost certainly need a factorial somewhere in your calculation. Our factorial calculator handles these computations instantly, so you can focus on interpreting the results rather than grinding through long multiplication chains by hand.
The Factorial Formula
The factorial formula has two equivalent forms that describe the same operation from different angles. The explicit (or iterative) definition spells out the multiplication directly, while the recursive definition expresses each factorial in terms of the one before it. Both are worth understanding, because the recursive form is how most computers actually calculate factorials, and seeing it helps build intuition for how rapidly these numbers grow.
Iterative Definition
For any positive integer n, the factorial is the product of all positive integers from 1 through n:
n! = n × (n − 1) × (n − 2) × … × 2 × 1
where n is a non-negative integer
For example: 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040. This definition is the most direct way to understand what the factorial of a number means. You start at n and keep multiplying by the next smaller integer until you reach 1.
Recursive Definition
The recursive definition expresses n! in terms of a smaller factorial. It is cleaner to write and closely mirrors how many programming languages implement the factorial function:
n! = n × (n − 1)!
Recursive step (for n ≥ 1)
0! = 1
Base case
You can trace the recursion for 5! like this: 5! = 5 × 4! = 5 × 4 × 3! = 5 × 4 × 3 × 2! = 5 × 4 × 3 × 2 × 1! = 5 × 4 × 3 × 2 × 1 × 0! = 5 × 4 × 3 × 2 × 1 × 1 = 120. The chain unwinds until it hits the base case, 0! = 1, at which point the multiplication can complete. Understanding this structure makes it easy to verify calculations and to see why 0! must equal 1.
Special Cases: 0! and 1!
Two values often confuse people when they first encounter factorials: 0! and 1!. Both equal 1, and while 1! is straightforward (it is just the product of a single number, 1), 0! needs a bit more explanation.
Why Does 0! Equal 1?
At first glance, multiplying no numbers together to get 1 can feel like a trick. But there are two satisfying reasons why mathematicians define 0 factorial as 1, and neither one is arbitrary.
The first reason comes directly from the recursive formula. If n! = n × (n − 1)!, then setting n = 1 gives 1! = 1 × 0!. Since 1! is clearly 1, we need 0! = 1 for the equation to be consistent. Any other value would break the pattern that holds for every positive integer.
The second reason comes from combinatorics. The number of ways to arrange zero objects in a sequence is exactly one: the empty arrangement. There is only one way to do nothing, and 0! = 1 captures that perfectly. This convention keeps formulas for permutations and combinations valid even when the input is zero, which happens frequently in probability problems.
What About 1!?
1! = 1 is the least surprising case. There is exactly one way to arrange a single object, and the product of all integers from 1 to 1 is simply 1. No mystery here — it follows cleanly from both the formula and the combinatorial interpretation.
Applications of Factorials
Factorials are far more than an abstract curiosity. They appear throughout mathematics, statistics, and computer science whenever problems involve arranging or selecting items. Knowing how to calculate factorial values is an essential skill across many fields.
Permutations
A permutation is an ordered arrangement of items. If you want to know how many ways you can arrange r items chosen from a set of n distinct items (where order matters), the answer is given by the permutation formula:
P(n, r) = n! ÷ (n − r)!
Number of ordered arrangements of r items from n
For example, how many ways can 3 runners finish first, second, and third in a race of 8 competitors? P(8, 3) = 8! ÷ 5! = 40,320 ÷ 120 = 336. There are 336 different possible podium outcomes. Notice how the factorial calculation naturally handles this by cancelling the shared terms in numerator and denominator.
Combinations
A combination counts the number of ways to choose r items from n when the order of selection does not matter. The combination formula uses factorials in all three positions:
C(n, r) = n! ÷ (r! × (n − r)!)
Number of unordered selections of r items from n
Choosing 5 lottery numbers from 1 to 49 involves C(49, 5) = 49! ÷ (5! × 44!) = 1,906,884 possible combinations. Factorials are the engine behind every such calculation. The binomial coefficient also forms the entries of Pascal’s triangle and appears in the binomial theorem, which expands expressions like (a + b)n.
Probability and Statistics
Many probability calculations lean directly on permutations and combinations, which in turn rely on factorials. The probability of a specific ordering of events, the likelihood of drawing a particular hand in a card game, and the chance of selecting a particular group of people for a committee all trace back to factorial expressions. The Poisson distribution and the multinomial distribution — two widely used statistical models — both contain factorials in their formulas.
Taylor Series and Calculus
In calculus, factorials appear in the denominators of Taylor series expansions. For example, the exponential function ex can be written as:
ex = 1 + x + x2/2! + x3/3! + x4/4! + …
Taylor series expansion of ex around x = 0
Similar expansions exist for sin(x), cos(x), and the natural logarithm. The factorial in each denominator grows so fast that the terms shrink rapidly, making the series converge. Without factorials, these elegant infinite representations would not work.
Properties of Factorials
Several important properties make factorials easier to work with and reveal why they behave the way they do.
- Rapid growth – Factorials grow faster than exponential functions. While 2n doubles with each step, n! multiplies by an ever-larger factor. By n = 20, the factorial is already 2,432,902,008,176,640,000 — a number with 19 digits.
- Divisibility – Because n! is the product of every integer from 1 to n, it is divisible by all of those integers and by every prime up to n.
- Ratio of consecutive factorials – The ratio (n + 1)! ÷ n! simplifies to just n + 1. This makes it simple to move between consecutive factorial values.
- Only defined for non-negative integers – The standard factorial is defined for 0, 1, 2, 3, and so on. The gamma function extends the concept to real and complex numbers, but that is a more advanced topic.
Stirling's Approximation
For very large values of n, Stirling's approximation provides a remarkably accurate estimate:
n! ≈ √(2πn) × (n/e)n
Stirling's approximation for large n
For n = 10, the relative error is less than 1%; for n = 100, it is less than 0.1%. Stirling's approximation is used in statistical physics, information theory, and any field where the rough size of a factorial is more important than the exact value.
How Trailing Zeros in n! Are Calculated
One of the more elegant factorial puzzles asks: how many trailing zeros does n! have? For example, 10! = 3,628,800, which has 2 trailing zeros. The answer is not found by computing the full factorial — instead, there is a neat shortcut.
A trailing zero is produced every time 10 appears as a factor in the product, and 10 = 2 × 5. Since factors of 2 are always more plentiful than factors of 5 in a factorial, the number of trailing zeros equals the number of times 5 divides into n!. This count is given by Legendre's formula:
Trailing zeros = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ⌊n/625⌋ + …
Sum continues until n/5k is less than 1
For 100!: ⌊100/5⌋ + ⌊100/25⌋ + ⌊100/125⌋ = 20 + 4 + 0 = 24 trailing zeros. You can verify this with our calculator: enter 100 and check the trailing zeros count. The formula works because multiples of 25 contribute an extra factor of 5 beyond what is already counted, multiples of 125 contribute yet another, and so on.
Factorials in Everyday Life
Factorials might seem like pure mathematics, but they show up in surprisingly concrete situations. Here are a few examples that illustrate just how large these numbers get.
Shuffling a Deck of Cards
A standard deck has 52 cards. The number of possible orderings is 52!, which equals roughly 8.07 × 1067. If every person who has ever lived shuffled a deck once per second for the entire age of the universe, the total number of shuffles would still be a tiny fraction of 52!. Every time a deck is properly shuffled, it almost certainly lands in an order that has never existed before in human history.
Lottery Odds
When a lottery asks you to choose 6 numbers from 1 to 49, the number of possible combinations is C(49, 6) = 49! ÷ (6! × 43!) = 13,983,816. That means you have roughly a 1 in 14 million chance of holding the winning ticket. Factorials let you calculate these odds exactly.
Seating Arrangements
Planning a dinner party for 8 guests? The number of distinct linear seating arrangements is 8! = 40,320. For circular seating, where rotations are considered identical, it drops to 7! = 5,040. Either way, factorials give you the exact count instantly.
Features of Our Factorial Calculator
- Exact large-number results – The calculator displays the full integer result for any input up to 170, not a rounded approximation. You can see every digit of 52! or 100! without scientific notation.
- Trailing zero count – Alongside the factorial value, the calculator shows how many trailing zeros the result contains, using Legendre's formula.
- Number of digits – See exactly how many digits the result has, helping you appreciate the scale of factorial growth.
- Step-by-step expansion – Watch the full multiplication chain unfold, showing exactly how the result is built from smaller factors.
- Factorial reference table – A complete table from 0! to n! lets you see how factorials grow at every step.
- Copy to clipboard – Copy the full result with a single click, ready to paste into a spreadsheet, document, or code editor.
- Works on any device – The responsive design functions equally well on desktop, tablet, and mobile, with no installation required.
Frequently Asked Questions
What is a factorial?
A factorial is the product of all positive integers from 1 up to a given number n, written as n!. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120. The factorial operation is fundamental in combinatorics, probability, and algebra, and it counts the number of ways to arrange n distinct objects in a sequence.
Why does 0! equal 1?
Zero factorial equals 1 by mathematical convention, and there are two good reasons for it. First, the recursive formula n! = n x (n-1)! requires 0! = 1 to work correctly when n = 1. Second, there is exactly one way to arrange zero objects: the empty arrangement. This definition keeps formulas for combinations and permutations consistent for all non-negative integers.
What is the largest factorial this calculator can handle?
This calculator supports values from 0 to 170. Beyond 170, the result exceeds the range of standard floating-point numbers in JavaScript. However, the calculator uses BigInt for exact integer arithmetic, so every digit displayed for values up to 170! is exact, not an approximation.
How are trailing zeros in a factorial calculated?
Trailing zeros in n! come from factors of 10, and since 10 = 2 x 5, you need to count how many times 5 appears as a factor. The formula is: floor(n/5) + floor(n/25) + floor(n/125) + floor(n/625) + ... and so on until the division result is zero. For example, 100! has floor(100/5) + floor(100/25) + floor(100/125) = 20 + 4 + 0 = 24 trailing zeros.
What are common uses of factorials?
Factorials are used in permutations (counting ordered arrangements), combinations (counting selections), probability calculations, Taylor series in calculus, and many areas of computer science. Practical examples include calculating lottery odds, counting possible passwords, determining seating arrangements, and analyzing card game probabilities.
Is factorial defined for negative numbers or decimals?
The standard factorial function is defined only for non-negative integers (0, 1, 2, 3, and so on). For non-integer and negative values, mathematicians use the gamma function, which extends the factorial concept to real and complex numbers. The gamma function satisfies the relationship gamma(n+1) = n! for non-negative integers. This calculator handles the standard integer factorial only.
Related Calculators
Percentage Calculator
Calculate percentages, percentage increase, and percentage decrease
Exponent Calculator
Calculate powers and exponents for any base and exponent value
Radical Calculator
Simplify radical expressions with step-by-step solutions
All Math Calculators
Browse our complete collection of mathematical calculators and tools