Math calculator

Union and Intersection Calculator

Six operations at once — with the identities computed on your own sets rather than printed from a table.

Set operations

Six at once, with the identities checked rather than quoted.

A = {1, 2, 3, 4}, B = {3, 4, 5, 6}

A ∪ B = {1, 2, 3, 4, 5, 6}

A ∩ B = {3, 4}

Every operation

Each set operation with its result and meaning
OperationResultSizeMeaning
A ∪ B{1, 2, 3, 4, 5, 6}6everything that is in A, in B, or in both
A ∩ B{3, 4}2everything that is in A and in B at the same time
A − B{1, 2}2in A but not in B
B − A{5, 6}2in B but not in A — the other way round, and usually a different set
A △ B{1, 2, 5, 6}4in exactly one of the two: the union with the overlap removed
A′{5, 6, 7, 8}4everything in the universe that is not in A
B′{1, 2, 7, 8}4everything in the universe that is not in B

Venn regions

A only: 1, 2B only: 5, 6A ∩ B: 3, 4Outside every set: 7, 8

The regions hold 8 elements between them and the universe has 8 they partition it exactly, which is the property a Venn diagram has to have.

Inclusion–exclusion, with your numbers in it

|A ∪ B| = |A| + |B| − |A ∩ B| = 4 + 4 − 2 = 6 (left side counted from the union itself: 6)

De Morgan, verified on these sets

(A ∪ B)′ = A′ ∩ B′{7, 8} versus {7, 8}

(A ∩ B)′ = A′ ∪ B′{1, 2, 5, 6, 7, 8} versus {5, 6, 7, 8, 1, 2}

A − B and B − A are different sets here — {1, 2} against {5, 6}. Set difference is not symmetric, unlike union and intersection.

Both identities above are evaluated on your sets and compared, not printed from a table. If either ever disagreed the arithmetic would be visibly wrong here rather than silently right in the code.

What this tool shows

Six operations, the Venn regions, and two identities computed on your own sets rather than printed from a table.

  • Union, intersection, both differences, symmetric difference and complements
  • Venn regions computed from the same sets that produce the lists
  • Inclusion–exclusion with the actual counts substituted and checked
  • De Morgan verified on your sets rather than stated
Six operations at once Identities computed, not quoted Venn regions from the same sets Free, no signup

Free, no signup — identities verified, not asserted.

Updated 6 September 2026 · Works in any browser, no installation

The union takes everything in either set; the intersection takes only what is in both. For A = {1, 2, 3, 4} and B = {3, 4, 5, 6}: A ∪ B = {1, 2, 3, 4, 5, 6} and A ∩ B = {3, 4}.

At a glance

Formula shown
|A \u222a B| = |A| + |B| \u2212 |A \u2229 B|. The correction removes the elements counted twice, which is exactly the intersection.
Scenario support
Two or three finite sets, with an optional universe for complements.
Educational estimate
Planning support from the values you enter — not professional advice.

Six operations, and what each one is asking

They differ in which elements survive, and the plain-English reading is worth having beside the symbol:

  • A ∪ Beverything that is in A, in B, or in both. Here: {1, 2, 3, 4, 5, 6}.
  • A ∩ Beverything that is in A and in B at the same time. Here: {3, 4}.
  • A − Bin A but not in B. Here: {1, 2}.
  • B − Ain B but not in A — the other way round, and usually a different set. Here: {5, 6}.
  • A △ Bin exactly one of the two: the union with the overlap removed. Here: {1, 2, 5, 6}.

Union and intersection are both commutative and associative, which is why A ∪ B and B ∪ A give the same set and why a three-way union needs no brackets. The differences are neither, which is the subject of the next section.

A − B and B − A are different sets

A − B and B − A are different sets here — {1, 2} against {5, 6}. Set difference is not symmetric, unlike union and intersection.

This is the operation that behaves like ordinary subtraction and it is worth noticing that ordinary subtraction is not symmetric either — 5 − 3 and 3 − 5 are different numbers, and nobody finds that surprising.

The symmetric difference exists precisely to have a symmetric version: A △ B is {1, 2, 5, 6}, the elements in exactly one of the two sets. It is the union minus the intersection, and A △ B and B △ A really are the same.

Complements need a universe, and inventing one is wrong

A′ means “everything not in A”, and that is not a set until you say what everything is. Without a universe the complement of {1, 2} would have to contain 3, 4, π, the letter q and the Eiffel Tower.

Complements need a universe. Without one, A′ has no meaning — "everything not in A" is not a set until you say what everything is. Give a universal set to see A′, B′ and the De Morgan checks.

