Audited 25 May 2026·Last updated 27 Jul 2026·5 citations·Tier 1·0 uses

Combinations with Replacement Calculator

Calculate combinations with replacement using C(n+k-1, k). Count multisets when order does not matter and items can be repeated.

Combinations with Replacement Calculator

Number of distinct item types
Number of items to choose
Combinations with Replacement
35
Number of multisets of size k from n types
Binomial Coefficient
35

Background.

Combinations with replacement, also known as multisets or multichoose, count the number of ways to select k items from a set of n distinct types when repetition is allowed and order does not matter. The canonical example is choosing k scoops of ice cream from n flavors, where multiple scoops may be the same flavor and the order in which they are placed in the cone is irrelevant. The calculator evaluates the binomial coefficient C(n+k−1, k), which gives the exact count for any non-negative integers n and k. This combinatorial concept appears in statistical mechanics, where bosons can occupy the same quantum state, in manufacturing, where a parts bin may contain multiple identical units, and in computer science, where password-strength estimators must account for repeated characters. A quality engineer sampling with replacement from a lot of n defect types needs to know how many distinct samples of size k are possible. A data scientist generating synthetic datasets with k features drawn from n categorical levels must enumerate the possible feature vectors. In each case, the standard combination formula C(n, k) is insufficient because it forbids repetition.

The formula C(n+k−1, k) = (n+k−1)! / (k!(n−1)!) can be understood through the stars-and-bars argument. Imagine k identical stars representing the selected items and n−1 bars dividing the stars into n categories. Each arrangement of stars and bars corresponds to exactly one combination with replacement. The total number of symbols is n+k−1, and choosing which k positions are stars (or equivalently which n−1 are bars) yields the binomial coefficient. This bijective proof, attributed to early twentieth-century combinatorialists and formalized in modern textbooks, is elegant because it reduces a counting problem with repetition to a counting problem without repetition.

In probability theory, combinations with replacement govern the multivariate hypergeometric distribution and its approximations. When drawing k balls from an urn containing n colors with replacement, the number of distinct color-count vectors is C(n+k−1, k). This denominator appears in Bayesian nonparametrics when enumerating partitions and in occupancy problems when distributing indistinguishable balls into distinguishable bins. The calculator therefore serves statisticians, physicists, and operations researchers who need exact counts for enumeration or normalization constants.

The computational challenge is factorial overflow. For n = 100 and k = 50, the result is C(149, 50) ≈ 2.04 × 10⁴³, which exceeds the range of 64-bit integers. The calculator uses IEEE-754 double-precision floating point, which can represent integers exactly up to 2⁵³ and approximates larger values with about 15 significant digits. For exact integer results beyond this range, arbitrary-precision libraries are required, but the double-precision output is sufficient for most practical estimation and verification tasks. The validation rules reject negative inputs and non-integer values because the combinatorial definition applies only to non-negative integers.

In software engineering, combinations with replacement model the state space of certain search algorithms. A constraint-satisfaction problem with k variables and n values per variable has n^k ordered assignments, but only C(n+k−1, k) unordered multisets if the values are indistinguishable except by type. This reduction factor guides complexity analysis and heuristics selection. In genetics, multinomial sampling with replacement describes the distribution of k offspring across n alleles under neutral drift. The normalization constant of the multinomial probability mass function involves factorials that the calculator can verify independently. The formula thus bridges recreational mathematics—how many ways to make change for a dollar using k coins of n denominations—with frontier research in algorithmic biology.

What is combinations with replacement calculator?

A combination with replacement is a selection of k objects from n distinct categories such that each category may be chosen multiple times and the order of selection is irrelevant. The result is a multiset: a generalization of a set that allows repeated elements. The notation for the count is ((n choose k)) or C(n+k−1, k), read as "n multichoose k." This quantity is also the number of weak compositions of k into n parts, where each part is a non-negative integer representing how many times a particular category was selected. The relationship to ordinary combinations is direct. Ordinary combinations C(n, k) count selections without replacement: once an item is chosen, it cannot be chosen again. Combinations with replacement relax this restriction. For example, choosing two letters from {A, B, C} without replacement yields {A,B}, {A,C}, and {B,C}: three combinations. With replacement, the selections {A,A}, {B,B}, and {C,C} are also valid, giving six total. The formula C(3+2−1, 2) = C(4, 2) = 6 confirms this enumeration. The inputs n and k must be non-negative integers. By convention, C(n, 0) = 1 for all n ≥ 1, reflecting the single empty selection. The calculator requires n > 0 and k ≥ 0. It enforces integer inputs because fractional or negative selections have no combinatorial meaning.

How to use this calculator.

  1. Enter the set size n, which is the number of distinct categories or types available.
  2. Enter the selection size k, which is the number of items to choose.
  3. Ensure both n and k are non-negative integers. Decimal or negative values will be rejected.
  4. Click the Calculate button to evaluate the multiset coefficient.
  5. Review the Combinations with Replacement output for the exact count of possible multisets.
  6. Check the Binomial Coefficient output to see the equivalent C(n+k−1, k) form.
  7. Use the result to verify textbook problems, plan sampling schemes, or estimate state-space sizes.

