A student works through math notes on graph paper while organizing a counting problem.

How Inclusion-Exclusion Counts Overlapping Groups

Inclusion-exclusion fixes double counting by adding groups, subtracting overlaps, and correcting what was removed too many times.

Counting sounds simple until the groups overlap. A student can play soccer and run track. A number can be divisible by 2 and by 3. A survey response can belong to more than one category at the same time. If each group is counted separately and the totals are simply added, the shared items sneak into the answer more than once.

The inclusion-exclusion principle is the counting tool that fixes that problem. It begins with an ordinary idea: include the groups you want to count. Then it asks a careful follow-up question: what got counted too many times? The answer is usually an overlap. Subtract the overlap, and the count becomes fair again. For two groups, that is the whole story. For three or more groups, the same idea continues, but the corrections need one more layer.

Why ordinary addition overcounts

Suppose a class survey asks which students are taking art, music, or both. Twenty students take art, 15 take music, and 6 take both. Adding 20 and 15 gives 35, but that cannot be the number of students taking at least one of the two classes. The 6 students who take both classes were included once in the art count and once in the music count.

Those 6 students are not wrong to appear in both lists. The mistake is treating two lists as if they were completely separate. To count students who take art or music, include both groups, then subtract the shared group once:

20 + 15 – 6 = 29

So 29 students take art, music, or both. The subtraction does not remove those students from the final answer. It removes the extra copy of them. Each student who takes both classes still counts once, which is exactly what the word or usually means in counting problems: one group, the other group, or both.

A student organizes a counting problem on a whiteboard, similar to sorting overlapping groups.

The two-group formula

Mathematicians often write the two-group version with sets. If A and B are two finite sets, then the number of items in A or B is

|A union B| = |A| + |B| – |A intersection B|

The vertical bars mean the number of items in a set. The union means everything in A, B, or both. The intersection means the overlap: items that belong to A and B at the same time. The formula is not meant to make the idea harder. It is just a compact way to say, add the two groups, then subtract the part counted twice.

A Venn diagram makes the formula feel less mysterious. The left circle is A, the right circle is B, and the middle region is the overlap. When you count A, the middle region is included. When you count B, the middle region is included again. Subtracting the middle once leaves every region counted exactly one time.

This is why inclusion-exclusion is useful beyond math class. It appears whenever categories can overlap: students in clubs, customers who bought several products, survey respondents with more than one answer, website visitors using more than one device, or numbers that meet several divisibility rules. The setting changes, but the mistake is the same: treating overlapping groups as if they were separate.

A number example with divisibility

Consider the numbers from 1 through 30. How many are divisible by 2 or by 3? There are 15 numbers divisible by 2, because every second number qualifies. There are 10 numbers divisible by 3. If those are added, the result is 25, but some numbers have been counted twice.

The overlap is the set of numbers divisible by both 2 and 3. That means numbers divisible by 6: 6, 12, 18, 24, and 30. There are 5 of them. Inclusion-exclusion gives

15 + 10 – 5 = 20

So 20 numbers from 1 through 30 are divisible by 2 or by 3. A quick check confirms the logic: the numbers that do not qualify are 1, 5, 7, 11, 13, 17, 19, 23, 25, and 29. Ten numbers are left out, so 20 are included.

The check is more than a nice extra step. It shows a second counting strategy: sometimes it is easier to count what is not included and subtract from the total. This complement approach often works well with inclusion-exclusion, especially when a problem asks for numbers that avoid several conditions.

A calculator and math textbook used while checking a counting problem with overlapping cases.

What changes with three groups

Three overlapping groups need more care. Imagine a school counts students who take art, music, or drama. Adding the three class totals includes every student in at least one class, but students in two classes are counted twice. Students in all three classes are counted three times.

The natural next step is to subtract the pairwise overlaps: art and music, art and drama, music and drama. That fixes the students who are in exactly two groups. But a student in all three groups sits inside every pairwise overlap. After adding the three class totals, that student was counted three times. Then the three pairwise overlap subtractions remove that same student three times. The student has now been counted zero times, which is too few.