The usual silent default — treating the union of every set mentioned as the universe — gives wrong answers whenever the real universe is larger. With A and B as above and a universe of {1, 2, 3, 4, 5, 6, 7, 8}, A′ is {5, 6, 7, 8}; that default would have given the empty set instead.

Counting the union without counting anything twice

|A ∪ B| = |A| + |B| − |A ∩ B| = 4 + 4 − 2 = 6 — and the left side there is not a formula, it is the length of the union the tool actually computed.

The subtraction is doing one job: the shared elements were counted once in |A| and once in |B|, so one copy has to come off. That is the whole of inclusion–exclusion at two sets.

At three sets it gets four correction terms and this is where people lose track. |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C| = 2 + 2 + 2 − 1 − 0 − 1 + 0 = 4 The pattern — add the singles, subtract the pairs, add the triple back — continues for any number of sets, alternating signs, and it is why the identity has the name it does.

De Morgan, checked rather than quoted

The two laws say a complement turns union into intersection and back:

  • (A ∪ B)′ = A′ ∩ B′{7, 8} versus {7, 8}, which agree.
  • (A ∩ B)′ = A′ ∪ B′{1, 2, 5, 6, 7, 8} versus {5, 6, 7, 8, 1, 2}, which agree.

Both sides are computed from the given sets and compared. That is a deliberate choice: an identity printed from a table proves nothing about the code underneath, and while this page was being built that comparison is exactly what caught the complement being computed with its arguments the wrong way round.

The same two laws hold in logic, where they turn ¬(p ∧ q) into ¬p ∨ ¬q. That is not an analogy — sets under ∪, ∩, ′ and propositions under ∨, ∧, ¬ are the same algebraic structure, and the Truth Table Generator verifies the logical version the same way.

Venn regions partition the universe

A Venn diagram is not a picture of the sets so much as a partition of the universe: every element lands in exactly one region, and the regions between them account for everything.

For A, B and the universe above: A only = 1, 2; B only = 5, 6; A ∩ B = 3, 4; Outside every set = 7, 8. Their sizes add to 8, which is the size of the universe — as a partition requires.

Three sets give eight regions rather than four, including the one outside all of them, and that count is 2ⁿ for the same reason a power set has 2ⁿ members: each element is in or out of each set independently. The tool computes the regions from the same lists as the operations, so the diagram and the answers cannot disagree.

Sources and methodology

Set operations, inclusion–exclusion and De Morgan are standard; the reference below carries the canonical statements.

Method. Every figure on this page comes from src/lib/union-and-intersection.ts over src/lib/algebra/sets.ts. The inclusion–exclusion and De Morgan lines are computed from the same set objects that produce the operation results and compared, so they act as assertions about this page rather than as quotations. That engine is verified on every change against 57 hand-written assertions, including that the Venn regions always partition the universe exactly, and that both De Morgan laws hold on every tested pair. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

SubsetTest whether one set is a subset, a proper subset, equal or disjoint — and when the answer is no, name the exact element that breaks it.
Power SetList all 2^n subsets with the binary word that generates each one, grouped by size and checked against the binomial coefficients, with the element-versus-subset distinction spelled out.
Interval NotationConvert between inequality, interval notation, set-builder form and a number-line graph in every direction, including absolute values, unions and the empty set.
Truth Table GeneratorBuild a truth table with a column for every sub-expression, classify the result, compare two expressions with a named counterexample row, and read DNF and CNF straight off the table.
Binomial Coefficientn choose k exactly on big integers, by the multiplicative formula that never builds a number bigger than the answer — with Pascal's rule, the row it sits in, and permutations beside it.

More in Math, or browse all calculators.

Read the guide

Set operations, containment and the power set are three views of the same structure. The Subset Calculator covers the relation these operations respect, and the Truth Table Generator verifies the same De Morgan laws in their logical form.

Educational use disclaimer

This calculator performs set operations on two or three finite sets. Complements require a universal set, and the page says so rather than treating the union of everything mentioned as the universe — that default is common and wrong. Elements are compared as written, so 1 and 1.0 are different labels.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 6 September 2026

  1. Published the union and intersection page: six operations on two or three sets at once, with the Venn regions computed from the same sets as the lists.
  2. Inclusion–exclusion and both De Morgan laws are COMPUTED and compared rather than quoted, so the identities are checks on the arithmetic.
  3. Refuses to invent a universe for complements — without one, A′ has no meaning, and the page says so instead of treating everything mentioned as the universe.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.