Combination Calculator

By · Last updated:

Combination Calculator nCr = n! / (r!(n − r)!)

Enter the total number of items n and how many you choose r. You get the exact number of combinations (nCr), permutations (nPr) and both with-repetition counts, a chart of row n of Pascal’s triangle, and the cancellation worked out.

Examples:

A combination is a selection of r items from a set of n in which the order of the items does not matter, and the number of such selections is the binomial coefficient nCr = n! / (r!(n − r)!). This combination calculator returns nCr exactly, together with the permutation count nPr and both with-repetition counts, for n up to 1,000.

What is a combination?

A combination answers the question “how many different groups of size r can I form from n distinct items?” The group {A, B, C} is the same combination as {C, A, B}, because only membership counts. The count is written nCr, C(n, r) or as the binomial coefficient “n choose r”.

Choosing a 3-person committee from 10 people is a combination problem: there are 120 possible committees. Awarding gold, silver and bronze to 3 of those 10 people is a permutation problem, because swapping two medals gives a different outcome, and there are 720 ways to do it.

What is the combination formula?

\[ C(n,r) = \binom{n}{r} = \frac{n!}{r!\,(n-r)!} \qquad P(n,r) = \frac{n!}{(n-r)!} = C(n,r)\cdot r! \]
  • n is the total number of distinct items available.
  • r is the number of items chosen, with 0 ≤ r ≤ n.
  • n! (n factorial) is the product n × (n − 1) × … × 1, with 0! defined as 1.
  • P(n, r) counts ordered arrangements. Each combination can be ordered in r! ways, which is why nCr is nPr divided by r!.

Two properties are worth knowing. The count is symmetric, C(n, r) = C(n, n − r), since choosing which r items to keep is the same as choosing which n − r to leave out. It also obeys Pascal’s rule, C(n, r) = C(n − 1, r − 1) + C(n − 1, r), which is how each row of Pascal’s triangle in the chart is built from the row above.

Worked example: 10 choose 3

The calculator loads with n = 10 and r = 3. Substituting into the formula gives 10! / (3! × 7!). The 7! cancels the last seven factors of 10!, leaving three factors on top:

\[ \binom{10}{3} = \frac{10 \times 9 \times 8}{3 \times 2 \times 1} = \frac{720}{6} = 120 \]

The numerator, 720, is the permutation count P(10, 3). Dividing by 3! = 6 collapses the six orderings of each trio into one selection. As a check with Pascal’s rule, C(9, 2) + C(9, 3) = 36 + 84 = 120. The full row for n = 10 is 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, which sums to 210 = 1,024.

Combination vs permutation: does order matter?

Two questions decide which of the four counting formulas applies: does the order of the chosen items matter, and can the same item be chosen more than once? The table fills in all four cases for n = 10 and r = 3, which are the four values the calculator reports.

No repetitionRepetition allowed
Order mattersPermutation: n! / (n − r)! = 720
Gold, silver and bronze among 10 runners
nr = 103 = 1,000
A 3-digit PIN from the digits 0 to 9
Order does not matterCombination: n! / (r!(n − r)!) = 120
A 3-person committee from 10 people
C(n + r − 1, r) = C(12, 3) = 220
3 scoops from 10 ice-cream flavours

Reading across a row, allowing repetition always increases the count. Reading down a column, ignoring order always decreases it.

Where are combinations used in statistics and machine learning?

Binomial distribution. The probability of exactly k successes in n independent trials is C(n, k) pk(1 − p)n − k. For 3 heads in 10 fair coin flips that is 120 / 1,024 = 0.1172. The coefficient counts the arrangements of successes; the mean of the distribution, np, is what an expected value calculation returns.

Hypergeometric distribution. Sampling without replacement uses three binomial coefficients, C(K, k) × C(N − K, n − k) / C(N, n). The hypergeometric probability calculator evaluates that ratio directly.

Feature selection. With p candidate features there are C(p, r) subsets of size r. Picking 5 features from 20 already gives 15,504 candidate models, and searching every size gives 220 = 1,048,576, which is why exhaustive subset search is replaced by greedy or regularised methods.

Pairwise comparisons. The number of unordered pairs among n items is C(n, 2) = n(n − 1) / 2. A one-vs-one multiclass classifier trains one binary model per pair of classes, so 10 classes need C(10, 2) = 45 models. Their votes are then scored with a multiclass confusion matrix.

Cross-validation. Leave-p-out cross-validation fits one model for every possible test set of size p, which is C(n, p) fits. With 100 samples, leave-one-out needs 100 fits, leave-2-out needs 4,950, and leave-5-out needs 75,287,520. k-fold cross-validation is popular because it uses only k of those possible splits.

SituationExpressionCount
One-vs-one models for 10 classesC(10, 2)45
Feature subsets of size 5 from 20 featuresC(20, 5)15,504
Leave-2-out splits of 100 samplesC(100, 2)4,950
5-card hands from a 52-card deckC(52, 5)2,598,960
6-number tickets in a 49-ball lotteryC(49, 6)13,983,816

Permutations appear too: the Leibniz expansion of an n × n determinant sums over all n! orderings of the columns, 3,628,800 terms for a 10 × 10 matrix, which is why a determinant solver uses elimination instead.

Common mistakes

  • Using nPr when order is irrelevant. This overcounts by a factor of r!. A lottery ticket is a combination, so the odds are 1 in 13,983,816, not 1 in 10,068,347,520.
  • Swapping n and r. n is always the size of the pool. C(3, 10) is 0 because you cannot pick 10 distinct items from 3.
  • Forgetting repetition. If an item can be chosen again, use C(n + r − 1, r) or nr; the plain formulas undercount.
  • Computing full factorials in floating point. 171! overflows a double, and JavaScript numbers are exact only up to about 9 × 1015. Cancel first, or use exact integers as this page does.
  • Assuming C(n, 0) is 0. It is 1: there is one way to choose nothing.

How do you calculate combinations in Python?

Python 3.8 and later include exact integer functions in the standard library, documented in the Python math module reference. SciPy offers scipy.special.comb, which also handles repetition.

import math
from scipy.special import comb

n, r = 10, 3
print(math.comb(n, r))           # 120   combinations
print(math.perm(n, r))           # 720   permutations
print(math.comb(n + r - 1, r))   # 220   combinations with repetition
print(n ** r)                    # 1000  permutations with repetition

print(comb(n, r, exact=True))                    # 120
print(comb(n, r, exact=True, repetition=True))   # 220
print(math.comb(100, 50))   # 100891344545564193334812497256

Pass exact=True to SciPy when you need every digit; the default returns a floating-point approximation.

Frequently asked questions

What is the difference between a combination and a permutation?

A combination counts selections where order does not matter, and a permutation counts arrangements where order matters. Every combination of r items can be arranged in r! orders, so nPr equals nCr multiplied by r!. For n = 10 and r = 3 that is 120 combinations and 720 permutations.

How do you calculate 10 choose 3?

Write 10! / (3! 7!), cancel the 7!, and you are left with (10 x 9 x 8) / (3 x 2 x 1) = 720 / 6 = 120.

What is nCr when r is 0 or r equals n?

It is 1 in both cases. There is exactly one way to choose nothing and exactly one way to choose everything, which matches the formula because 0! is defined as 1.

Can this calculator handle large values such as 100 choose 50?

Yes. It uses arbitrary-precision integer arithmetic, so 100 choose 50 is returned exactly as 100,891,344,545,564,193,334,812,497,256, which is about 1.0089 x 10^29. Inputs up to n = 1000 are supported.

Related calculators

Browse every tool in the statistics calculators hub, or continue with the ones that build directly on counting: