Inclusion-Exclusion Calculator

In at least one set (|A union B union C|)210
In exactly one set135
In exactly two sets65
In at least two sets75
How this was calculated
  1. Inclusion-exclusion adds the single sets, subtracts the pairwise intersections and adds back the triple intersection, so nothing is double-counted.
  2. Union = 120 + 95 + 80 - 40 - 30 - 25 + 10 = 210.
  3. Exactly two sets: (40 - 10) + (30 - 10) + (25 - 10) = 65, and 75 are in at least two sets counting the 10 in all three.
  4. The remaining 135 are in exactly one set; the three groups 135 + 65 + 10 rebuild the union of 210.

This inclusion-exclusion calculator finds the size of the union of overlapping sets, so you can count each item once instead of double-counting the people or items that belong to more than one group. For three sets, it applies the formula A + B + C - AB - AC - BC + ABC. In a survey with sets of 120, 95 and 80, pairwise overlaps of 40, 30 and 25, and 10 in all three, the calculator returns a union of 210. It also breaks that 210 down by membership count: 135 people are in exactly one set, 65 in exactly two, and 10 in all three. Other worked cases include a club with sets of 45, 38 and 29 that has a union of 87, and a feature-usage example with sets of 200, 150 and 100 that has a union of 330 out of 450 total memberships.

The method is the accepted standard for this kind of calculation because simply adding set sizes overcounts the shared members. In the survey example, adding the three set sizes alone gives 295 memberships, but those collapse to a union of 210 once the overlaps are subtracted and the triple overlap is added back. Inclusion-exclusion corrects that overcount in a single, repeatable procedure. This page shows the formula, step-by-step workings, worked examples and sources, so you can follow each stage of the calculation and check the result yourself.

Worked examples

Survey sets

(120 · 95 · 80 · 40 · 30 · 25 · 10)

In at least one set (|A union B union C|)210
In exactly one set135
In exactly two sets65
In at least two sets75

Club sets

(45 · 38 · 29 · 12 · 9 · 7 · 3)

In at least one set (|A union B union C|)87
In exactly one set65
In exactly two sets19
In at least two sets22

Feature sets

(200 · 150 · 100 · 60 · 45 · 30 · 15)

In at least one set (|A union B union C|)330
In exactly one set225
In exactly two sets90
In at least two sets105

How inclusion-exclusion works for three sets

For three sets, inclusion-exclusion corrects the overcounting that happens when you simply add the set sizes together. The rule is: the union equals A + B + C minus AB minus AC minus BC, plus ABC. Each pairwise overlap (AB, AC, BC) was counted twice when you added the three set sizes, so you subtract each one once. The triple intersection (ABC) needs special handling, which is where the addition comes back in.

Work through the survey example to see the arithmetic. The three sets have 120, 95 and 80 members. The pairwise overlaps are 40, 30 and 25, and 10 people are in all three sets. Applying the formula: 120 + 95 + 80 - 40 - 30 - 25 + 10 = 210. So the union is 210 people. Notice that adding the three set sizes alone gives 295 memberships, but those 295 collapse to a 210 union once the overlaps are corrected. That gap of 85 is exactly the overcounting removed by the formula.

Why is the triple intersection added back? When the three set sizes are added, the 10 people in all three sets are counted three times. Subtracting the three pairwise overlaps takes each of those 10 people out three times as well, which leaves them counted zero times. Adding ABC once restores them to a count of one. That is the fix the final + ABC term provides, and it is why the sign pattern runs plus, minus, plus.

The same structure gives you a breakdown of the union. Of the 210 people in the survey, 135 are in exactly one set, 65 are in exactly two sets, and 10 are in all three. Those parts sum to 210, so the union can be read either as a single total or as a split by membership count. An inclusion exclusion calculator applies the formula directly, so you can enter set sizes and overlaps and get the union without tracking the signs by hand.

Other examples follow the identical pattern. A club with sets of 45, 38 and 29 has a union of 87, with 65 in exactly one set. A feature-usage example with sets of 200, 150 and 100 has a union of 330 out of 450 total memberships. In every case the pairwise overlaps are subtracted and the triple intersection is added back, which keeps the result accurate rather than inflated by double counting.

