A ∪ B

Set Theory Calculator

Enter two sets and instantly compute union, intersection, difference, symmetric difference, Cartesian product, and Venn diagram.

A ∪ B Union A ∩ B Intersection A \ B Difference A × B Cartesian Product
Share this tool

Set A

Enter elements separated by commas. Example: 1, 2, 3 or { a, b, c }

Up to 50 elements. Duplicates removed automatically.

Set B

Enter elements separated by commas. Example: 3, 4, 5 or { x, y, z }

Computes all operations: union, intersection, difference, and more.
Quick Load:
Computing set operations…

Enter two sets above and press Compute Sets to see all set operations instantly.

How Set Operations Work

Visual Venn diagrams showing the four fundamental operations

A ∪ B — Union A B A ∩ B — Intersection A B A \ B — Difference A B A △ B — Symmetric Diff A B

What Is Set Theory?

Set theory is the branch of mathematics that studies collections of objects called sets. A set is any well-defined collection of distinct objects — numbers, letters, people, colours, or any other entities. Sets underpin nearly every area of mathematics: logic, probability, algebra, and computer science all rely on set-theoretic concepts.

Sets are written using curly braces. The set of even numbers less than ten is written { 2, 4, 6, 8 }. Order does not matter, and each element appears only once — { 1, 2, 3 } and { 3, 1, 2 } are the same set.

This set theory calculator accepts any comma-separated list of elements, strips duplicate entries, and instantly computes every standard set operation. You can enter numbers, words, or symbols — the parser handles them all.

How to Calculate the Union of Two Sets

The union of sets A and B, written A ∪ B, is the set containing every element that appears in A or B (or both). It is the most inclusive operation — nothing from either set is left out.

A = { 1, 2, 3, 4 }

B = { 3, 4, 5, 6 }

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

The union is useful wherever you need a combined list with no repeats: merging two contact lists, finding all students enrolled in either of two courses, or combining two database result sets with SQL UNION.

How to Find the Intersection of Two Sets

The intersection of A and B, written A ∩ B, contains only the elements present in both sets simultaneously. If the intersection is empty, the sets are called disjoint.

A = { 1, 2, 3, 4 }

B = { 3, 4, 5, 6 }

A ∩ B = { 3, 4 }

Intersection answers the question "what do both groups have in common?" It maps directly to the SQL INNER JOIN, Venn diagram overlaps in probability, and eligibility checks in logic (a student must pass test A and test B).

Set Difference: A \ B vs B \ A

The set difference A \ B (also written A − B or A ∖ B) contains elements that belong to A but not to B. Unlike most set operations, difference is not commutative: A \ B and B \ A are generally different sets.

A \ B

A = { 1, 2, 3, 4 }

B = { 3, 4, 5, 6 }

A \ B = { 1, 2 }

B \ A

A = { 1, 2, 3, 4 }

B = { 3, 4, 5, 6 }

B \ A = { 5, 6 }

Set difference is also called the relative complement. In a database context, A \ B corresponds to a LEFT OUTER JOIN WHERE B IS NULL — returning rows in A that have no match in B.

Symmetric Difference Explained

The symmetric difference A △ B contains elements that are in A or B but not in both. It is equivalent to (A \ B) ∪ (B \ A), or alternatively (A ∪ B) \ (A ∩ B).

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

A △ B = { 1, 2, 5, 6 }

(elements 3 and 4 are in both, so excluded)

Symmetric difference is useful in change detection: if set A is the old state and B is the new state, A △ B tells you exactly what was added or removed. It also maps to the XOR gate in digital logic.

Cartesian Product of Two Sets

The Cartesian product A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B. If |A| = m and |B| = n, then |A × B| = m × n.

A = { 1, 2 }, B = { x, y, z }

A × B = { (1,x), (1,y), (1,z), (2,x), (2,y), (2,z) }

|A × B| = 2 × 3 = 6

The Cartesian product is the foundation of relational databases (a CROSS JOIN), coordinate systems (ℝ × ℝ = ℝ²), and combinatorics where you count all combinations of two independent choices.

Subset, Superset, and Equal Sets

A is a subset of B (A ⊆ B) when every element of A is also in B. A is a proper subset (A ⊂ B) when A ⊆ B and A ≠ B. Two sets are equal (A = B) when A ⊆ B and B ⊆ A simultaneously.

SymbolNameMeaning
A ∪ BUnionAll elements in A or B
A ∩ BIntersectionElements in both A and B
A \ BSet DifferenceElements in A but not B
A △ BSymmetric DifferenceElements in exactly one set
A × BCartesian ProductAll ordered pairs (a, b)
A ⊆ BSubsetEvery element of A is in B
A ⊇ BSupersetEvery element of B is in A
∅Empty SetSet with no elements
|A|CardinalityNumber of elements in A

Set Theory FAQ

What is the union of two sets?

The union A ∪ B is the set containing all elements that appear in A, in B, or in both. Each element is listed only once, even if it appears in both sets. If A = {1,2,3} and B = {3,4,5}, then A ∪ B = {1,2,3,4,5}.

What is the intersection of two sets?

The intersection A ∩ B contains only the elements that are present in both A and B simultaneously. If A = {1,2,3} and B = {3,4,5}, then A ∩ B = {3}. If no elements are shared, the result is the empty set ∅.

What is the difference between A \ B and B \ A?

A \ B gives elements in A that are not in B. B \ A gives elements in B that are not in A. These are different sets in general. For A = {1,2,3} and B = {3,4,5}: A \ B = {1,2} and B \ A = {4,5}.

What is symmetric difference in set theory?

The symmetric difference A △ B contains elements that are in exactly one of the two sets — in A but not B, or in B but not A. It equals (A \ B) ∪ (B \ A). For A = {1,2,3} and B = {3,4,5}: A △ B = {1,2,4,5}.

What is the Cartesian product of two sets?

The Cartesian product A × B is the set of all ordered pairs (a, b) where a comes from A and b comes from B. If A = {1,2} and B = {x,y}, then A × B = {(1,x),(1,y),(2,x),(2,y)}. Its size is |A| × |B|.

How do I check if one set is a subset of another?

A is a subset of B (A ⊆ B) if every element of A also belongs to B. Check each element of A against B: if all pass, A ⊆ B is true. Equal sets are subsets of each other. The empty set ∅ is a subset of every set.

Can sets contain duplicate elements?

No. By definition, a set contains each element exactly once. If you enter duplicates like {1, 1, 2, 3}, this calculator automatically deduplicates to {1, 2, 3} before performing any operation. Collections that allow duplicates are called multisets or bags.

What does the cardinality of a set mean?

Cardinality |A| is the number of distinct elements in the set. |{apple, banana, cherry}| = 3. For finite sets, it is simply a count. The cardinality of the Cartesian product equals |A| × |B|, making it easy to predict the number of ordered pairs before computing them.