Inclusion-Exclusion Calculator
Compute the size of a union of up to 5 sets using the inclusion–exclusion principle. Enter raw elements or cardinalities of every intersection — get the signed expansion, a live Venn-diagram visualization, and the size of every disjoint region.
Your ad blocker is preventing us from showing ads
MiniWebtool is free because of ads. If this tool helped you, please support us by going Premium (ad‑free + faster tools), or allowlist MiniWebtool.com and reload.
- Allow ads for MiniWebtool.com, then reload
- Or upgrade to Premium (ad‑free)
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:
For three sets, subtracting every pairwise intersection removes the triple-count twice, so we add the triple intersection back:
In general, for n sets the signs alternate with the size of the intersection being counted:
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.
| Mode | When to use | Example input |
|---|---|---|
| Elements | You have the actual items of each set and want every intersection derived automatically. | A: 1, 2, 3, 4B: 3, 4, 5, 6C: 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.
This is the Möbius-inversion dual of inclusion-exclusion. For example, with three sets:
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?
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
- Pick an input mode — Elements if you have the items, Cardinalities if you only have sizes.
- Enter your data in the text area, one line per set or one line per known cardinality.
- Choose the number of sets (2 to 5) in Cardinalities mode. In Elements mode the count is detected automatically.
- 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.
- 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
- Combinatorics — counting derangements, surjections, permutations with forbidden positions.
- Probability — P(A ∪ B ∪ C) for events, Boole's inequality, the birthday paradox.
- Number theory — counting integers coprime to a product via Euler's totient: the φ-formula is pure inclusion-exclusion.
- Survey analysis — "how many respondents belong to at least one category" questions.
- Database queries — estimating the size of
UNIONs fromCOUNTs ofINTERSECTs. - Computer science — sieve algorithms, bitmap index cardinality estimation, GDPR/HIPAA reach counting.
Tips & Common Pitfalls
- Don't forget to add back the triple intersection. The most common student mistake in 3-set problems is stopping after subtracting pairs, producing an answer that is too small.
- Missing ≠ zero when real sets are involved. In Cardinalities mode an omitted intersection is treated as zero. If your problem doesn't say an intersection is empty, you probably need to include it.
- Every intersection ≤ every containing set. |A ∩ B| can never exceed min(|A|, |B|). The calculator rejects impossible inputs immediately.
- Use Elements mode when you can. It removes the entire class of "did I enter every intersection correctly" errors by deriving the intersections from the sets themselves.
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
- Inclusion-exclusion principle — Wikipedia
- Venn diagram — Wikipedia
- Möbius inversion formula — Wikipedia
- Derangements (a classical IE application) — Wikipedia
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.
Related MiniWebtools:
Advanced Math Operations:
- Antilog Calculator
- Beta Function Calculator
- Binomial Coefficient Calculator
- Binomial Probability Distribution Calculator
- Bitwise Calculator Featured
- Central Limit Theorem Calculator
- Combination Calculator
- Complementary Error Function Calculator
- Complex Number Calculator
- Entropy Calculator
- Error Function Calculator
- Exponential Decay Calculator Featured
- Exponential Growth Calculator
- Exponential Integral Calculator
- Exponents Calculator
- Factorial Calculator
- Gamma Function Calculator
- Golden Ratio Calculator
- Half Life Calculator
- Percent Growth Rate Calculator Featured
- Permutation Calculator
- Poisson Distribution Calculator
- Polynomial Roots Calculator
- Probability Calculator
- Probability Distribution Calculator
- Proportion Calculator
- Quadratic Formula Calculator
- Scientific Calculator
- Scientific Notation Calculator
- Significant Figures Calculator New
- Sum of Cubes Calculator
- Sum of Positive Integers Calculator Featured
- Sum of Squares Calculator
- Truth Table Generator New
- Set Theory Calculator New
- Venn Diagram Generator (3 Sets) New
- Chinese Remainder Theorem Calculator New
- Euler's Totient Function Calculator New
- Extended Euclidean Algorithm Calculator New
- Modular Multiplicative Inverse Calculator New
- Continued Fraction Calculator New
- Dijkstra's Shortest Path Calculator New
- Minimum Spanning Tree Calculator New
- Graph Degree Sequence Validator New
- Derangement (Subfactorial) Calculator New
- Stirling Numbers Calculator New
- Pigeonhole Principle Calculator New
- Markov Chain Steady State Calculator New
- Rounding Calculator New
- Negative Binomial Distribution Calculator New
- Permutations with Repetition Calculator New
- Modular Exponentiation Calculator New
- Primitive Root Calculator New
- Boolean Algebra Simplifier New
- Karnaugh Map (K-Map) Solver New
- Graph Coloring Calculator New
- Topological Sort Calculator New
- Adjacency Matrix Calculator New
- Inclusion-Exclusion Calculator New
- Linear Programming Solver New
- Traveling Salesman Solver (TSP) New
- Hamiltonian Path Checker New