The formula.

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

The standard formula for combinations with replacement is C(n+k−1, k) = (n+k−1)! / (k! × (n−1)!). This expression is a binomial coefficient evaluated at n+k−1 and k, and it can be derived rigorously via the stars-and-bars correspondence. Consider k indistinguishable stars and n−1 distinguishable bars arranged in a line of n+k−1 positions. The bars partition the line into n bins, one for each category. The number of stars in bin i represents how many times category i was selected. Because stars are identical and bars are identical within their own type, every distinct arrangement corresponds to exactly one combination with replacement, and every combination with replacement corresponds to exactly one arrangement. The number of arrangements is the number of ways to choose k positions for the stars out of n+k−1 total positions, which is C(n+k−1, k). Equivalently, one may choose n−1 positions for the bars, yielding C(n+k−1, n−1); the two binomial coefficients are equal by the symmetry identity C(m, r) = C(m, m−r). Computationally, direct factorial evaluation is inefficient and prone to overflow. The calculator should implement the multiplicative formula: C(n+k−1, k) = Πᵢ₌₁ᵏ (n+k−i) / i. This product computes the result iteratively, keeping intermediate values as small as possible and avoiding factorials entirely. At each step, the current numerator term is divided by i before multiplication, which reduces rounding error in floating-point arithmetic. The product has exactly k terms. When k > n+k−1−k = n−1, it is more efficient to compute C(n+k−1, n−1) instead, using the smaller of the two choices. The formula satisfies several identities that serve as sanity checks. Pascal's identity extends to multisets: C(n+k−1, k) = C(n+k−2, k) + C(n+k−2, k−1). The boundary conditions are C(n−1, 0) = 1 and C(n+k−1, 1) = n. For n = 1, the formula reduces to C(k, k) = 1, confirming that there is exactly one way to choose k items from a single category. For k = 0, it reduces to C(n−1, 0) = 1, confirming the empty selection.

A worked example.

Example

A bakery offers five cupcake flavors—vanilla, chocolate, strawberry, lemon, and red velvet—and a customer wants to assemble a box of eight cupcakes. Because the box can contain multiple cupcakes of the same flavor and the order inside the box does not matter, this is a combination-with-replacement problem with n = 5 and k = 8. Applying the formula C(n+k−1, k) = C(5+8−1, 8) = C(12, 8). By the symmetry identity C(12, 8) = C(12, 4). Compute C(12, 4) = (12 × 11 × 10 × 9) / (4 × 3 × 2 × 1) = 11880 / 24 = 495. The customer therefore has 495 distinct flavor combinations to choose from. To verify, use the multiplicative form: (12/1) × (11/2) × (10/3) × (9/4) = 12 × 5.5 × 3.333… × 2.25. Stepwise: 12 × 5.5 = 66; 66 × 3.333… = 220; 220 × 2.25 = 495. The result is exact because all intermediate divisions produce integers. A bakery manager using this figure can plan frosting inventory, knowing that any given eight-cupcake order is one of 495 possible multisets.

k8
n5

Frequently asked questions.

