Set Calculator: Union, Intersection, Difference & Venn Diagram

AlgebraFreeNo sign-up

A set calculator combines sets the way you would on paper, listing each element once. For A = {1, 2, 3, 4, 5} and B = {4, 5, 6, 7}, the union A ∪ B is {1, 2, 3, 4, 5, 6, 7}, the intersection A ∩ B is {4, 5}, and the difference A − B is {1, 2, 3}. The Venn diagram shades the region for each answer.

Set calculator
Separate elements with commas. Numbers, letters and short words work; braces are optional; 1..10 means 1 to 10. Leave a set empty for ∅. U is needed only for complements.
Try:
Union
A ∪ B = {1, 2, 3, 4, 5, 6, 7}
|A ∪ B| = 7 elements · |A| = 5, |B| = 4, |U| = 10
✗ A ⊆ B✗ B ⊆ A✗ A = B✗ A and B are disjoint
ABU1, 2, 36, 74, 5outside: 8, 9, 10
Venn diagram: shaded region is A ∪ B
Operation Result Size
A ∪ B {1, 2, 3, 4, 5, 6, 7} 7
A ∩ B {4, 5} 2
A − B {1, 2, 3} 3
B − A {6, 7} 2
A △ B {1, 2, 3, 6, 7} 5
A′ {6, 7, 8, 9, 10} 5
B′ {1, 2, 3, 8, 9, 10} 6
Show steps
  1. Write each set once, in orderA = {1, 2, 3, 4, 5} and B = {4, 5, 6, 7}; U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Repeated elements count once, and order does not matter.
  2. Start with A, then add what is new in BElements of B that are not already in A: {6, 7}. So A ∪ B = {1, 2, 3, 4, 5, 6, 7}.
  3. Check the sizeInclusion–exclusion: |A ∪ B| = |A| + |B| − |A ∩ B| = 5 + 4 − 2 = 7.

Related: probability calculator · permutations and combinations calculator · truth table generator

Set Calculator: Union, Intersection, Difference & Venn Diagram
Embed this calculator on your site

Free to use on class pages, blogs and course pages. Copy the code below and paste it into your page:

How to use the set calculator

  1. Two sets: type the elements of A and B separated by commas, and a universal set U if you need complements (1..10 means 1 to 10). Choose what to show. You get the answer, a shaded Venn diagram, every other operation in a table, the sizes and whether A ⊆ B, B ⊆ A, A = B or the sets are disjoint.
  2. Three sets: enter A, B, C (and U) and any expression, such as (A ∪ B) ∩ C′. Use the symbol buttons or type u, n, – and ‘ instead. Add an equals sign to test an identity such as De Morgan’s law.
  3. Power set: list every subset of a set, grouped by size.
  4. A × B: list all ordered pairs of the Cartesian product.

Elements can be numbers, letters or short words. Duplicates are removed, numbers like 2.0 and 2 count as the same element, and an empty box means the empty set ∅.

The set operations

All examples use A = {1, 2, 3, 4, 5}, B = {4, 5, 6, 7} and U = {1, 2, …, 10}.

Operation Symbol Keeps Example
Union A ∪ B everything in A or B (or both) {1, 2, 3, 4, 5, 6, 7}
Intersection A ∩ B only what is in both {4, 5}
Difference A − B what is in A but not in B {1, 2, 3}
Difference B − A what is in B but not in A {6, 7}
Symmetric difference A △ B what is in exactly one of them {1, 2, 3, 6, 7}
Complement A′ everything in U that is not in A {6, 7, 8, 9, 10}

A − B is also written A \ B, and the complement A′ is also written Aᶜ or Ā. A complement only makes sense once you say what the universal set is: the complement of {1, 3, 5} is {2, 4} inside U = {1, 2, 3, 4, 5}, but {2, 4, 6, 7, 8, 9, 10} inside U = {1, …, 10}.

Subsets and the power set

A ⊆ B (A is a subset of B) means every element of A is also in B. {2, 4} ⊆ {1, 2, 3, 4}, and every set is a subset of itself. A proper subset (A ⊂ B) is a subset that is not equal to B. The empty set ∅ is a subset of every set, because it has no element that could be missing.

The power set P(A) is the set of all subsets. Each element is either in a subset or not, so a set with n elements has 2ⁿ subsets and 2ⁿ − 1 proper subsets. For {a, b, c} that is 8 subsets: ∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c} and {a, b, c}. The number with exactly k elements is the binomial coefficient C(n, k), which is why the sizes 1, 3, 3, 1 match a row of Pascal’s triangle.

Cardinality and inclusion–exclusion

The cardinality |A| is the number of distinct elements. Adding |A| and |B| counts the shared elements twice, so subtract them once:

  • |A ∪ B| = |A| + |B| − |A ∩ B|. With the sets above: 5 + 4 − 2 = 7.
  • |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|. With C = {2, 4, 6, 8}: 5 + 4 + 4 − 2 − 2 − 2 + 1 = 8.

