Since 2010 · Powering 2M+ tool runs every month
Since 2010
Add to Chrome

My Toolbox

Automatic Mode

No saved tools yet.

Go Premium
Related tools
Venn Diagram Generator (3 Sets)Set Theory CalculatorDerangement (Subfactorial) CalculatorThermal Expansion CalculatorRugby Points Calculator
Home Page > Math > Advanced Math Operations

Inclusion-Exclusion Calculator

Compute the size of a union of up to five sets with the inclusion-exclusion principle. Enter raw elements or the cardinality of every intersection to get the signed expansion, a live Venn diagram and every disjoint region's size.

Free to useNo sign-up requiredInstant Results
Inclusion-Exclusion CalculatorTry it now — free ▼
Elements mode: one line per set, e.g. A: 1, 2, 3. The calculator detects every intersection automatically.
Cardinalities mode: one size per line, e.g. |A| = 50 and |A∩B| = 15. Any intersection you omit is treated as zero. Accepts A&B, AB, or |A∩B|.

Embed Inclusion-Exclusion Calculator Widget

About Inclusion-Exclusion Calculator

The Inclusion-Exclusion Calculator computes the size of a union of finite sets, |A1 ∪ A2 ∪ … ∪ An|, using the inclusion-exclusion principle — one of the most widely used identities in combinatorics and discrete probability. Enter raw set elements, or just the known cardinalities of each intersection, and the calculator returns the union size, the full signed expansion, the sizes of every disjoint Venn region, and a live diagram — for 2 to 5 sets at a time.

The Inclusion-Exclusion Principle

For two finite sets A and B, adding their sizes double-counts elements in both. Subtracting the intersection fixes the overcount:

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

For three sets, subtracting every pairwise intersection removes the triple-count twice, so we add the triple intersection back:

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

In general, for n sets the signs alternate with the size of the intersection being counted:

|A1 ∪ … ∪ An| = ΣS ≠ ∅ (−1)|S|+1 · |⋂i ∈ S Ai|

There are 2n − 1 non-empty subsets of {1, …, n}, so the formula has 3 terms for 2 sets, 7 for 3 sets, 15 for 4 sets, and 31 for 5 sets. The calculator evaluates each term individually and shows its sign so you can follow the derivation.

Two Input Modes

Pick the mode that matches the data you have. Most textbook problems give you cardinalities directly; programming tasks usually give you the sets themselves.

ModeWhen to useExample input
Elements You have the actual items of each set and want every intersection derived automatically. A: 1, 2, 3, 4
B: 3, 4, 5, 6
C: 4, 6, 7, 8
Cardinalities You know how many elements are in each set and each intersection but not the elements themselves. |A| = 50
|B| = 40
|A∩B| = 15

In Cardinalities mode any intersection you omit is assumed to be zero. Accepted separators for the intersection label include A∩B, A&B, and AB, with optional pipes around the expression (|A∩B|).

Disjoint Region Sizes — Möbius Inversion

Beyond the union size the calculator returns the size of every disjoint region of the Venn diagram. The region labelled "in A and B but not C" counts elements that belong to exactly those sets. The sizes of all disjoint regions sum to the union, giving an instant sanity check.

|region T| = ΣS ⊇ T (−1)|S|−|T| · |⋂i ∈ S Ai|

This is the Möbius-inversion dual of inclusion-exclusion. For example, with three sets:

|A only| = |A| − |A∩B| − |A∩C| + |A∩B∩C| |A ∩ B only| = |A∩B| − |A∩B∩C|

If you enter inconsistent cardinalities — for instance |A∩B| > |A| — the calculator rejects the input. If the individual sizes pass but the combined values still can't come from real sets, one or more regions will be negative, which is flagged as a warning.

Worked Example — 3-Set Classroom Survey

A class of 100 students is asked which sports they play. 50 play football (A), 40 basketball (B), 30 tennis (C). 15 play both A and B, 10 both A and C, 8 both B and C, and 3 play all three. How many play at least one sport?

|A ∪ B ∪ C| = 50 + 40 + 30 − 15 − 10 − 8 + 3 = 120 − 33 + 3 = 90

So 90 of 100 students play at least one of these sports; 10 play none. The region breakdown reveals more: 28 play only football, 20 only basketball, 15 only tennis, 12 play football and basketball but not tennis, and so on.

How to Use This Calculator

  1. Pick an input mode — Elements if you have the items, Cardinalities if you only have sizes.
  2. Enter your data in the text area, one line per set or one line per known cardinality.
  3. Choose the number of sets (2 to 5) in Cardinalities mode. In Elements mode the count is detected automatically.
  4. Click Calculate Union & Regions. The result shows |⋃ Aᵢ| in a hero card, the full inclusion-exclusion expansion with each signed term, a Venn-diagram SVG (for 2, 3, or 4 sets), and a table with every disjoint region and its size.
  5. Hover a Venn region or a table row to cross-highlight the matching entry — a quick visual proof that the table and the diagram represent the same decomposition.

Common Applications

Tips & Common Pitfalls

Frequently Asked Questions

What is the inclusion-exclusion principle?

The inclusion-exclusion principle is a counting identity that gives the size of a union of sets in terms of the sizes of the sets themselves and their intersections. For two sets it says |A ∪ B| = |A| + |B| − |A ∩ B|. For three sets a correction for the triple intersection is added back, and for n sets the signs alternate, adding single sets, subtracting pairs, adding triples, and so on.

What is the difference between Elements mode and Cardinalities mode?

Elements mode expects the actual elements of each set, one line per set, and the calculator finds every intersection automatically. Cardinalities mode expects only the sizes of the sets and their intersections and is ideal when solving word problems where you know how many people like tea, coffee, or both, without being given the actual names.

Why does my calculator show negative region sizes?

Negative region sizes in Cardinalities mode mean your inputs are inconsistent — no collection of real sets can have those intersection sizes. Usually this happens when the pairwise or triple intersection is larger than the individual sets can support. Recheck the numbers; every intersection must be smaller than or equal to each of the sets that contain it.

How many sets can this calculator handle?

The calculator supports 2 to 5 sets. The Venn diagram is rendered for 2, 3, and 4 sets; the region-breakdown table is shown for any number of sets including 5. For larger problems the inclusion-exclusion expansion becomes unwieldy, so most textbook problems top out at 4 or 5 sets.

What is a disjoint region?

A disjoint region is a piece of the Venn diagram that belongs to exactly one combination of sets and to no others. For three sets A, B, C there are seven non-empty regions: A-only, B-only, C-only, A∩B-only, A∩C-only, B∩C-only, and A∩B∩C. Their sizes sum to |A ∪ B ∪ C|, which is a fast way to double-check an inclusion-exclusion calculation.

Can I use the calculator with infinite or continuous sets?

The calculator is designed for finite sets whose sizes are non-negative integers. For probability or measure-theory problems with continuous sets you can still apply the inclusion-exclusion identity conceptually, but the numeric tool expects cardinalities you can type as whole numbers.

Further Reading

Reference this content, page, or tool as:

"Inclusion-Exclusion Calculator" at https://MiniWebtool.com/inclusion-exclusion-calculator/ from MiniWebtool, https://MiniWebtool.com/

by miniwebtool team. Updated: Apr 21, 2026

You can also try our AI Math Solver GPT to solve your math problems through natural language question and answer.

Advanced Math Operations:

Top & Updated:

Probability CalculatorGroup Theory Order CalculatorBoolean Algebra SimplifierView all →
Home Page > Math > Advanced Math Operations > Inclusion-Exclusion Calculator