Inclusion-Exclusion Principle Calculator

Calculate the union of sets using the Inclusion-Exclusion Principle — without double-counting overlapping elements. Enter the sizes of Set A, Set B, and optionally Set C, along with their intersections, and get back the union size and a full breakdown of how each term contributes to the formula.

Number of Sets *

Total number of elements in Set A

Total number of elements in Set B

Total number of elements in Set C (3-set mode only)

Elements in both Set A and Set B

Elements in both Set A and Set C (3-set mode only)

Elements in both Set B and Set C (3-set mode only)

Elements present in all three sets (3-set mode only)

Results

Union Size |A ∪ B| or |A ∪ B ∪ C|

--

Sum of Individual Sets

--

Pairwise Intersections Subtracted

--

Triple Intersection Added Back

--

Elements Only in A

--

Elements Only in B

--

Elements Only in C

--

Results Table

More Math Tools

Frequently Asked Questions

What is the Inclusion-Exclusion Principle?

The Inclusion-Exclusion Principle is a counting technique used to find the total number of elements in the union of multiple sets without double-counting elements that belong to more than one set. For two sets, the formula is |A ∪ B| = |A| + |B| − |A ∩ B|. For three sets, pairwise intersections are subtracted and the triple intersection is added back.

Why do we subtract intersections when calculating the union?

When you add |A| and |B| together, any element in both sets gets counted twice. Subtracting |A ∩ B| removes one of those duplicate counts, leaving each element counted exactly once. This is the core idea behind the principle: include all, then exclude the over-counted overlaps.

Why is the triple intersection added back in the three-set formula?

When you subtract all three pairwise intersections (A∩B, A∩C, B∩C), elements that belong to all three sets get removed too many times — they get subtracted three times but should only be subtracted twice. Adding |A ∩ B ∩ C| back corrects this imbalance, ensuring every element is counted exactly once.

Can the Inclusion-Exclusion Principle be applied to probabilities?

Yes. In probability, P(A ∪ B) = P(A) + P(B) − P(A ∩ B). The same logic extends to three or more events. Instead of set sizes you use probabilities, but the structure of the formula is identical. This is fundamental in combinatorics and probability theory.

What are common real-world applications of this principle?

The Inclusion-Exclusion Principle appears in many practical contexts: counting students enrolled in multiple courses, finding how many integers below N are divisible by given numbers, calculating the number of derangements (permutations with no fixed points), and solving scheduling or resource allocation problems where overlap must be tracked.

What happens if my intersection value is larger than one of the sets?

An intersection cannot be larger than either of the sets it overlaps. For example, |A ∩ B| must be ≤ |A| and ≤ |B|. If you enter an intersection larger than a set size, the result will be mathematically invalid. The calculator will flag such inputs and you should double-check your values.

Can this calculator handle more than three sets?

This calculator supports up to three sets. For four or more sets, the Inclusion-Exclusion formula continues to alternate between adding and subtracting intersections of increasing size, but the number of intersection terms grows exponentially (2ⁿ − 1 terms for n sets), making manual entry impractical for large n.

What is the difference between union and intersection?

The union (A ∪ B) contains every element that appears in at least one of the sets — it's the combined total without duplicates. The intersection (A ∩ B) contains only elements that appear in both sets simultaneously. The Inclusion-Exclusion Principle uses intersections to correctly compute union sizes.