The same formula answers survey questions. If 18 students play soccer, 12 play tennis and 5 play both, then 18 + 12 − 5 = 25 play at least one of the two sports.

Reading a Venn diagram

Two circles split the rectangle U into four regions: only A, both, only B, and neither. Three circles make eight regions. To shade an expression, work from the inside out. For (A ∪ B) ∩ C′ with the sets above, A ∪ B is {1, 2, 3, 4, 5, 6, 7} and C′ is {1, 3, 5, 7, 9, 10}, so the answer is {1, 3, 5, 7}: the parts of A and B that lie outside C. The calculator shades the regions and writes each element where it belongs.

Set identities

Law Identity
Commutative A ∪ B = B ∪ A and A ∩ B = B ∩ A
Associative A ∪ (B ∪ C) = (A ∪ B) ∪ C
Distributive A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
De Morgan (A ∪ B)′ = A′ ∩ B′ and (A ∩ B)′ = A′ ∪ B′
Difference A − B = A ∩ B′

Type an identity with an equals sign in the Three sets tab. The calculator compares both sides for your sets and also checks all eight Venn regions, so it can tell a true law from two sides that only happen to match. For example, A ∪ B = A ∪ C is false in general: with the sets above, the left side is {1, 2, 3, 4, 5, 6, 7} and the right side is {1, 2, 3, 4, 5, 6, 8}.

The Cartesian product

A × B is the set of all ordered pairs (a, b) with a from A and b from B. For A = {1, 2, 3} and B = {x, y} there are 3 · 2 = 6 pairs: (1, x), (1, y), (2, x), (2, y), (3, x), (3, y). Order matters, so (1, x) is not the same as (x, 1). Two dice give 6 · 6 = 36 outcomes, which is why the product is the starting point for many probability questions.

Common mistakes

Mistake Fix
Listing a shared element twice in a union Write each element once: {1, 2, 3} ∪ {3, 4} = {1, 2, 3, 4}.
Treating A − B and B − A as the same Difference is not symmetric; check which set you start from.
Taking a complement without U State the universal set first.
Mixing up ∈ and ⊆ 2 ∈ {1, 2}, but {2} ⊆ {1, 2}.
Thinking ∅ and {∅} are equal ∅ has no elements; {∅} has one element, the empty set.
Forgetting ∅ and the set itself in a power set Count them: there should be 2ⁿ subsets.

Sets practice quiz: 10 questions

Test yourself with 10 multiple-choice questions. Choose an answer and press Submit to see if you are right and why. Your score appears at the end.

Question 1 of 10
1. If P = {2, 3, 5, 7} and E = {2, 4, 6, 8}, what is P ∪ E?

Found a mistake? Let us know!

2. With the same sets, what is P ∩ E?

Found a mistake? Let us know!

3. With the same sets, what is P − E?

Found a mistake? Let us know!

4. With the same sets, what is P △ E?

Found a mistake? Let us know!

5. If U = {1, 2, …, 8} and X = {1, 2, 5}, what is X′?

Found a mistake? Let us know!

6. How many subsets does {p, q, r, s} have?

Found a mistake? Let us know!

7. How many 2-element subsets does a 5-element set have?

Found a mistake? Let us know!

8. |A| = 12, |B| = 9 and |A ∩ B| = 4. What is |A ∪ B|?

Found a mistake? Let us know!

9. Which statement is true for A = {1, 2} and B = {1, 2, 3}?

Found a mistake? Let us know!

10. If A has 3 elements and B has 4, how many ordered pairs are in A × B?

Found a mistake? Let us know!

Frequently asked questions

What is the union of two sets?

The union A ∪ B contains every element that is in A, in B or in both, each listed once. {1, 2, 3} ∪ {3, 4} = {1, 2, 3, 4}.

What is the intersection of two sets?

The intersection A ∩ B contains only the elements the sets share. {1, 2, 3} ∩ {3, 4} = {3}. If nothing is shared, the answer is ∅ and the sets are called disjoint.

What does subset mean?

A ⊆ B means every element of A is also in B. The calculator checks this both ways and also tells you whether the sets are equal.

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

A − B keeps the elements of A that are not in B; B − A keeps the elements of B that are not in A. For {1, 2, 3} and {3, 4}, A − B = {1, 2} and B − A = {4}.

Why do I need a universal set for the complement?

The complement A′ is everything that is not in A, and "everything" has to be defined. The universal set U says what that is.

How many subsets does a set with n elements have?

2ⁿ, including ∅ and the set itself. A set with 4 elements has 16 subsets, 15 of them proper.

Related calculators

More algebra calculators

Browse all 206 calculators

Related to This Article

What people say about "Set Calculator: Union, Intersection, Difference & Venn"?

No one replied yet.

Leave a Reply