The sign pattern for three sets is plus, minus, plus: add the three set sizes, subtract the three pairwise overlaps, then add the triple intersection once.

Exactly one, exactly two, at least two

The union of 210 tells you how many people belong to at least one of the three sets, but it hides how those people are spread across the sets. Some belong to just one, some to two, and some to all three. Breaking the union into those layers is where an inclusion exclusion calculator earns its keep, because the pairwise overlaps in the data are not the same as the number of people in exactly two sets. Each pairwise overlap of 40, 30 or 25 includes the 10 people who sit in all three sets, so that 10 is counted inside each of those overlap figures.

To get the exactly-two count, remove the triple overlap from each pairwise figure and add the results: (40 - 10) + (30 - 10) + (25 - 10) = 30 + 20 + 15 = 65. So 65 people belong to exactly two of the sets. The at-least-two count adds the all-three group back on top: 65 + 10 = 75. The exactly-one count follows by subtraction from the union: 210 - 65 - 10 = 135. Check the arithmetic by rebuilding the union from its layers: 135 people in one set, 65 in two, and 10 in three give 135 + 65 + 10 = 210, which matches the union the formula produced.

The same layering applies to any three-set problem. In the club example, with sets of 45, 38 and 29, the union is 87 and 65 members fall in exactly one set. In the feature-usage example, sets of 200, 150 and 100 give a union of 330 out of 450 total memberships. In each case the raw set sizes overcount, because people in overlapping regions are counted once per set they belong to. In the survey, adding the three set sizes alone gives 295 memberships, and those 295 collapse to a 210 union once the overlaps are handled. The exactly-one, exactly-two and all-three figures are what let you say where the 210 people actually sit.

A quick sanity check is worth building into any calculation. The exactly-one count plus the exactly-two count plus the all-three count should equal the union, and the exactly-two count plus the all-three count should equal the at-least-two count. If either check fails, an overlap has probably been subtracted twice or the triple intersection has been left out. Running these checks after each inclusion exclusion calculation keeps the layered counts consistent with the union they are meant to explain.

  • Exactly two: (40 - 10) + (30 - 10) + (25 - 10) = 65
  • At least two: 65 + 10 = 75
  • Exactly one: 210 - 65 - 10 = 135
  • Check: 135 + 65 + 10 = 210, the union
The pairwise overlaps of 40, 30 and 25 each contain the 10 people in all three sets, so subtract that 10 before adding them to get the exactly-two count of 65.

Worked examples

The quickest way to see how an inclusion exclusion calculator works is to run three cases side by side. In each one, the union is A + B + C - AB - AC - BC + ABC, and the difference between a rough sum and the corrected answer shows why the subtraction and addition steps matter.

Start with the survey. The three sets hold 120, 95 and 80 people, the pairwise overlaps are 40, 30 and 25, and 10 people sit in all three sets. Adding the set sizes alone gives 295 memberships, but that total counts overlapping people more than once. Applying the formula brings 295 memberships down to a union of 210. The overlaps also break down cleanly: of those 210 people, 135 are in exactly one set, 65 are in exactly two, and 10 are in all three. That breakdown is a useful check, because the three groups should add back up to the union.

The club example is smaller but follows the same path. With sets of 45, 38 and 29, the union comes out to 87, and 65 members fall in exactly one set. The gap between the raw sum of the set sizes and 87 is the overcounting that the pairwise overlaps create, and the formula removes it.

Feature usage shows the same logic at a larger scale. Sets of 200, 150 and 100 produce a union of 330 out of 450 total memberships. Here the union is well below the 450 figure, which is what you would expect once shared memberships stop being counted twice or three times.

  • Survey: sets of 120, 95 and 80, overlaps of 40, 30 and 25, and 10 in all three give a union of 210. Of those 210, 135 are in exactly one set, 65 in exactly two and 10 in all three.
  • Clubs: sets of 45, 38 and 29 give a union of 87, with 65 in exactly one set.
  • Feature usage: sets of 200, 150 and 100 give a union of 330 out of 450 total memberships.
In the survey example, adding the three set sizes alone gives 295 memberships, but the corrected union is 210. The inclusion exclusion calculator exists to close that gap.