That is why the three-group formula adds the triple overlap back:

|A union B union C| = |A| + |B| + |C| – |A intersection B| – |A intersection C| – |B intersection C| + |A intersection B intersection C|

The plus sign at the end is the part students often forget. Inclusion-exclusion alternates because each round corrects the correction before it. First include the single groups. Then exclude the pair overlaps. Then include the triple overlap again. For four groups, the pattern continues: add singles, subtract pairs, add triples, subtract four-way overlaps.

That alternating pattern is easier to trust when you focus on one item at a time. If an item belongs to only one group, it is counted once and never touched by an overlap correction. If it belongs to two groups, it is counted twice and then subtracted once. If it belongs to three groups, it is counted three times, subtracted three times, and added once. In every case, the final goal is the same: count each qualifying item exactly once.

How inclusion-exclusion connects to probability

Probability uses the same structure because probability is often counting in disguise. If one card is drawn from a deck, the chance of drawing a heart or a face card cannot be found by blindly adding the chance of a heart to the chance of a face card. The jack, queen, and king of hearts are both hearts and face cards, so they would be counted twice.

The probability version subtracts the overlap just as the set-counting version does:

P(A or B) = P(A) + P(B) – P(A and B)

OpenStax describes this as an extension of the addition rule for cases where events are not mutually exclusive. That phrase, not mutually exclusive, simply means the events can happen together. If two events cannot happen together, there is no overlap to subtract. If they can happen together, the overlap matters.

This connection helps explain why inclusion-exclusion appears in statistics and data interpretation. Poll results, medical symptoms, course enrollments, and consumer choices can all involve overlapping categories. Without an overlap correction, a chart can make a total look larger than the actual group being measured.

Common mistakes to avoid

The most common mistake is subtracting the wrong overlap. In the art-and-music example, the overlap is not the students who take neither class. It is the students who take both. The overlap must belong to both groups being corrected.

Another mistake is assuming the word or always means one but not the other. In everyday speech, people sometimes use or that way. In many math and data problems, or usually means at least one. A student who takes art and music is part of the group taking art or music. If a problem means exactly one, it should say so, and the counting changes.

A third mistake is forgetting to add the triple overlap back in three-group problems. Pairwise subtractions are necessary, but they overcorrect the part shared by all three groups. Whenever three circles overlap in the center, that center region deserves special attention.

The cleanest habit is to label what each number counts before using it. Does it count one group? A pairwise overlap? A triple overlap? The total outside all the groups? Once the numbers are labeled, the formula becomes less like a rule to memorize and more like a bookkeeping system.

Inclusion-exclusion is powerful because it respects the messiness of real categories. It does not pretend groups are separate when they are not. It lets a count include every relevant item, correct the duplicates, and arrive at a total that matches the actual situation. That is the heart of good counting: not just adding numbers, but knowing what each number has already counted.

Have any questions or need more information on the topics covered? Get quick answers, further details, or clarifications by chatting with our AI assistant, Novo, at the bottom right corner of the page.

Akshay Dinesh

As a student, I am dedicated to writing articles that educate and inspire others. My interests span a wide range of topics, and I strive to provide valuable insights through my work. If you have any questions or would like to reach out, feel free to contact me at akshay[at]novolearner.com

Add comment

πŸ“˜ Free Tutoring – By Students, For Students

πŸŽ“ Get completely free, personalized tutoring from high school and college students who understand what it’s like to be a learner today.

Just tell us your grade and subject(s) - we’ll follow up within 24 hours with your class info.

πŸ‘‰ Book your free class here

Like what we do?

Consider donating to us. Running a free educational website has its costs. We never charge our users a fee to access our content. However, we still have to foot our bills. Please help us do more. Any amount is appreciated.

Your Support Matters

We noticed you're using an ad blocker. Our website depends on ad revenue to keep our content free and accessible to everyone. Please consider disabling your ad blocker to support us and help us continue providing valuable content.

Advertisement

Advertisement

Advertisement

Advertisement

Advertisement

Advertisement