Set Theory • Union • Intersection • Difference

Union and Intersection Calculator

Use this Union and Intersection Calculator to find \(A\cup B\), \(A\cap B\), \(A-B\), \(B-A\), and the symmetric difference of two sets. Enter elements separated by commas or new lines, and the calculator will remove duplicates, compare the sets, show cardinalities.

UnionFind all elements in \(A\), \(B\), or both.
IntersectionFind elements common to both \(A\) and \(B\).
Set differencesFind \(A-B\), \(B-A\), and \(A\triangle B\).

Enter two sets

Set operation calculator.
Enter set \(A\) and set \(B\). Example: \(A=\{1,2,3,4\}\), \(B=\{3,4,5,6\}\).

Separate values with commas or new lines.

Repeated entries can be removed automatically.

Results

Enter two sets and calculate.
Set \(A\)
\(\{1,2,3,4\}\)
Set \(B\)
\(\{3,4,5,6\}\)
Union \(A\cup B\)
\(\{1,2,3,4,5,6\}\)
Intersection \(A\cap B\)
\(\{3,4\}\)
Differences and cardinality
\(A-B=\{1,2\}\), \(B-A=\{5,6\}\)

Union and intersection formulas

The union and intersection of sets are two of the most important operations in set theory. The union of two sets collects everything that appears in either set. The intersection collects only what appears in both sets. If \(A\) and \(B\) are sets, the union is written as:

\[ A\cup B=\{x:x\in A\ \text{or}\ x\in B\} \]

The intersection is written as:

\[ A\cap B=\{x:x\in A\ \text{and}\ x\in B\} \]

The cardinality formula connecting union and intersection is:

\[ |A\cup B|=|A|+|B|-|A\cap B| \]

This formula matters because elements in the intersection are counted twice when you add \( |A|+|B| \). Subtracting \( |A\cap B| \) removes the duplicate count. This calculator applies these same definitions. It reads the elements of \(A\), reads the elements of \(B\), removes repeated entries if selected, then calculates the union, intersection, differences, symmetric difference, and cardinalities.

How to use the Union and Intersection Calculator

  1. Enter set \(A\). Type elements separated by commas or line breaks. Example: \(1,2,3,4\).
  2. Enter set \(B\). Type the second set in the same format. Example: \(3,4,5,6\).
  3. Choose the operation. You can show all set operations or highlight one operation such as \(A\cup B\) or \(A\cap B\).
  4. Choose duplicate handling. In standard set theory, repeated entries are ignored, so duplicates should usually be removed.
  5. Click Calculate Set Operations. The calculator displays the union, intersection, differences, symmetric difference, and counts.
  6. Read the steps. The explanation shows which elements are included, which are shared, and how the cardinality formula works.

This tool is useful for students studying set theory, Venn diagrams, probability, discrete mathematics, logic, database filtering, and algebraic notation. It is also helpful for teachers who want a clean visual way to show how set operations work.

What is the union of two sets?

The union of two sets is the set of all elements that are in at least one of the sets. If an element is in \(A\), it belongs in the union. If an element is in \(B\), it belongs in the union. If an element is in both \(A\) and \(B\), it still appears only once in the union because sets do not list duplicates.

For example, let:

\[ A=\{1,2,3,4\} \]

and:

\[ B=\{3,4,5,6\} \]

The union is:

\[ A\cup B=\{1,2,3,4,5,6\} \]

The elements \(3\) and \(4\) appear in both sets, but they are not repeated in the final union. The union answers the question: “What elements appear in \(A\), \(B\), or both?”

What is the intersection of two sets?

The intersection of two sets is the set of elements that appear in both sets at the same time. If an element appears only in \(A\), it is not part of the intersection. If an element appears only in \(B\), it is not part of the intersection. It must be shared by both.

Using the same sets:

\[ A=\{1,2,3,4\},\qquad B=\{3,4,5,6\} \]

The intersection is:

\[ A\cap B=\{3,4\} \]

The elements \(3\) and \(4\) are common to both sets. The intersection answers the question: “What do the two sets have in common?” In a Venn diagram, the intersection is the overlapping region between the two circles.

Union versus intersection

The easiest way to remember the difference is that union is broad and intersection is shared. Union includes everything from both sets. Intersection includes only common elements. The words “or” and “and” are very helpful here:

\[ A\cup B:\ x\in A\ \text{or}\ x\in B \]
\[ A\cap B:\ x\in A\ \text{and}\ x\in B \]

In mathematics, “or” is usually inclusive. That means \(x\in A\) or \(x\in B\) includes the case where \(x\) is in both. This is why shared elements are still part of the union. By contrast, “and” requires membership in both sets, so only shared elements appear in the intersection.

Operation Symbol Meaning Example result
Union \(A\cup B\) Elements in \(A\), \(B\), or both. \(\{1,2,3,4,5,6\}\)
Intersection \(A\cap B\) Elements in both \(A\) and \(B\). \(\{3,4\}\)
Difference \(A-B\) Elements in \(A\) but not in \(B\). \(\{1,2\}\)
Symmetric difference \(A\triangle B\) Elements in exactly one of the sets. \(\{1,2,5,6\}\)

