The factorial of n, written n!, is the product of every whole number from 1 up to n, and it counts how many ways you can order n distinct things. It is one of the most useful ideas in counting (combinatorics) and shows up everywhere from probability to algorithms. This calculator computes n! exactly for large numbers, and extends to permutations, combinations, and the double factorial.

What a factorial means

n! answers a simple question: in how many different orders can you arrange n distinct items? With 3 books there are 3! = 6 orders; with 5 there are 120; with 10 there are over 3.6 million. The reasoning is the multiplication principle: you have n choices for the first position, n-1 for the second, and so on down to 1. Multiply them together and you get n!. Because each extra item multiplies the count by a larger number, factorials grow faster than any exponential.

Why 0! = 1

It looks strange that the factorial of zero is one, not zero. There are two good reasons. First, there is exactly one way to arrange an empty set — the empty arrangement — so the count should be 1. Second, defining 0! = 1 keeps the combination formula nCr = n! / (r!(n-r)!) working at the edges: choosing 0 items from n, or all n items, should both give exactly 1 way, and that only comes out right when 0! = 1. Mathematicians call this an empty product, and an empty product is always 1.

Permutations vs. combinations

Both pick r items from a pool of n, but they differ on whether order matters. A permutation (nPr = n!/(n-r)!) treats ABC and CBA as different — use it for finishing positions in a race, or PIN codes. A combination (nCr = n!/(r!(n-r)!)) treats them as the same — use it for lottery numbers, poker hands, or a committee where seats are unlabeled. Because every combination can be reordered r! ways, nPr is always r! times nCr, so permutations are never fewer than combinations.

Double factorials and very large n

The double factorial n!! multiplies every other term: 9!! = 9 x 7 x 5 x 3 x 1 = 945. It appears in formulas for volumes of spheres and certain integrals. For very large n the exact factorial has thousands of digits, so this tool also reports Stirling's approximation — ln(n!) ~= n ln n - n + 0.5 ln(2 pi n) — which gives the digit count and order of magnitude. Even so, the exact digits are computed with arbitrary-precision integers, so nothing is rounded.