Union and Intersection Calculator
Test cases replayed : 3 of 3 match · Methodology · No outside source listed
Enter the sizes of two sets and of their intersection (or their probabilities, with a universe of 1) to get the union and every region of the Venn diagram.
Result
Union n(A ∪ B) = n(A) + n(B) − n(A ∩ B)
Only A, n(A − B)
- Only B, n(B − A)
- Symmetric difference n(A △ B)
- Neither A nor B, n(U) − n(A ∪ B)
Estimate for planning only, not tax, legal, financial or medical advice. This calculator uses the method explained on this page.
This browser did not allow copying. The sentence is in the box below, already selected: copy it with your keyboard or the menu.
How to use this calculator
Fill in the fields in this order; each step takes you to its field.
- Size of set A, n(A): enter 0 or more.
- Size of set B, n(B): enter 0 or more.
- Size of the intersection, n(A ∩ B): enter 0 or more.
- Size of the universal set U (0 if unknown; 1 for probabilities): enter 0 or more.
- Read the result: Union n(A ∪ B) = n(A) + n(B) − n(A ∩ B); the panel also shows Only A, n(A − B), Only B, n(B − A), Symmetric difference n(A △ B) and Neither A nor B, n(U) − n(A ∪ B).
How this calculator works
The inclusion–exclusion principle for two finite sets: n(A ∪ B) = n(A) + n(B) − n(A ∩ B). The intersection is subtracted once because its elements are counted in both n(A) and n(B).
The other regions follow: only A = n(A) − n(A ∩ B), only B = n(B) − n(A ∩ B), symmetric difference = n(A) + n(B) − 2n(A ∩ B), and neither = n(U) − n(A ∪ B). The same rule holds for probabilities: P(A or B) = P(A) + P(B) − P(A and B).
The formula
| Symbol | Meaning |
|---|---|
| Size of set A, n(A) | |
| Size of set B, n(B) | |
| Size of the intersection, n(A ∩ B) | |
| Union n(A ∪ B) = n(A) + n(B) − n(A ∩ B) | |
min(a, b, …) | the smallest of the values. |
Worked example
| Size of set A, n(A) | 20 |
|---|---|
| Size of set B, n(B) | 15 |
| Size of the intersection, n(A ∩ B) | 5 |
| Size of the universal set U (0 if unknown; 1 for probabilities) | 50 |
| Only A, n(A − B) | 15 |
|---|---|
| Only B, n(B − A) | 10 |
| Symmetric difference n(A △ B) | 25 |
| Neither A nor B, n(U) − n(A ∪ B) | 20 |
Union n(A ∪ B) = n(A) + n(B) − n(A ∩ B) 30
Each step uses the unrounded value of the step before it; figures on this page are rounded for display.
Frequently asked questions
A class has 20 students in chess and 15 in band, 5 in both. How many are in at least one?
20 + 15 − 5 = 30. In a class of 50, the other 20 are in neither.
Does this work for probabilities?
Yes. With P(A) = 0.5, P(B) = 0.4 and P(A and B) = 0.2, P(A or B) = 0.7 and P(neither) = 0.3.