Set difference formulas

The difference of two sets finds elements in one set but not the other. The difference \(A-B\), also written \(A\setminus B\), is:

\[ A-B=\{x:x\in A\ \text{and}\ x\notin B\} \]

The difference \(B-A\) is:

\[ B-A=\{x:x\in B\ \text{and}\ x\notin A\} \]

Set difference is not commutative. That means \(A-B\) is not usually the same as \(B-A\). For example, if \(A=\{1,2,3,4\}\) and \(B=\{3,4,5,6\}\), then:

\[ A-B=\{1,2\} \]
\[ B-A=\{5,6\} \]

The order matters because the operation asks what is left in the first set after removing elements found in the second set.

Symmetric difference formula

The symmetric difference of two sets contains elements that appear in exactly one of the sets, but not both. It is written as:

\[ A\triangle B \]

One formula for symmetric difference is:

\[ A\triangle B=(A-B)\cup(B-A) \]

Another equivalent formula is:

\[ A\triangle B=(A\cup B)-(A\cap B) \]

Using \(A=\{1,2,3,4\}\) and \(B=\{3,4,5,6\}\), the symmetric difference is:

\[ A\triangle B=\{1,2,5,6\} \]

The shared elements \(3\) and \(4\) are excluded because they belong to both sets. Symmetric difference is useful when you want items that are unique to one side or the other.

Cardinality of union and intersection

Cardinality means the number of elements in a set. The cardinality of \(A\) is written as \( |A| \). If \(A=\{1,2,3,4\}\), then \( |A|=4 \). If \(B=\{3,4,5,6\}\), then \( |B|=4 \). The union \(A\cup B=\{1,2,3,4,5,6\}\), so \( |A\cup B|=6 \).

The formula is:

\[ |A\cup B|=|A|+|B|-|A\cap B| \]

For the example:

\[ |A\cup B|=4+4-2=6 \]

This formula prevents double counting. The elements in \(A\cap B\) appear in both \(A\) and \(B\), so they are counted twice when \( |A|+|B| \) is calculated. Subtracting the intersection count corrects that.

Worked example: union and intersection

Let:

\[ A=\{red,blue,green,yellow\} \]

and:

\[ B=\{green,yellow,purple,orange\} \]

The union includes all colors that appear in either set:

\[ A\cup B=\{red,blue,green,yellow,purple,orange\} \]

The intersection includes only colors that appear in both sets:

\[ A\cap B=\{green,yellow\} \]

The difference \(A-B\) includes colors in \(A\) but not \(B\):

\[ A-B=\{red,blue\} \]

The difference \(B-A\) includes colors in \(B\) but not \(A\):

\[ B-A=\{purple,orange\} \]

Worked example with numbers

Suppose:

\[ A=\{2,4,6,8,10\} \]

and:

\[ B=\{1,2,3,4,5\} \]

The union is:

\[ A\cup B=\{1,2,3,4,5,6,8,10\} \]

The intersection is:

\[ A\cap B=\{2,4\} \]

The shared elements are \(2\) and \(4\). The elements \(6,8,10\) belong only to \(A\), while \(1,3,5\) belong only to \(B\). Therefore:

\[ A-B=\{6,8,10\},\qquad B-A=\{1,3,5\} \]

The symmetric difference is:

\[ A\triangle B=\{1,3,5,6,8,10\} \]

Union and intersection in Venn diagrams

A Venn diagram is a visual way to show relationships between sets. For two sets \(A\) and \(B\), the diagram usually has two overlapping circles. The left circle represents \(A\), the right circle represents \(B\), and the overlapping region represents \(A\cap B\).

The union \(A\cup B\) is the entire area covered by both circles. It includes the left-only region, the overlap, and the right-only region. The intersection \(A\cap B\) is only the overlapping region. The difference \(A-B\) is the left-only region, and \(B-A\) is the right-only region.

Venn diagrams are especially helpful in probability because events are sets. If \(A\) and \(B\) are events, then \(A\cup B\) means event \(A\), event \(B\), or both happen. The intersection \(A\cap B\) means both events happen.

Union and intersection in probability

Set operations are central to probability. If \(A\) and \(B\) are events in a sample space, then the probability of their union is often calculated using:

\[ P(A\cup B)=P(A)+P(B)-P(A\cap B) \]

This formula is the probability version of the cardinality formula. The intersection is subtracted to avoid double counting. If two events cannot happen at the same time, then \(A\cap B=\varnothing\), and the formula becomes:

\[ P(A\cup B)=P(A)+P(B) \]

For example, when rolling one standard die, the event “roll an even number” is \(A=\{2,4,6\}\). The event “roll a number greater than 4” is \(B=\{5,6\}\). The intersection is \(A\cap B=\{6\}\), and the union is \(A\cup B=\{2,4,5,6\}\).

Disjoint sets

Two sets are disjoint if they have no elements in common. This means their intersection is the empty set:

\[ A\cap B=\varnothing \]

For example:

\[ A=\{1,2,3\},\qquad B=\{4,5,6\} \]

