Set Calculator - Union, Intersection, and Difference of Sets

Use this calculator to calculate the union, intersection, or difference between two sets. Start by copy-pasting your two sets into the text boxes Data Set #1 and Data Set #2. Then, choose the operation to perform. The result will be displayed in the Output.

Loading...

Make sure you have javascript enabled!

Descriptions of Set Operations

In mathematics, a set operation is a function that takes two sets, or unordered lists, and generates a third list based on a standard operation. These operations are related to, but different from, stardard math operations like addition and subtraction in that they act on the entire list as a whole.

See below for a more detailed description of each operation.

Union

Union of Two Sets

The union of two sets contains all the elements that appear in either of the sets. Another way of thinking about it is to imagine the union as the "sum" of the two sets, set 1 and set 2, excluding any duplicate values.

For example, suppose Mary and Carlos are buying fruits and vegetables at a farmstand. Mary's basket contains:

  • berries,
  • lettuce, and
  • apples

and Carlos's basket contains:

  • lettuce,
  • peppers,
  • onions, and
  • berries

When they get home, together they purchased the following:

  • apples,
  • berries,
  • lettuce,
  • peppers, and
  • onions

This is the union of the two sets!

Try it!

Intersection

Intersection of Two Sets

The intersection of two sets is only the elements that appear in both sets. The most common way to think about this is to visualize the intersecting part of a Venn Diagram. This is the list of items that are shared between the two sets.

For example, suppose you are a teacher and are trying to determine which of your students play multiple sports based on the roster of each team. The tennis team roster contains:

  • Jason,
  • James,
  • Emily, and
  • Robert

while the swim team roster includes:

  • Emily,
  • Jared,
  • Larry, and
  • Rachel

If you want to see which student is shared between the two sports, you determine that the only student that plays multiple sports is:

  • Emily

This is the intersection of the two sets!

Try it!

Difference

Difference of Two Sets

The difference of two sets is all the elements that appear in the first set, except for any elements that appear in the second set. Unlike union and intersection, order matters when determining the difference, as the second set is “subtracted” from the first set.

For example, suppose a teacher is trying to create a list of all their students that are in math courses except for any students that are currently taking geometry. She can use the difference of two sets to identify the list of students. The full list of students taking math courses is:

  • Stacy,
  • Matthew,
  • Jon,
  • Caroline

and the list of students taking geometry are:

  • Stacy, and
  • Matthew

Thus, the list of students she wants is:

  • Caroline, and
  • Jon

This is the difference of two sets!

Try it!