Permutations and combinations explained

How many ways can a race finish, how many lottery tickets are there, how many passwords of eight characters? Counting questions like these look endlessly varied, but almost all of them come down to the same two questions: does the order of the items matter, and may the same item be chosen more than once? The answers give four formulas, and with them you can count anything from podiums to poker hands without listing a single case.

Three places filled with 5, 4 and 3 choices, the six orders of A, B and C collapsing into one selection, and a row of stars and bars
Three places filled with 5, 4 and 3 choices, the six orders of A, B and C collapsing into one selection, and a row of stars and bars

The multiplication principle

Every formula in counting grows from one idea: if a choice is made in steps, multiply the number of options at each step. A shirt from 4 and trousers from 3 gives 4 × 3 = 12 outfits, and adding one of 2 pairs of shoes makes 24. The principle works as long as the number of options at each step does not depend on what was chosen before, even if the options themselves do. It turns questions about huge sets into a few multiplications.

Permutations: when the order matters

Put k of n different items in a row. There are n choices for the first place, n − 1 for the second, because one item is used, and n − k + 1 for the last. The product n × (n − 1) × … × (n − k + 1) is written P(n, k), nPk or nPr, and equals n! / (n − k)!, where n! = n × (n − 1) × … × 2 × 1 is n factorial. Eight runners can fill the podium in 8 × 7 × 6 = 336 ways, and all of them can finish in 8! = 40,320 orders. If k is larger than n there are not enough items and the count is 0.

Combinations: when only the selection counts

A lottery ticket does not care in which order the balls are drawn. Count the ordered draws first, P(n, k), and notice that each selection of k items has turned up k! times, once for each order of its items. Dividing gives the number of combinations, C(n, k) = n! / (k! (n − k)!), also written nCk, nCr or as n over k in brackets and read n choose k. A lottery of 6 from 49 has 13,983,816 tickets, and a poker hand of 5 from 52 cards can be dealt in 2,598,960 ways. Choosing k to take is the same as choosing n − k to leave, so C(n, k) = C(n, n − k).

Choices with repetition

When the same item may be picked again, every place has all n options, and the multiplication principle gives nᵏ ordered lists: 10⁴ = 10,000 PINs of four digits, and 2⁸ = 256 bytes. Without order, picking with repetition means choosing how many of each kind to take, like three scoops from five flavours. Draw the scoops as k stars and separate the flavours with n − 1 bars, so that ★|★★||| means one of the first flavour and two of the second. Every row of n + k − 1 symbols is one choice, and choosing the places of the stars gives C(n + k − 1, k): 35 cones of three scoops from five flavours.

Words with repeated letters

The 11 letters of MISSISSIPPI can be put in 11! orders, but swapping the four I's among themselves gives the same word, and so does swapping the four S's or the two P's. Each distinct word appears 4! × 4! × 2! times in the 11! orders, so there are 11! / (4! · 4! · 2!) = 34,650 distinct words. In general n items with groups of m₁, m₂, … equal items have n! / (m₁! m₂! …) arrangements, the multinomial coefficient. The same formula counts the ways to deal 52 cards into four hands of 13 or to split a class into teams.

How fast the numbers grow

Factorials outgrow every power: 10! is 3,628,800, 20! already has 19 digits, and the 52! orders of a deck of cards form a number of 68 digits, so large that a well-shuffled deck has almost certainly never been in the same order before. Stirling's formula n! ≈ √(2πn) (n/e)ⁿ estimates them. This is why brute-force searches fail so quickly and why short passwords are weak: each extra character multiplies the number of possibilities by the size of the alphabet.

Counting through history

Indian mathematicians counted combinations more than two thousand years ago: Pingala's work on poetic metres and the medical writer Sushruta, who listed the 63 combinations of six tastes, are early examples. In the 12th century Bhaskara II gave the formulas for permutations and combinations, and Levi ben Gershon proved them in 1321. Pascal and Fermat founded probability theory on counting in their letters of 1654, and Jacob Bernoulli's Ars Conjectandi of 1713 gave the subject its systematic form. Today combinatorics runs through computer science, from the analysis of algorithms to codes and cryptography.

A manuscript of Bhaskara II's Lilavati, in Sanskrit and Newar script. In the 12th century Bhaskara II gave the formulas for permutations and combinations.
A manuscript of Bhaskara II's Lilavati, in Sanskrit and Newar script. In the 12th century Bhaskara II gave the formulas for permutations and combinations.

Explore it

Open the permutation and combination calculator to enter n and k and see all four counts at once, exact to the last digit. Click a case to see its formula worked out for your numbers and a picture of the count, try the worked examples from lotteries to anagrams, and type your own items, words, numbers or emoji, to list every arrangement in alphabetical order.

Frequently asked questions

How do I know whether to use a permutation or a combination?

Ask whether swapping two of the chosen items gives a different result. If it does, as for a ranking, a password or a seating plan, the order matters and you count permutations. If it does not, as for a team, a hand of cards or a pizza's toppings, you count combinations.

Why is 0! equal to 1?

There is exactly one way to arrange nothing: the empty arrangement. With 0! = 1 the formulas also hold at the edges: P(n, n) = n! / 0! = n!, and C(n, 0) = C(n, n) = 1, the one way to choose nothing or everything.

What does C(n, k) have to do with Pascal's triangle?

The number in row n at place k of Pascal's triangle, counting from 0, is C(n, k). The rule that every number is the sum of the two above it is C(n, k) = C(n − 1, k − 1) + C(n − 1, k): a selection either contains the last item or it does not.

What are the odds of winning a 6 out of 49 lottery?

There are C(49, 6) = 13,983,816 possible tickets and only one wins the jackpot, so the chance is 1 in 13,983,816, about 0.000007%. Buying ten tickets makes it 10 in 13,983,816: still far less likely than being struck by lightning in your lifetime.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Open the permutation and combination calculator