Skip to content
K Knidox Search…
Computer Science · Discrete Math

Set Operations Calculator

Compute the union, intersection, difference, and symmetric difference of two sets.

Elements separated by commas or spaces.
Elements separated by commas or spaces.
Try an example
Union (A ∪ B)
{1, 2, 3, 4}|A ∪ B| = 4

A = {1, 2, 3} with |A| = 3; B = {2, 3, 4} with |B| = 3. Neither set is a subset of the other.

UnionA ∪ B
{1, 2, 3, 4}
4 elements
IntersectionA ∩ B
{2, 3}
2 elements
DifferenceA − B
{1}
1 element
DifferenceB − A
{4}
1 element
Symmetric differenceA △ B
{1, 4}
2 elements
Venn diagram of sets A and BAB1234
Venn diagram — A only · both · B only

A set operation combines two sets of distinct elements. For A = {1, 2, 3} and B = {2, 3, 4}: the union A ∪ B = {1, 2, 3, 4}, the intersection A ∩ B = {2, 3}, the difference A − B = {1}, B − A = {4}, and the symmetric difference A △ B = {1, 4}. Neither set is a subset of the other.

What set operations do

A set is an unordered collection of distinct elements — no duplicates, no position. Set operations build a new set from two existing sets A and B. The union (A ∪ B) gathers every element that appears in either set; the intersection (A ∩ B) keeps only elements in both; the difference (A − B, also written A \ B) keeps elements of A that are not in B; and the symmetric difference (A △ B) keeps elements in exactly one of the two sets. This calculator parses each box into a set — splitting on commas or spaces and discarding duplicates — then reports every operation together with the cardinalities |A|, |B|, |A ∪ B|, and |A ∩ B|.

A ∪ B = {x : x ∈ A or x ∈ B} · A ∩ B = {x : x ∈ A and x ∈ B} · A − B = {x : x ∈ A and x ∉ B} · A △ B = (A − B) ∪ (B − A)

The four core operations in set-builder notation. A ⊆ B holds when every element of A is also in B.

Worked example: A = {1, 2, 3}, B = {2, 3, 4}

The two sets overlap in 2 and 3. Walk through each operation element by element.

  1. 1
    Parse each set and remove duplicates. A = {1, 2, 3} and B = {2, 3, 4}. A set ignores order and repeats, so “2, 2, 3” collapses to {2, 3}.
  2. 2
    Union — take everything, once. List every element from A or B without repeating shared ones: A ∪ B = {1, 2, 3, 4}, so |A ∪ B| = 4.
  3. 3
    Intersection — keep the shared elements. Only 2 and 3 appear in both sets, so A ∩ B = {2, 3} and |A ∩ B| = 2.
  4. 4
    Difference — subtract one from the other. Remove B’s elements from A: A − B = {1}. Remove A’s elements from B: B − A = {4}. Difference is not symmetric.
  5. 5
    Symmetric difference — in exactly one set. Combine the two differences: A △ B = (A − B) ∪ (B − A) = {1, 4}. It equals the union minus the intersection.
  6. 6
    Check subset and superset. A ⊆ B only if A − B is empty. Here A − B = {1} is not empty, so neither set is a subset of the other.

Set operations at a glance

Each operation with its meaning and its result for A = {1, 2, 3}, B = {2, 3, 4}.

OperationMeaningResult
Union — A ∪ BIn A or B (or both){1, 2, 3, 4}
Intersection — A ∩ BIn both A and B{2, 3}
Difference — A − BIn A but not B{1}
Difference — B − AIn B but not A{4}
Symmetric difference — A △ BIn exactly one set{1, 4}
Subset — A ⊆ BEvery element of A is in Bfalse (A − B ≠ ∅)

Duplicates, order, and the empty set

Because a set is defined by membership alone, duplicates and order carry no meaning. Entering “3, 1, 2” or “1, 1, 2, 3” both describe the set {1, 2, 3}, and the calculator normalises them before computing. The symmetric difference collects the elements that belong to exactly one set — equivalently A △ B = (A ∪ B) − (A ∩ B) — which makes it the set analogue of exclusive-or (XOR). When two sets share no elements they are disjoint, so A ∩ B = ∅ (the empty set) and A △ B equals the full union. A ⊆ B means B is a superset of A; if that holds in both directions the sets are equal.

What is the difference between union and intersection?
The union A ∪ B collects every element that is in A or in B, while the intersection A ∩ B keeps only the elements that are in both. For {1, 2, 3} and {2, 3, 4} the union is {1, 2, 3, 4} and the intersection is {2, 3}.
What is the symmetric difference of two sets?
The symmetric difference A △ B is the set of elements in exactly one of the two sets — that is, (A − B) ∪ (B − A), or equivalently the union minus the intersection. For {1, 2, 3} and {2, 3, 4} it is {1, 4}. It behaves like an exclusive-or on membership.
Does the order or duplication of elements matter?
No. A set is defined only by which elements it contains, so order and repeats are ignored. Typing “3, 1, 2, 2” describes the same set as {1, 2, 3}, and the calculator removes duplicates before computing.
Why is A − B different from B − A?
Difference is not symmetric: A − B keeps elements of A that are absent from B, while B − A keeps elements of B absent from A. For {1, 2, 3} and {2, 3, 4}, A − B = {1} but B − A = {4}.
When is A a subset of B?
A ⊆ B holds when every element of A is also in B — equivalently when A − B is the empty set. If A ⊆ B and B ⊆ A both hold, the two sets are equal.
What does the tool do with non-numeric elements?
Elements are treated as text, so words and symbols work as well as numbers — “red, green, blue” is a valid set. Purely numeric sets are sorted numerically for display; mixed or text sets are sorted alphabetically.