How is this different from ordinary combinations?
Ordinary combinations count selections without replacement: each distinct item can be chosen at most once. Combinations with replacement allow the same item or category to be chosen multiple times. For example, choosing two letters from {A, B, C} without replacement yields {A,B}, {A,C}, and {B,C}: three combinations. With replacement, the selections {A,A}, {B,B}, and {C,C} are also valid, giving six total. The ordinary formula is C(n, k) = n!/(k!(n−k)!), while the with-replacement formula is C(n+k−1, k). The difference in the numerator argument—n versus n+k−1—reflects the additional degrees of freedom introduced by repetition. If k > n, ordinary combinations are zero because there are not enough distinct items, but combinations with replacement remain valid and grow monotonically.
What are stars and bars?
Stars and bars is a combinatorial proof technique that represents a selection as a sequence of symbols. Stars (*) stand for the k selected items, and bars (|) separate the n categories. For n = 4 categories and k = 5 selections, the arrangement **|*||** corresponds to two items from category 1, one from category 2, none from category 3, and two from category 4. The total number of symbols is n+k−1, and the number of distinct arrangements is the number of ways to place either the stars or the bars. This yields C(n+k−1, k) or equivalently C(n+k−1, n−1). The method was popularized by combinatorial textbooks in the mid-twentieth century and is now the standard pedagogical tool for multisets and weak compositions.
Can n or k be zero?
Yes, with specific conventions. If k = 0, there is exactly one selection: the empty set. The formula gives C(n−1, 0) = 1 for any n ≥ 1. If n = 1, there is exactly one category, so there is exactly one way to choose k items: all from that category. The formula gives C(k, k) = 1. The calculator requires n > 0, so n = 0 is rejected at validation. These boundary cases are important for software validation because they test the initialization of multiplicative loops and the handling of empty products. The calculator returns 1 for k = 0 and n ≥ 1.
Why does the calculator use floating point instead of exact integers?
Exact integer computation of binomial coefficients requires arbitrary-precision arithmetic because C(n+k−1, k) grows exponentially. For n = 100 and k = 50, the result exceeds 10⁴³, far beyond the 64-bit integer limit of 9.2 × 10¹⁸. IEEE-754 double-precision floating point can represent integers exactly up to 2⁵³ ≈ 9 × 10¹⁵ and approximates larger values with about 15 significant digits. For most practical applications—estimating state-space sizes, computing sampling-plan coverage, or verifying homework answers—15 significant digits are sufficient. Users who need exact large integers for cryptographic or number-theoretic work should use specialized libraries such as Python's integers or Java's BigInteger. The calculator documents its precision limits so that users understand when exactness is guaranteed.
What is a weak composition and how does it relate?
A weak composition of an integer k into n parts is an ordered n-tuple of non-negative integers (x₁, x₂, …, xₙ) such that x₁ + x₂ + … + xₙ = k. The number of weak compositions is C(n+k−1, k). This is identical to the number of combinations with replacement because each weak composition records how many times each category was selected. The difference is purely notational: combinations with replacement emphasize the selection process, while weak compositions emphasize the resulting count vector. In statistics, weak compositions appear as the support of the multinomial distribution. In computer science, they enumerate the possible memory allocations of k indistinguishable pages across n distinguishable processes.
How do permutations with replacement differ?
Permutations with replacement count ordered selections where repetition is allowed. The count is n^k because each of the k positions can be filled independently by any of the n categories. Combinations with replacement ignore order, so n^k overcounts by the number of permutations of each multiset. For example, with n = 3 and k = 2, permutations with replacement give 3² = 9 ordered pairs: (A,A), (A,B), (A,C), (B,A), (B,B), (B,C), (C,A), (C,B), (C,C). Combinations with replacement give only 6 unordered multisets because (A,B) and (B,A) are considered identical, as are (A,C) with (C,A) and (B,C) with (C,B). The relationship is n^k = Σ C(k; m₁, m₂, …, mₙ), where the sum is over all multisets and the summand is the multinomial coefficient.
Where does this formula appear in physics?
In statistical mechanics, Bose-Einstein statistics describe indistinguishable particles that can occupy the same quantum state. The number of ways to distribute k bosons among n energy states is C(n+k−1, k). This result appears in the derivation of the Planck blackbody radiation law and in the theory of quantum degeneracy. In polymer physics, the number of ways to arrange k monomers of n types along a chain, ignoring sequence order, is given by the same multiset coefficient. These applications require exact counts for partition functions, which sum over all microstates. The calculator provides a quick verification of textbook derivations and a tool for cross-checking simulation results.
What happens if k is much larger than n?
The formula is symmetric in the sense that C(n+k−1, k) = C(n+k−1, n−1). When k >> n, it is computationally more efficient to evaluate C(n+k−1, n−1) because the product has only n−1 terms instead of k terms. For example, with n = 3 and k = 100, C(102, 100) = C(102, 2) = 102 × 101 / 2 = 5151. The direct computation with k = 100 would require a 100-term product, while the symmetric form requires only two multiplications and one division. The calculator implementation should automatically select the smaller of k and n−1 for the loop bound. This optimization also reduces accumulated floating-point rounding error because fewer operations are performed.
Can this formula be used for password or lottery calculations?
Only with caution. A password of length k drawn from a character set of size n with repetition allowed has n^k permutations, not C(n+k−1, k), because the order of characters matters for password strength. Lottery calculations usually involve ordinary combinations C(n, k) when each number can be drawn only once. Combinations with replacement apply to lotteries only if the same number can be drawn repeatedly and the ticket pays regardless of order, which is rare. The calculator is designed for multiset counting, not for ordered sequences or sampling without replacement. Users should verify that their problem matches the multiset assumptions—indistinguishable order, replacement allowed—before applying the result.
How do I verify the calculator result by hand?
For small values, enumerate all multisets explicitly. For n = 3 flavors and k = 2 items, the six multisets are {1,1}, {1,2}, {1,3}, {2,2}, {2,3}, {3,3}. For larger values, use the multiplicative formula step by step. To compute C(12, 5), write the product (12/1) × (11/2) × (10/3) × (9/4) × (8/5) and evaluate sequentially: 12/1 = 12; 12 × 11/2 = 66; 66 × 10/3 = 220; 220 × 9/4 = 495; 495 × 8/5 = 792. Each intermediate result is an integer, which provides a built-in check against arithmetic error. The calculator's output can be compared against this manual product. If the manual and calculator results agree, confidence in both is high; if they disagree, the stepwise manual calculation usually reveals the error source.

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

In this category

Embed

Quanta Pro

Paid features are coming later.

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