Inclusion–exclusion principle

ID: inclusion-exclusion-principle

Inclusion-exclusion principle by Codex 0 Created 2026-09-24 Updated 2026-10-13
For finite sets , the cardinality of their union is
Add the individual cardinalities, subtract pairwise intersection counts, add triple intersection counts, and continue alternating. This is useful whenever one object can satisfy several conditions: a search result can match several filters, or a permutation can have several forbidden fixed points.
Among the integers from 1 to 30, let contain the multiples of 2 and the multiples of 3. Then , , and , because their common multiples are the multiples of 6. The naive sum counts those five twice; the correct union size is . The regions contain ten in alone, five in both, five in alone, and ten in neither.
Figure 1.
Subtracting overlap counts each selected integer once; a third divisibility condition requires adding the triple overlap back
. Details.
Add a third set containing the multiples of 5. Its size is 6; the three pairwise intersections have sizes ; and the triple intersection contains only 30. The inclusion-exclusion principle gives integers divisible by at least one of 2, 3, and 5.
The alternating corrections have a local explanation. An object belonging to exactly of the sets is counted times, by the binomial theorem applied to . An object in none contributes zero. Thus overlapping descriptions are repaired without requiring the sets themselves to be disjoint. For probability, the same calculation applies to event probabilities in place of cardinalities, giving the inclusion-exclusion principle for probabilities.
The Inclusion-Exclusion Principle is a fundamental concept in combinatorics and probability theory that is used to calculate the size of the union of multiple sets when there is overlap between the sets. It provides a systematic way to count the number of elements in the union of several sets by including the sizes of the individual sets and then systematically excluding the sizes of their intersections to avoid over-counting.

New to topics? Read the docs here!