The twelvefold way is a classification of twelve elementary counting problems involving the distribution of balls into
boxes. The balls may be distinct or identical, the boxes may
be distinct or identical, 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 |
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).