Audited 25 May 2026·Last updated 28 Oct 2026·5 citations·Tier 1·0 uses

Combinations with Replacement Calculator

Count multisets: the ways to pick k items from n types when repeats are allowed and order is ignored, C(n+k−1, k), with stars-and-bars working shown.

Combinations with Replacement Calculator

Number of distinct item types
Number of items to choose
Combinations with Replacement
35
The number of different multisets of size k drawn from n types, or equivalently the ways to share k identical items among n recipients; a pure count with no unit.
Binomial Coefficient
35

Background.

Three scoops from a counter with 31 flavors, where two or even all three scoops may be the same flavor and nobody cares which went in first: there are 5,456 different cups you could be handed. Counting them is a combinations-with-replacement problem. Mathematicians also call the result a multiset, or "31 multichoose 3", and the count is the binomial coefficient C(n + k − 1, k), here C(33, 3).

Set that beside the neighboring counts and the role of each assumption becomes clear. If the three scoops had to be different flavors, the answer would be the ordinary combination C(31, 3) = 4,495. If order mattered, so that vanilla-on-top differed from vanilla-at-the-bottom, every one of the three positions could take any of 31 flavors, giving 31³ = 29,791 sequences. Allowing repeats while ignoring order lands in between, and it is the one of the four cases that needs a trick to count. The gap between 4,495 and 5,456 is easy to account for by sorting cups by their pattern of repeats: 31 × 30 = 930 cups have two scoops of one flavor and one of another, 31 cups are a single flavor three times, and 4,495 + 930 + 31 = 5,456.

The same number answers questions that do not look like selections at all. Handing k identical items to n people, finding the non-negative whole-number solutions of x₁ + x₂ + … + xₙ = k, listing the distinct results k dice can show, and counting the terms of a polynomial of degree k in n variables are all the same count in disguise. Physics meets it too, wherever identical particles have to be shared among quantum states.

One warning belongs up front, because it catches people who move from counting to probability. The multisets are not equally likely when the items are drawn at random. Two dice can show 21 different unordered results, but a double one comes up once in 36 rolls while a one-and-two comes up twice in 36, because it can happen two ways. Dividing by the multiset count gives the wrong probability; for chance questions you count ordered outcomes instead.

What is combinations with replacement calculator?

A combination with replacement is an unordered selection of k items from n distinct types in which any type may be chosen more than once. The result is a multiset, a collection like a set except that elements can repeat, so {A, A, C} is a legitimate selection and is the same selection as {A, C, A}. Choosing 2 from the types A, B and C gives six of them: AA, AB, AC, BB, BC and CC. A multiset is fully described by how many copies of each type it holds, so the count is also the number of ways to write k as an ordered sum of n non-negative whole numbers, which combinatorics calls the weak compositions of k into n parts. The usual notation is C(n + k − 1, k), sometimes written with doubled parentheses and read "n multichoose k". It assumes an unlimited supply of every type, or at least k of each.

How to use this calculator.

  1. Enter the number of distinct types in Set Size (n): flavors on offer, faces on a die, variables in a polynomial, or people receiving items. It is the number of kinds, not the number of physical items in stock.
  2. Enter how many items each selection contains in Selection Size (k): scoops per cup, dice rolled, the degree of the polynomial, or identical items being handed out. Both values must be whole numbers, with n at least 1.
  3. If every type must appear at least once, enter k − n instead of k. Placing one of each first leaves k − n items to choose freely, and the count of those free choices is the answer.
  4. Before trusting the count, check its three assumptions: items of one type are interchangeable, order does not matter, and each type is available at least k times. If the items can be told apart, like numbered lottery balls, an ordinary combination or n to the power k is the right tool instead.
  5. Read the count. The second output shows the same number labeled as the binomial coefficient C(n + k − 1, k), so the two always agree; a result of 10¹⁵ or more is shown in scientific notation to four significant figures.

The formula.

C(n+k−1, k) = (n+k−1)! ⁄ [ k!(n−1)! ]

The count is C(n + k − 1, k) = (n + k − 1)! ÷ (k! × (n − 1)!), and the cleanest way to see why is the stars-and-bars picture. Write each selection as a row of k stars, one per item, divided into n compartments by n − 1 bars. With four types and seven items, ★★|★||★★★★ means two of the first type, one of the second, none of the third and four of the fourth. Every multiset gives exactly one such row and every row gives exactly one multiset, so counting multisets means counting rows. A row has n + k − 1 symbols, and it is fixed completely once you decide which k of those positions hold stars, which is an ordinary combination C(n + k − 1, k). Choosing the n − 1 bar positions instead gives C(n + k − 1, n − 1), the same number by the symmetry of binomial coefficients.

A second route explains the shape of the numbers. Every selection either contains none of the last type, leaving k items to choose from n − 1 types, or contains at least one, in which case removing one copy leaves k − 1 items from all n types. Adding the two cases gives a recurrence like Pascal's triangle: the count for 5 types and 8 items, 495, is the 165 selections of 8 items from 4 types plus the 330 selections of 7 items from 5 types.

The edge values follow from the formula without special rules. With k = 0 there is one selection, the empty one; with one type there is one selection, k copies of it; and with k = 1 there are n. For a fixed number of types the count grows as a polynomial in k of degree n − 1: two types give k + 1, and three give (k + 1)(k + 2) ÷ 2. The answer is computed by multiplying and dividing one factor at a time rather than through full factorials, which keeps intermediate values small; results below about 10¹⁴ come out as exact whole numbers.

