Inclusion-Exclusion Calculator
The inclusion-exclusion principle counts the size of a union of overlapping sets without double counting. This calculator handles two or three sets: enter the size of each set, the size of each pairwise overlap, and the size of the triple overlap, and it returns the size of the union. If you also provide the size of the whole universe, it reports how many elements belong to none of the sets. For two sets only, set the third set and any intersection involving it to zero, and the familiar two-set formula applies.
Inclusion-exclusion formula
|A union B union C| = |A| + |B| + |C|
- |A and B| - |A and C| - |B and C|
+ |A and B and C|
In none = universe size - |A union B union C|
For two sets, set C and all intersections with C to zero, giving |A| + |B| - |A and B|.
Set counting context
- Singles are added, pairwise overlaps subtracted, and the triple overlap added back.
- Each pairwise intersection should be at most the smaller of the two sets it joins.
- The triple intersection should be at most the smallest pairwise intersection.
- The universe-minus-union result counts elements outside all three sets.
- The principle generalises to any number of sets with alternating signs.
Inclusion-exclusion: frequently asked questions
What is the inclusion-exclusion principle?
It is a counting rule for the size of a union of sets. For three sets the union equals the sum of the individual sizes, minus the sum of the three pairwise intersections, plus the triple intersection. This corrects for elements counted more than once when sets overlap.
What is the formula for three sets?
The size of A union B union C equals |A| plus |B| plus |C|, minus |A and B|, minus |A and C|, minus |B and C|, plus |A and B and C|. The alternating signs add singles, subtract pairs, then add the triple overlap.
How do I use this for only two sets?
Set the third set size and all intersections involving C to zero. The union of A and B is then |A| plus |B| minus |A and B|, which is the two-set inclusion-exclusion formula and what the calculator returns.
Can the intersection counts be inconsistent?
Yes. If you enter intersections larger than the sets they belong to, the result will not correspond to any real collection of sets. The calculator does the arithmetic exactly as entered, so check that each pairwise intersection is at most the smaller of its two sets, and the triple is at most the smallest pairwise value.
What if I have a total universe size?
Enter the universe size to also see the count of elements in none of the three sets, which is the universe minus the union. This is useful for survey and probability problems where you want the complement of the union.
Official sources
- NIST Digital Library of Mathematical Functions: Combinatorial Analysis.
- U.S. National Institute of Standards and Technology: NIST home, mathematical references.
Reviewed by the CalculatorHub team, edited by James Graham, 17 June 2026. See our methodology.