The twelvefold way is a classification of twelve elementary counting problems involving the distribution of
balls into
boxes. The balls may be distinguishable
or indistinguishable, the boxes may
likewise be distinguishable or indistinguishable, and the occupancy of the boxes
may be unrestricted, at most one ball per box, or at least one ball per box.
According to Stanley (1999, p. 41), the idea of the twelvefold way is due to G.-C. Rota's lectures, and the terminology to Joel Spencer.
With
denoting a Stirling number of the second
kind,
a falling factorial,
the number of partitions
of
into at most
parts, and
the number of partitions of
into exactly
parts, the twelve cases are as follows. In the "at most
one" column, the entries are understood to be 0 when
.
| Balls and boxes | Unrestricted | At most one | At least one |
| distinct balls, distinct boxes | |||
| identical balls, distinct boxes | |||
| distinct balls, identical boxes | |||
| identical balls, identical boxes |
The
unrestricted assignments of distinct balls to distinct boxes form the sample
space for the classical occupancy problem
when the box choices are independent
and identically distributed according to the discrete
uniform distribution. This is the basic probabilistic case of the broader occupancy problem.
For example, distributing distinct balls among an unrestricted number of identical boxes
gives the Bell number
. Distributing them among exactly
nonempty identical boxes gives
. The same classification also occurs
in physical counting problems when balls and boxes are interpreted as particles and
available states, respectively (Akhanjee 2026).