A worked example.

Example

A teacher has 8 identical stickers to hand out among 5 pupils, and any pupil may get none, some or all of them. Only how many each pupil ends up with matters, so this is 5 multichoose 8: n = 5 and k = 8. In stars-and-bars form each handout is a row of 8 stars and 4 bars, 12 symbols in all, and choosing where the 4 bars go settles it. The count is C(12, 4) = (12 × 11 × 10 × 9) ÷ (4 × 3 × 2 × 1) = 11,880 ÷ 24 = 495, the same as C(12, 8) counted from the stars' side. There are 495 ways to distribute the stickers. Now suppose every pupil must get at least one. Giving each pupil a sticker first uses 5 of them and leaves 3 to hand out freely, so the answer is 5 multichoose 3, C(7, 3) = (7 × 6 × 5) ÷ 6 = 35. The requirement removes 460 of the 495 distributions, which shows how much of the original count consisted of pupils going empty-handed.

k8
n5

Frequently asked questions.

Why can't I divide by this count to get a probability?
Because the multisets are not equally likely when items are picked at random. Three dice show 56 different unordered results, but three ones can only happen one way out of 216 ordered rolls, while a one, a two and a three can happen in six orders. Dividing by 56 would make them equally likely. For probabilities, count ordered outcomes or use the multinomial distribution.
How many different unordered results can three six-sided dice show?
Fifty-six. The six faces are the types and the three dice are the selections, so the count is 6 multichoose 3, C(8, 3) = 56, against 6³ = 216 if the dice are told apart by color or position. Two dice give 21 unordered results against 36 equally likely ordered rolls.
What changes if each type has to appear at least once?
Subtract n from k before you enter it. Choosing 12 doughnuts from 6 varieties gives 6,188 possible boxes, but if every variety must be in the box you are really choosing only the 6 doughnuts left after taking one of each, which gives 462. The same shift counts solutions of x₁ + … + xₙ = k in positive rather than non-negative whole numbers.
What if only a limited number of each type is available?
Then the formula overcounts, because it assumes at least k of every type. Remove the excess with inclusion–exclusion. Choosing 4 items from 3 types gives 15 multisets, but if no type may appear more than twice, subtract the selections with three or more of some type: fix three copies of it and choose the remaining item freely, 3 ways for each of 3 types. That leaves 15 − 9 = 6.
How many terms does (a + b + c)⁴ have when expanded?
Fifteen. Each term is a product of four factors drawn from a, b and c with repeats allowed and order irrelevant, such as a²bc, so the count is 3 multichoose 4 = C(6, 4) = 15. More generally, a polynomial in n variables has n multichoose k distinct terms of degree k: a quadratic model in 10 variables has 55 second-degree terms.
Why does 5 types and 8 items give the same answer as 9 types and 4 items?
Both are C(12, 4) = 495. In stars-and-bars terms, 5 types and 8 items is a row of 8 stars and 4 bars; read the bars as items and the gaps between stars as types and the same row describes 4 items from 9 types. In general n multichoose k equals (k + 1) multichoose (n − 1), a duality that is easy to check here.
How large can n and k be before the answer becomes approximate?
Results below about 10¹⁴ are exact whole numbers. Just under 10¹⁵ the last digit can occasionally slip: 18 types and 44 items shows 536,830,054,536,824.94 where the exact count ends in 825. From 10¹⁵ up, results appear to four significant figures, so 100 types and 50 items gives 1.342 × 10⁴⁰. Beyond about 1.8 × 10³⁰⁸, the largest number double precision can hold, the result overflows and shows as infinity, which first happens at n = k = 511.
Why is a set size of zero not accepted?
Mathematically the cases are defined: with no types there is exactly one way to choose nothing and no way to choose anything else. They are rarely what anyone means, though, and the calculator asks for at least one type. A selection size of zero is accepted and gives 1, the single empty selection, for any number of types.
Is a password or PIN with repeated characters counted this way?
No. In a password the order of characters matters, so 1123 and 3211 are different PINs, and the count is n to the power k: 10⁴ = 10,000 four-digit PINs. The multiset count, 715 for four digits, only tells you how many different collections of digits exist, which is irrelevant to how hard a PIN is to guess.
Where does this count appear in physics?
In the statistics of identical particles. Bosons, such as photons, are indistinguishable and any number can share a quantum state, so k of them can be spread over n states in C(n + k − 1, k) ways, which underlies Bose–Einstein statistics. Planck's 1900 derivation of black-body radiation counted the ways to share energy units among oscillators with the same formula.

References& sources.

  1. [1]Knuth, D.E. (1997). The Art of Computer Programming, Vol. 1: Fundamental Algorithms, 3rd ed. Addison-Wesley. Section 1.2.6.
  2. [2]Feller, W. (1968). An Introduction to Probability Theory and Its Applications, Vol. 1, 3rd ed. Wiley. Chapter II.
  3. [3]Rosen, K.H. (2019). Discrete Mathematics and Its Applications, 8th ed. McGraw-Hill. Chapter 6.
  4. [4]Stanley, R.P. (1997). Enumerative Combinatorics, Vol. 1. Cambridge University Press. Section 1.2.
  5. [5]NIST Digital Library of Mathematical Functions. "Binomial Coefficients." https://dlmf.nist.gov/26.3

How this page was produced

Published by
Quanta Calculator
Primary sources
5 cited below
Method
C(n+k−1, k) = (n+k−1)! ⁄ [ k!(n−1)! ]
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon