Inclusion–exclusion: counting overlaps correctly
The inclusion–exclusion principle is a core idea in combinatorics and probability.
It answers a common problem: you want the size of a union \(A\cup B\cup C\cdots\), but the sets overlap.
If you simply add the sizes \(|A|+|B|+|C|\), you will overcount elements that lie in intersections.
Inclusion–exclusion fixes this by adding and subtracting overlaps in an alternating way.
Two sets: add, then subtract the overlap
For two sets, the rule is:
\[
|A\cup B| = |A| + |B| - |A\cap B|.
\]
The reasoning is simple: when you add \(|A|+|B|\), every element in \(A\cap B\) has been counted twice (once in \(A\) and once in \(B\)).
Subtracting \(|A\cap B|\) removes the extra copy, leaving each element counted exactly once.
In probability form, the same structure holds:
\[
P(A\cup B) = P(A) + P(B) - P(A\cap B).
\]
Three sets: correct the correction
For three sets, you add all singles, subtract all pairwise intersections, and then add the triple intersection:
\[
|A\cup B\cup C|
= |A|+|B|+|C|
- |A\cap B| - |A\cap C| - |B\cap C|
+ |A\cap B\cap C|.
\]
Why does the triple term appear? When you subtract the pairwise overlaps, any element in the triple intersection \(A\cap B\cap C\)
gets subtracted too many times: it was counted in all three singles (+3), then removed in each pairwise intersection (−3),
so it would become 0 unless you add it back once (+1).
This “add, subtract, add” pattern continues for more sets.
Four sets and the alternating pattern
For four sets \(A,B,C,D\), inclusion–exclusion uses all intersections:
add 1-way terms, subtract 2-way terms, add 3-way terms, subtract the 4-way term.
In general, every intersection of size \(m\) appears with sign \(({-}1)^{m+1}\).
The main practical message is: each correction step may create a new overcorrection for deeper overlaps,
so the formula alternates until you reach the deepest intersection you are tracking.
How to use this tool
Choose Counts mode if you are working with set sizes like \(|A|\) and \(|A\cap B|\), or choose
Probability mode if your inputs are probabilities such as \(P(A)\) and \(P(A\cap B)\).
Select 2–4 sets, then enter the required singles and intersections. If an intersection is known to be impossible,
you can leave it blank and the tool treats it as 0.
After you click Calculate, the result is shown with a step-by-step formula so you can see exactly which terms were added or subtracted.
The interactive diagram is a schematic Venn-style picture (not to scale) that helps you visualize overlap and overcount.
Press Play to highlight terms in sequence (+ singles, − pairwise, + triple, …), reinforcing the logic of “correcting overcount.”
As an advanced note, inclusion–exclusion can be extended to larger finite collections and even to infinite families under additional conditions.
In those settings, convergence and measure-theoretic ideas become important, but the intuition remains the same:
overlaps cause overcount, and alternating corrections keep track of how many times each element has been counted.