Inclusion–exclusion for Two Sets Explained with Worked Examples

For two finite sets, : add the sizes, then subtract the overlap, which was counted twice.

Write 2x or 2*x to multiply, ^ for powers, and ; between simultaneous equations. You can also type factor, expand, derivative of, integrate … from a to b, limit … as x->0 or 15% of 80.

Try an example

Before you start

This page is easier if you are comfortable with:

What Inclusion–exclusion for two sets (Venn counting) means

If 30 students play football, 25 play tennis and 10 play both, then play at least one of the two; in a class of 50, play neither. Among the numbers 1 to 100, 25 are divisible by 4, 16 by 6, and 8 by both (that is, by 12), so are divisible by 4 or 6. The overlap is found with the lowest common multiple.

The same formula in probability is the union of two events, and the sets of a Venn diagram are described by overlapping sets and set identities. The extension to three sets adds back the triple overlap (inclusion–exclusion for three events).

The principle also counts the complement: the number with neither property is the total minus the union, as with the 5 students above. It leads to formulas for derangements and for Euler's totient via Möbius inversion.

What is it used for?

To count the union of two sets, add their sizes and remove the overlap once.

How to use inclusion–exclusion for two sets (venn counting)

  1. Find , and .
  2. Compute .
  3. For "neither" subtract from the total.
  4. Draw a Venn diagram to check.

Graph

Football 30, tennis 25, both 10: union 45football: 30tennis: 25both: 10either: 4500.511.522.533.544.5501020304050Football 30, tennis 25, both 10: union 45groupyGraph with x from 0 to 5 and y from 0 to 50. Shows bars (4); point football: 30 at (1, 30); point tennis: 25 at (2, 25); point both: 10 at (3, 10); point either: 45 at (4, 45).

The overlap of 10 is counted twice and then removed once.

Worked examples

These examples are worked by hand, step by step, so you can compare your own working.

Example 1: sports

Find the number who play football or tennis: 30, 25, both 10.

Worked example
Answer
4545
  1. Formula

Example 2: neither

In a class of 50, how many play neither?

Worked example
Answer
55
  1. Formula

Example 3: divisibility

How many integers from 1 to 100 are divisible by 4 or 6?

Worked example
Answer
3333
  1. Counts
  2. Union

Special cases

A few situations come up again and again. Knowing them saves time and helps you spot answers that cannot be right.

|A| = 30, |B| = 25, |A∩B| = 10

30 + 25 − 10

45.

Universe 60

neither = 60 − 45

15.

Multiples of 2 or 3 up to 100

50 + 33 − 16

67.

Check by regions

20 + 10 + 15

45.

Word problems

|A ∪ B| = |A| + |B| − |A ∩ B|: add the sizes then subtract the overlap, which was counted twice.

Union

Find |A ∪ B| for 30, 25 and overlap 10.

  1. 55 − 10
  2. Check: ✓45

Neither

In a universe of 60, how many are in neither set?

  1. 60 − 45
  2. Check: ✓15

Divisibility Higher

Count 1–100 divisible by 2 or 3: 50 + 33 − 16.

  1. ⌊100/2⌋50
  2. ⌊100/3⌋33
  3. ⌊100/6⌋16
  4. Check: ✓67

Regions Higher

Only A = 20, both = 10, only B = 15. Find the union.

  1. 20 + 10 + 15
  2. Check: ✓45

Common mistakes

Not subtracting

30 + 25 ✗

subtract the overlap ✓

Double counted.

Subtracting twice

− 2·10 ✗

− 10 ✓

Once.

Mutually exclusive assumed

overlap 0 ✗

use the actual overlap ✓

Check.

Complement mix-up

union as neither ✗

universe − union ✓

Be careful.

Exam tips

  1. |A| + |B| − |A∩B|.
  2. Draw a Venn diagram.
  3. Neither = universe − union.
  4. Divisibility: lcm for the overlap.
  5. Check with regions.

Practice questions

Try each one on paper, then open the answer. Use the solver above to see the full working.

1. 40 + 35 − 12 Foundation

63

2. Neither in universe 100, union 75 Foundation

25

3. Multiples of 3 or 5 up to 50 Foundation

23

4. Multiples of 4 or 6 up to 60 Higher

20

5. |A ∩ B| from 50, 40, union 70 Higher

20

6. Multiples of 2 or 5 up to 100 Higher

60

Practice generator

Unlimited fresh questions with instant marking. Choose a level, work it out on paper, then type your answer.

Solve: …

Key terms

Inclusion–exclusion
Union size formula.
Union
A ∪ B.
Intersection
A ∩ B.
Venn diagram
Picture of sets.
Complement
Outside the sets.
Lowest common multiple
Overlap of multiples.

Frequently asked questions

What is inclusion–exclusion for two sets?

|A ∪ B| = |A| + |B| − |A ∩ B|.

Why subtract the overlap?

It was counted twice.

How do I count “neither”?

Universe minus the union.

How do I handle divisibility?

Use the lcm for the intersection.

Which page covers three events?

inclusion–exclusion for events.

Which page covers derangements?

derangements.

More in Discrete maths and number theory and the formula sheets.