How the two-set Venn diagram calculator works
A Venn diagram of two sets is drawn as two overlapping circles. Circle A holds every element of set A, circle B holds every element of set B, and the lens where they overlap holds the elements that belong to both. This calculator takes the size of set A, the size of set B, and the size of their overlap, then works out the four quantities people usually want: the union, the "only A" region, the "only B" region, and the intersection itself.
The inclusion–exclusion formula
The core identity is the two-set inclusion–exclusion principle:
|A ∪ B| = |A| + |B| − |A ∩ B|
The union (elements in A or B or both) is not simply |A| + |B|, because the elements sitting in the overlap would be counted once in |A| and again in |B|. Subtracting the intersection |A ∩ B| removes that double count. From the same three inputs the individual regions follow directly:
- Only A (in A but not B) = |A| − |A ∩ B|
- Only B (in B but not A) = |B| − |A ∩ B|
- Both (the overlap) = |A ∩ B|, the value you entered
These three disjoint regions always add back up to the union: (|A| − |A ∩ B|) + |A ∩ B| + (|B| − |A ∩ B|) = |A| + |B| − |A ∩ B|.
A worked example
Suppose 30 students take Chemistry (set A) and 25 take Physics (set B), and 10 of them take both. The union is 30 + 25 − 10 = 45 students taking at least one of the two subjects. Only Chemistry is 30 − 10 = 20, only Physics is 25 − 10 = 15, and the overlap is 10. Check: 20 + 10 + 15 = 45, which matches the union.
Why the overlap can never exceed either set
Every element in the overlap belongs to both A and B, so the overlap is a subset of each circle. That means |A ∩ B| ≤ |A| and |A ∩ B| ≤ |B| at the same time — the intersection can be at most the size of the smaller set. If someone tells you 30 people like tea, 25 like coffee, and 40 like both, the numbers are inconsistent: "both" cannot outnumber either single group. The calculator rejects that case rather than returning a negative "only A" region.
Common reference points
- Disjoint (mutually exclusive) sets: overlap = 0, so the union is simply |A| + |B| and the circles touch at most at an edge.
- One set inside the other: if |A ∩ B| = |A|, then set A is entirely contained in B, "only A" = 0, and the union equals |B|.
- Identical sets: if |A| = |B| = |A ∩ B|, both circles coincide and the union equals either set.