How this calculation works
If each box must receive at least one item, assign those items first and use the remaining items in the nonnegative allocation.
C(items + boxes − 1, boxes − 1)A worked example
Seven items into four labeled boxes yield C(10,3) = 120 allocations.
Good to know
Empty boxes are allowed.
Reference: NIST DLMF, Functions of Number Theory (opens in a new tab) ↗
Represent allocations with stars and separators
Distributing seven identical items among four labelled boxes can be represented by seven stars and three bars. The string with groups of sizes 2, 0, 3 and 2 uses adjacent bars for the empty second box. Reading from left to right recovers the allocation uniquely.
Every allocation corresponds to a length-ten string formed from seven identical stars and three identical bars. Choose the three bar positions in C(10,3) = 120 ways. This is the formula C(items + boxes − 1, boxes − 1). Bars may appear at the beginning or end, allowing the first or last box to be empty.
Check whether empty boxes and labels are allowed
The boxes are distinguishable. Sending all seven items to box A differs from sending them all to box B. If the boxes were unlabelled, this calculation would overcount. The Integer partition count calculator describes a related setting in which the order of positive parts is ignored.
If every box must contain at least one item, first reserve one item per box. Seven items across four nonempty boxes leave three items to distribute freely, giving C(6,3) = 20. This differs from the default 120 because the default allows zeros. Distinct items would require a different model as well, since the identities of the assigned items would matter.
A few questions, answered
What happens with zero items?
There is one allocation: every box receives zero. This remains true for any accepted positive number of boxes.
Can there be more boxes than items?
Yes. Empty boxes are permitted, so the allocation remains valid.