Union and Intersection Calculator

Enter two sets of elements to find their union, intersection, difference, and symmetric difference, plus the size of each result.

Quick Facts

Union
A ∪ B = {x : x ∈ A or x ∈ B}
Every element that appears in A, in B, or in both — duplicates count once.
Intersection
A ∩ B = {x : x ∈ A and x ∈ B}
Only the elements shared by both sets.
Inclusion-exclusion
|A ∪ B| = |A| + |B| − |A ∩ B|
Shared elements are counted once instead of twice.

Your Results

Calculated
Union (A ∪ B)
-
Elements in A, B, or both
Intersection (A ∩ B)
-
Elements in both A and B
Difference (A − B)
-
Elements only in A
Symmetric Difference (A △ B)
-
Elements in exactly one set

Ready

Enter elements for Set A and Set B, separated by commas, then press Calculate.

How Union and Intersection Work

A set is a collection of distinct elements — numbers, letters, or any other items — with no regard to order and no duplicates. Given two sets A and B, the two most basic set operations are the union and the intersection. This calculator parses the elements you type into Set A and Set B, then computes their union, intersection, difference, and symmetric difference.

Formula and method

The union of A and B, written A ∪ B, is the set of every element that belongs to A, to B, or to both: A ∪ B = {x : x ∈ A or x ∈ B}. The intersection, written A ∩ B, is the set of elements that belong to both A and B: A ∩ B = {x : x ∈ A and x ∈ B}. The calculator also reports the relative difference A − B (elements in A that are not in B) and the symmetric difference A △ B = (A − B) ∪ (B − A), the elements that belong to exactly one of the two sets. To count elements without double-counting the overlap, the inclusion-exclusion principle gives |A ∪ B| = |A| + |B| − |A ∩ B|, since elements in the intersection are otherwise counted once in |A| and once again in |B|.

Common sources of error

  • Treating a set like a list: a set never contains duplicates, so entering "2, 2, 3" is identical to entering "2, 3" — repeats collapse to a single element.
  • Case and spacing mismatches: "Apple" and "apple" are different text elements unless you normalize capitalization first; extra spaces around commas are trimmed automatically by this tool.
  • Confusing intersection with union: intersection is never larger than the smaller input set, while union is always at least as large as the bigger one — if your result breaks that rule, re-check which operation you meant.

Checking your result

A quick sanity check uses the inclusion-exclusion principle: the number of elements in the union plus the number in the intersection should always equal the number in A plus the number in B, i.e. |A ∪ B| + |A ∩ B| = |A| + |B|. If that identity does not hold for your two sets, an element was likely miscounted or mistyped.

Applications

Union and intersection appear throughout probability (combining or overlapping events), database queries (JOIN and UNION operations), search filtering (matching any keyword versus all keywords), and Venn-diagram reasoning in statistics and logic courses. Recording both sets and the operation used makes a result easy to reproduce or double-check later.

Frequently Asked Questions

What is the difference between the union and the intersection of two sets?
The union A ∪ B contains every element that is in A, in B, or in both, with duplicates counted once. The intersection A ∩ B contains only the elements that appear in both A and B. Union is always at least as large as either original set; intersection is never larger than the smaller set.
How do you find the size of a union using the inclusion-exclusion principle?
For two sets, |A ∪ B| = |A| + |B| − |A ∩ B|. You add the sizes of both sets, then subtract the size of the intersection once because those shared elements were counted twice.
Does the order of elements or repeated entries in a set matter?
No. A set is an unordered collection of distinct elements, so entering "1,2,2,3" is treated the same as "1,2,3", and the order you list elements in does not change the union, intersection, or any other result.
What is the symmetric difference of two sets?
The symmetric difference A △ B contains every element that is in exactly one of the two sets, but not both: A △ B = (A − B) ∪ (B − A), which is also equal to (A ∪ B) − (A ∩ B).