Set Theory Calculator
Enter two sets and instantly compute union, intersection, difference, symmetric difference, Cartesian product, and Venn diagram.
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
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.
| Symbol | Name | Meaning |
|---|---|---|
| A ∪ B | Union | All elements in A or B |
| A ∩ B | Intersection | Elements in both A and B |
| A \ B | Set Difference | Elements in A but not B |
| A △ B | Symmetric Difference | Elements in exactly one set |
| A × B | Cartesian Product | All ordered pairs (a, b) |
| A ⊆ B | Subset | Every element of A is in B |
| A ⊇ B | Superset | Every element of B is in A |
| ∅ | Empty Set | Set with no elements |
| |A| | Cardinality | Number of elements in A |
Set Theory FAQ
What is the union of two sets?
What is the intersection of two sets?
What is the difference between A \ B and B \ A?
What is symmetric difference in set theory?
What is the Cartesian product of two sets?
How do I check if one set is a subset of another?
Can sets contain duplicate elements?
What does the cardinality of a set mean?
Related Calculators
Probability Calculator
Union and intersection probabilities with Venn diagrams
Combination & Permutation
Count selections and arrangements from a set
Bayesian Calculator
Conditional probability using Bayes' theorem
Modular Arithmetic
Number theory — mod, inverses, and powers
Prime Factorization
Factor trees and prime sets of any integer
Binomial Distribution
Probabilities over sets of trials