Set Operations Calculator

Enter two finite sets to find their union, intersection, directional differences, and symmetric difference. Add a universal set to calculate complements. Duplicate values are removed, and everything runs privately in your browser.

Enter your sets

Separate elements with commas, semicolons, or new lines. Values are text labels, so 1 and 1.0 are different elements.

Example: red, green, blue4 unique elements

Empty input represents the empty set ∅.4 unique elements

U must contain every element of A and B.8 unique elements

Private by design: the sets are parsed and compared on this device. Inputs are not uploaded, saved, or included in the page URL.

Results

The number example is calculated below.

Advertisement

Set operation definitions and formulas

Union

A ∪ B = {x | x ∈ A or x ∈ B}

Every element found in either set, listed once.

Intersection

A ∩ B = {x | x ∈ A and x ∈ B}

Only elements shared by both sets.

Difference

A ∖ B = {x | x ∈ A and x ∉ B}

Elements of the first set that are absent from the second. Direction matters.

Symmetric difference

A △ B = (A ∖ B) ∪ (B ∖ A)

Elements in exactly one set, excluding the intersection.

Complement

Aᶜ = U ∖ A

Elements of the universal set U that are not in A.

Union cardinality

|A ∪ B| = |A| + |B| − |A ∩ B|

The shared elements are subtracted once because the first two counts include them twice.

Worked set operations example

Let A = {1, 2, 3, 5}, B = {2, 3, 4, 6}, and U = {1, 2, 3, 4, 5, 6, 7, 8}. The overlap is {2, 3}; values 1 and 5 belong only to A, while 4 and 6 belong only to B.

OperationResultCardinality
A ∪ B{1, 2, 3, 5, 4, 6}6
A ∩ B{2, 3}2
A ∖ B{1, 5}2
A △ B{1, 5, 4, 6}4
Aᶜ = U ∖ A{4, 6, 7, 8}4

The identity check gives |A ∪ B| = 4 + 4 − 2 = 6, matching the six unique elements in the union.

Method, matching rules, and limits

The calculator splits each input at commas, semicolons, and line breaks; trims leading and trailing whitespace; normalizes equivalent Unicode compositions; and removes duplicates. Exact matching is the default. In case-insensitive mode, labels such as Blue and blue match, while the first spelling encountered is retained for display.

Set results preserve useful input order: union and symmetric difference start with qualifying A elements and then add qualifying B elements; complements follow U. The universal set is optional for the first five operations, but complements are shown only when U contains every element of A and B. Blank A or B input is a valid empty set.

Each input is limited to 20,000 characters and 1,000 unique elements. Result cards display the first 100 elements to keep very large inputs responsive; copy and CSV exports still include the complete calculated result. Quoted CSV parsing is not used, so commas, semicolons, and line breaks cannot be part of an element.

The definitions follow the standard treatment in OpenStax, Contemporary Mathematics, Section 1.4.

Editorial review: Operation identities, validation rules, and representative outputs checked by the Starlight Tools editorial team. Last reviewed: .

Set operations calculator FAQ

What is the union of two sets?

The union A ∪ B contains every element in A, B, or both. Each value appears only once.

What is the intersection of two sets?

The intersection A ∩ B contains only values shared by A and B. If there are none, the result is the empty set ∅.

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

A ∖ B keeps A-only elements; B ∖ A keeps B-only elements. Reversing the operands usually changes the result.

What is symmetric difference?

A △ B contains values that occur in exactly one set. It combines the two directional differences and excludes the intersection.

Why is a universal set required for complements?

A complement is always relative to a universe. Aᶜ = U ∖ A, so changing U can change Aᶜ even when A stays the same.

Are duplicates removed?

Yes. Sets contain unique elements, so repeated input values collapse to one. The tool reports how many duplicates it removed from each input.

Are numbers sorted or evaluated?

No. Inputs are text labels and stay in first-seen order. For example, 01, 1, and 1.0 are three distinct elements.

Does the calculator store my sets?

No. Parsing, operations, copying, and file creation run locally in your browser. The tool does not transmit or save entered values.

Explore more tools