Where the principle is used

The inclusion-exclusion principle shows up wherever you need to count things that can fall into more than one category at once. An inclusion exclusion calculator does the bookkeeping for you, but the situations themselves are ordinary: survey respondents who tick several boxes, probability questions about events that can happen together, and databases that track overlapping audiences.

Survey deduplication is a classic case. Suppose three groups of respondents report using a product: 120, 95 and 80 people. Pairwise overlaps are 40, 30 and 25, and 10 people are in all three sets. Adding the three set sizes alone gives 295 memberships, which overcounts because the same people are counted more than once. For three sets, the union is A + B + C - AB - AC - BC + ABC, and here that works out to a union of 210. The breakdown is just as useful: of those 210 people, 135 are in exactly one set, 65 are in exactly two, and 10 are in all three. That tells you how much duplication sits behind a raw headcount. A smaller club example shows the same pattern: sets of 45, 38 and 29 produce a union of 87, with 65 in exactly one set.

In combinatorics, the same idea counts items that carry several overlapping properties. If you want to know how many objects have at least one of three attributes, you add the individual counts, subtract the pairwise overlaps, and add back the triple overlap. Probability uses the identical structure: the chance that at least one of several events occurs is the sum of their individual probabilities minus the pairwise intersections plus the triple intersection, and so on. The subtraction corrects for outcomes that would otherwise be counted twice, and the final addition corrects for the correction.

Database and audience overlap work is another natural fit. Marketing and analytics teams often hold several lists, such as members who used feature A, feature B or feature C. A feature-usage example with sets of 200, 150 and 100 produces a union of 330 out of 450 total memberships, so the audience is smaller than the raw sum suggests. Getting that number right matters for reach estimates, deduplicated contact counts and cost calculations.

The pattern extends to any number of sets. Start by adding the sizes of all sets, subtract every pairwise intersection, add every triple intersection, subtract every four-way intersection, and continue alternating signs until the intersection of all sets is reached. The signs alternate because each step corrects the overcount left by the previous one. Once you see that rhythm, you can apply the method to four, five or more categories without memorizing a separate formula for each.

The signs always alternate: add single sets, subtract pairs, add triples, subtract quadruples, and keep going until the final intersection.

FAQs

What is the inclusion-exclusion formula for three sets?

For three sets, the size of the union is A + B + C - AB - AC - BC + ABC. Add the three single-set counts, subtract the three pairwise overlaps, then add the triple intersection back once. In the survey example, this gives a union of 210.

Why is the triple intersection added back?

The triple intersection was added three times when you summed the singles and subtracted three times when you subtracted the pairs. That leaves it counted zero times, so it must be added once to be counted exactly once. In the survey example, that triple overlap is 10.

How many are in exactly two sets?

Subtract the triple overlap from each pairwise count, then sum those results. This removes people who are in all three sets, leaving only those in exactly two. In the survey example, that gives 65 people in exactly two sets.

How many are in at least one set?

That is the union itself. In the survey example, 210 respondents are in at least one set. In the club example, 87 people are in at least one club. The inclusion-exclusion formula computes this count directly by correcting for overlaps.

What goes wrong if I just add the set sizes?

Overlaps get counted repeatedly, so the total is too high. In the survey example, simply adding the set sizes gives 295 memberships, but those memberships belong to only 210 distinct people. Inclusion-exclusion corrects this by subtracting overlaps and adding the triple intersection back.

Does inclusion-exclusion work for more sets?

Yes. For more sets, you alternate subtracting and adding intersections of growing size: add singles, subtract pairs, add triples, and so on. The three-set case here is the largest most people need to work by hand.

Sources

Related calculators

Permutations Calculator
Permutations P(n, r), combinations C(n, r), permutations with repetition and n factorial, with large results in compact form.
Factorial Calculator
Exact factorials up to 170! computed with arbitrary-precision integers — no scientific-notation rounding — with the digit count and trailing zeros (Legendre's formula) explained.
Absolute Value Calculator
Absolute values and the distance between two numbers on the number line: |a|, |b| and |a - b|, with the sign-stripping logic spelled out.