Understanding the Venn diagram calculator — concept and principle
This calculator fills in every region of a two- or three-set Venn diagram from the totals and overlaps you know, using the inclusion–exclusion principle. It gives the union, each "only" region, each pairwise region without the third set, the triple overlap, the counts in exactly one and exactly two sets, the number outside all sets and the probability of the union. Use it for survey problems, probability, statistics and logic puzzles.
How it is calculated
Two sets: n(A ∪ B) = n(A) + n(B) − n(A ∩ B); only A = n(A) − n(A ∩ B).
Three sets:
- n(A ∪ B ∪ C) = n(A) + n(B) + n(C) − n(A ∩ B) − n(A ∩ C) − n(B ∩ C) + n(A ∩ B ∩ C).
- Pairwise region without the third = pairwise intersection − triple.
- Only A = n(A) − n(A ∩ B) − n(A ∩ C) + n(A ∩ B ∩ C).
- Outside all sets = U − union. Region ÷ U = probability.
If any region comes out negative, the counts cannot happen together.
The principle
Adding the three set sizes counts elements in two sets twice and elements in all three sets three times. Subtracting the three pairwise overlaps fixes the double-counting but removes the triple region three times, leaving it uncounted, so it is added back once. This alternating add-subtract pattern is the inclusion–exclusion principle, and it extends to any number of sets. Working from the centre outward (triple first, then pairs, then singles) fills a Venn diagram without errors.
Worked example
Default inputs: U = 100, n(A) = 45, n(B) = 38, n(C) = 30, n(A ∩ B) = 15, n(A ∩ C) = 10, n(B ∩ C) = 8, n(A ∩ B ∩ C) = 4.
- Union = 45 + 38 + 30 − 15 − 10 − 8 + 4 = 84.
- Pairs without the third: A and B only 11, A and C only 6, B and C only 4. All three: 4.
- Only A = 45 − 15 − 10 + 4 = 24; only B = 19; only C = 16.
- Exactly one = 24 + 19 + 16 = 59; exactly two = 11 + 6 + 4 = 21.
- Outside all sets = 100 − 84 = 16; probability of the union = 0.84.
| n(A ∩ B ∩ C) (three sets only) | Union (in at least one set) |
|---|---|
| 1 | 81 |
| 2 | 82 |
| 3 | 83 |
| 4 | 84 |
| 5 | 85 |
| 6 | 86 |
| 8 | 88 |
How to read the result
The regions add up to the union: 59 + 21 + 4 = 84. "Only" regions answer questions like "how many like only tea?". The outside region is everyone in U who is in none of the sets. A negative region is a sign that the input data are inconsistent or contain a typing error.
Common mistakes
- Forgetting to add back the triple intersection.
- Reading n(A ∩ B) as "A and B only"; it includes those in C as well.
- Starting from the outside regions instead of the centre.
- Leaving U at 0 and then expecting an outside count.
Frequently asked questions
What is the inclusion–exclusion principle?
A rule for counting a union: add the sizes, subtract the pairwise overlaps, add back the triple overlaps, and so on.
How do I find "only A" with three sets?
n(A) − n(A ∩ B) − n(A ∩ C) + n(A ∩ B ∩ C).
Why might I get a negative region?
The numbers entered are inconsistent; for example, an intersection larger than one of its sets.
Sources: Inclusion–exclusion principle for finite sets (e.g. OpenStax, Contemporary Mathematics (2023), §1.4–1.5)