These sets are disjoint because no element appears in both. Their intersection is:

\[ A\cap B=\varnothing \]

The union is still valid:

\[ A\cup B=\{1,2,3,4,5,6\} \]

For disjoint sets, the cardinality formula simplifies because \( |A\cap B|=0 \):

\[ |A\cup B|=|A|+|B| \]

Subset relationships and set operations

If \(A\subseteq B\), then every element of \(A\) is already inside \(B\). In that case, the union and intersection become simpler:

\[ A\cup B=B \]
\[ A\cap B=A \]

For example, if \(A=\{1,2\}\) and \(B=\{1,2,3,4\}\), then \(A\subseteq B\). The union is \(B\), because \(B\) already contains everything in \(A\). The intersection is \(A\), because all elements of \(A\) are shared with \(B\).

This relationship helps students recognize patterns quickly. If one set is fully contained in another, union gives the larger set and intersection gives the smaller set.

Common mistakes with union and intersection

  • Repeating elements in the union. Sets do not list duplicates, so shared elements appear only once.
  • Confusing union and intersection. Union means elements in either set; intersection means elements in both sets.
  • Forgetting the empty set. If there are no shared elements, the intersection is \( \varnothing \), not zero.
  • Thinking \(A-B=B-A\). Set difference is not commutative. The order matters.
  • Double-counting the intersection. In \( |A\cup B|=|A|+|B|-|A\cap B| \), the subtraction is essential.
  • Ignoring case or formatting. In computer-based calculations, “A” and “a” may be treated differently unless case-insensitive comparison is selected.
  • Using list thinking instead of set thinking. A list may contain duplicates and order; a set focuses on unique membership.

The calculator avoids these errors by standardizing the input, removing duplicates when selected, and showing the reasoning behind each result.

Union and intersection properties

Set operations follow important algebra-like properties. The commutative laws say:

\[ A\cup B=B\cup A \]
\[ A\cap B=B\cap A \]

The associative laws say:

\[ (A\cup B)\cup C=A\cup(B\cup C) \]
\[ (A\cap B)\cap C=A\cap(B\cap C) \]

The distributive laws say:

\[ A\cap(B\cup C)=(A\cap B)\cup(A\cap C) \]
\[ A\cup(B\cap C)=(A\cup B)\cap(A\cup C) \]

These laws are used in logic, probability, database queries, Boolean algebra, and proofs. They also show why set theory is closely connected to logical operators: union behaves like “or,” and intersection behaves like “and.”

Union and intersection in databases and filters

Set operations are not only abstract mathematics. They appear in databases, spreadsheets, search filters, and programming. Suppose one list contains students enrolled in Mathematics and another list contains students enrolled in Physics. The union gives all students enrolled in at least one of the two subjects. The intersection gives students enrolled in both subjects.

If \(M\) is the set of Mathematics students and \(P\) is the set of Physics students, then:

\[ M\cup P=\text{students in Mathematics or Physics} \]
\[ M\cap P=\text{students in both Mathematics and Physics} \]

The difference \(M-P\) gives students in Mathematics but not Physics. This same idea applies to customer lists, email segments, tags, search results, course enrollments, and permissions.

Union and intersection summary table

Operation Formula Plain meaning
Union \(A\cup B=\{x:x\in A\text{ or }x\in B\}\) Everything in either set.
Intersection \(A\cap B=\{x:x\in A\text{ and }x\in B\}\) Only shared elements.
Difference \(A-B=\{x:x\in A\text{ and }x\notin B\}\) Elements only in \(A\).
Reverse difference \(B-A=\{x:x\in B\text{ and }x\notin A\}\) Elements only in \(B\).
Symmetric difference \(A\triangle B=(A-B)\cup(B-A)\) Elements in exactly one set.
Union cardinality \(|A\cup B|=|A|+|B|-|A\cap B|\) Counts union without double-counting overlap.

Related calculators and study tools

Union and intersection connect naturally to subsets, power sets, probability, logic, and Venn diagrams. These related tools can help students continue learning set theory and discrete mathematics on NUM8ERS.

Update these internal links if your final NUM8ERS URL structure uses different calculator paths.

Union and Intersection Calculator FAQs

What is the union of two sets?

The union of two sets, written \(A\cup B\), is the set of all elements that appear in \(A\), \(B\), or both.

What is the intersection of two sets?

The intersection of two sets, written \(A\cap B\), is the set of elements that appear in both \(A\) and \(B\).

What is the formula for the cardinality of a union?

The formula is \( |A\cup B|=|A|+|B|-|A\cap B| \). The intersection is subtracted to avoid double counting shared elements.

What does \(A-B\) mean?

\(A-B\) means the set of elements that are in \(A\) but not in \(B\). It is also written as \(A\setminus B\).

What is symmetric difference?

The symmetric difference \(A\triangle B\) contains elements that are in exactly one of the two sets. It can be calculated as \((A-B)\cup(B-A)\).

Are repeated elements counted in set operations?

No. In standard set theory, repeated entries do not create new elements. For example, \(\{1,1,2\}=\{1,2\}\).