Combination calculator (nCr) with step-by-step working
Work out how many ways there are to choose r items from n when the order doesn’t matter. The calculator gives the exact value of nCr however large it gets, shows the working step by step, lists every combination for small cases, and handles selections with repetition too.
On this page
The combination formula
The number of ways to choose items from distinct items, ignoring order and without using any item twice, is the binomial coefficient
All four notations mean the same number; textbooks and calculators use whichever is easiest to type. It is read “ choose ”. The exclamation mark is the factorial: , with .
Why the formula works
Start by counting ordered selections. There are ways to pick the first item, for the second, and so on, which gives ordered lists: the permutations . A combination is one of these lists with the order forgotten. Each set of items can be put in order in ways, so every combination was counted times. Dividing gives the formula:
Worked example: choose a committee of 3 from 10 people
- Substitute into the formula: .
- Cancel , which appears on the top and the bottom: .
- Multiply out: .
- Divide: 120 committees.
If the three roles were different (chair, secretary, treasurer), order would matter and the answer would be = 720, six times as many.
Step 2 is the trick for calculating by hand: never compute the large factorials. Keep only the top factors of and divide by . The calculator does the same, and it uses the symmetry first when that gives a shorter product, so is worked as .
Combination or permutation?
Ask one question: would rearranging the chosen items give a different outcome?
| Situation | Order matters? | Use |
|---|---|---|
| Lottery numbers, a hand of cards, pizza toppings, a team | No | Combination |
| Race podium, a password, seating in a row, a PIN | Yes | Permutation or |
| Scoops of ice cream or donuts where flavours can repeat | No, with repetition |
The same objects can fall on either side depending on the question. Three people chosen from ten form groups, but if you then line them up for a photo, each group gives photos.
Combinations with repetition
Tick Repetition allowed when the same kind can be chosen more than once and only how many of each you take matters: six donuts from four flavours, or three coins from pennies, nickels and dimes. The answer is
The reason is the stars and bars picture. Write the chosen items as stars and separate the kinds with bars: ★★|★||★★★ means two of the first flavour, one of the second, none of the third and three of the fourth. Every selection is one such row of symbols, and a row is fixed once you choose which of the positions hold stars. For six donuts from four flavours that gives = 84 different boxes.
Common combination problems
Lottery odds
In a 6-from-49 lottery the order the balls are drawn in doesn’t matter, so there are = 13,983,816 possible tickets. One ticket wins the jackpot with probability 1 in 13,983,816. Try it with the “Lottery” example above.
Card hands
A five-card hand from a standard deck: = 2,598,960. To count hands with at least one ace, count the complement: hands with no ace come from the 48 other cards, so the answer is = 886,656. Subtracting the complement is almost always easier than adding up “exactly one, exactly two, …”.
Choosing from two groups
A class has 6 girls and 5 boys. A team of two girls and two boys can be picked in = 150 ways, by the product rule. A team of 4 with at least one boy: = 315.
Subsets
Twelve toppings and you want exactly three: = 220 pizzas. Any number of toppings at all: , because each topping is independently in or out. Summing over every gives the same 4096, which is the row-sum identity of Pascal’s triangle.
- Counting ordered lists when order doesn’t matter. Picking “first a red card, then a black card” and multiplying counts every pair twice.
- Double counting with “at least”. Counting hands with at least one ace as (pick an ace, then any four cards) counts a hand with two aces twice. Subtract the complement instead.
- Rounding. A floating-point calculator loses digits beyond about . This calculator uses exact big-integer arithmetic, so comes out to all 300 digits.
Useful identities
- Symmetry: . Choosing what to take is choosing what to leave.
- Pascal’s rule: , the addition rule of Pascal’s triangle.
- Row sum: , the number of subsets of an -element set.
- Edge cases: , and when .
- Binomial theorem: , which is where the name “binomial coefficient” comes from.
How the calculator works
Everything runs in your browser with JavaScript’s BigInt, so results are exact integers with no rounding. To avoid ever building a huge factorial, it multiplies and divides alternately: after step the running value is exactly , which is always a whole number, so every division is exact. Values with ten or more digits are also shown in scientific notation, and the page address updates as you type so you can bookmark or share a calculation.
For the theory behind the four basic counting formulas, with Pascal’s triangle drawn interactively, see permutations, combinations and Pascal’s triangle. For ordered selections, use the permutation calculator.
References
- R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, 2nd ed., Addison-Wesley, 1994. Chapter 5, “Binomial coefficients”.
- K. H. Rosen, Discrete Mathematics and Its Applications, 8th ed., McGraw-Hill, 2019. Sections 6.3 and 6.5.
- “Combination”, Wikipedia.