Set Operations, Explained

After reading this you can compute the union, intersection, both differences, the symmetric difference and the power set of two sets, and you will know how to read each result without confusing "and" with "or".

A set is a collection of distinct items with no order. The set {1, 2, 3, 4} is the same as {4, 3, 2, 1}, and writing 2 twice changes nothing: {2, 2, 3} is just {2, 3}. Set operations combine two collections in the four standard ways, and each one answers a different plain-language question about membership.

Here is the hook. Take A = {1, 2, 3, 4} and B = {3, 4, 5, 6}. The union has 6 elements, the intersection has 2, and the two differences have 2 elements each. Six numbers, four answers, no overlap in what they mean. The rest of this article shows how those counts arise and how to interpret them.

What each operation means

There are four core operations plus the power set. Each is defined by a membership rule, so you decide whether an element belongs by answering a yes or no question.

Union A \cup B
Everything in A, or in B, or in both. The "or" here is inclusive.
Intersection A \cap B
Only the elements that are in both A and B at the same time.
Difference A \setminus B
Elements in A that are not in B. Order matters: A \setminus B and B \setminus A are usually different.
Symmetric difference A \triangle B
Elements in exactly one of the two sets, never in both. This is the "or, but not both" case, the exclusive or.
Power set \mathcal{P}(A)
The set of all subsets of A, including the empty set and A itself.

Union corresponds to the word or, intersection to and, and symmetric difference to exclusive or. If you have used a truth table generator, these are the same three connectives applied to membership instead of truth values.

When to use this, and when not

Reach for set operations when you have two lists and you care about membership, not counts or order. Which customers appear in both mailing lists? That is intersection. Which items are in the new inventory but were not in the old one? That is a difference. Which tags belong to exactly one of two articles? That is symmetric difference.

Do not use a set when duplicates carry information. If you are tracking how many times each value occurs, a set will collapse the repeats and lose the counts. A list of the numbers 3, 3, 3, 5 becomes the set {3, 5}, and the fact that 3 appeared three times is gone. For frequency work you want a tally or a multiset, not a set.

Order is also discarded. If sequence matters, for example the steps of a route, a set is the wrong container.

The formulas and the intuition

The four core operations are defined by membership conditions on an element x.

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

Read this as: x is in the union exactly when x is in A or in B. An element counted once, even if it sits in both sets.

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

Here x must pass both tests. If either fails, x is out.

A \setminus B = \{\, x : x \in A \ \text{and}\ x \notin B \,\}

x \in A means x is an element of A, and x \notin B means x is not an element of B. Swap the letters and you get the other difference.

The sizes are linked by one identity worth memorizing. Let |A| denote the number of elements in A.

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

You subtract the intersection because elements in both sets would otherwise be counted twice. This is inclusion-exclusion for two sets. Check it against the hook: 4 + 4 - 2 = 6, which matches the union size.

The power set has a fixed size that depends only on how many elements the set has.

|\mathcal{P}(A)| = 2^{|A|}

Each element is either in a given subset or not, two choices per element, multiplied across all elements. A set of 4 elements has 2^4 = 16 subsets. A set of 10 has 1024. This growth is why the power set is only practical for small sets.

With A = {1, 2, 3, 4} and B = {3, 4, 5, 6}: union {1, 2, 3, 4, 5, 6}, intersection {3, 4}, A \setminus B = \{1, 2\}, B \setminus A = \{5, 6\}, symmetric difference {1, 2, 5, 6}.

Worked example with the demo data

A = {1, 2, 3, 4}, B = {3, 4, 5, 6}

These are the values behind the Demo button. Work through each result by checking membership element by element.

  1. Intersection. Which numbers are in both? Only 3 and 4. So A \cap B = \{3, 4\}, size 2.
  2. Union. List everything once: 1, 2, 3, 4, 5, 6. So A \cup B = \{1, 2, 3, 4, 5, 6\}, size 6. Confirm with inclusion-exclusion: 4 + 4 - 2 = 6.
  3. A minus B. Keep the elements of A not in B: drop 3 and 4, leaving A \setminus B = \{1, 2\}.
  4. B minus A. Keep the elements of B not in A: drop 3 and 4, leaving B \setminus A = \{5, 6\}.
  5. Symmetric difference. Combine the two differences: \{1, 2\} \cup \{5, 6\} = \{1, 2, 5, 6\}, size 4. Notice the middle values 3 and 4 are absent.

The counts add up cleanly: symmetric difference size (4) plus twice the intersection size (2) equals the union size plus intersection size, and every number lands in exactly one of the three Venn regions.

The three region counts on the left (2, 2, 2) determine every operation on the right. Union adds all three, intersection is the shared bar, symmetric difference is the two outer bars.

Reading the results

Every output is itself a set, so treat it as unordered and duplicate-free. Three checks help you trust a result quickly.

First, the union size can never exceed |A| + |B| and can never be less than the larger of the two sizes. Here that is between 4 and 8, and 6 fits. Second, the intersection is a subset of both sets, so its size can never exceed the smaller input, here min(4, 4) = 4, and 2 fits. Third, the two differences and the intersection partition each input: |A \setminus B| + |A \cap B| = |A|, and indeed 2 + 2 = 4.

For subset tests, remember that every set is a subset of itself and the empty set is a subset of everything. If A \cap B = A, then A is a subset of B. In the demo data the intersection is {3, 4}, not equal to A, so neither set is a subset of the other.

Common mistakes

The difference is not symmetric. A \setminus B = \{1, 2\} but B \setminus A = \{5, 6\}. If you swap the two input lists, the two differences swap, so always confirm which set is playing the role of A.

A second trap is confusing intersection with symmetric difference. Intersection keeps what is common, {3, 4}. Symmetric difference keeps what is not common, {1, 2, 5, 6}. They are complements of each other inside the union, so together they rebuild it.

A third trap is treating repeated entries as separate. If you type 1, 1, 2 the tool reads the set {1, 2}. The count is 2, not 3. If your data genuinely has repeats that matter, a set is not the right model.

Finally, watch the item type. The strings "3" and the number 3 may or may not be treated as equal depending on how you enter them. Keep both lists in the same format, all numbers or all words, so that matching behaves the way you expect.

Related tools

Set logic connects to several other topics on this site. The truth table generator handles the propositional versions of "and", "or" and "exclusive or". When your sets are ranges of primes, the prime number tools generate the members for you. For number-theoretic sets defined by remainders, the congruence solver finds which integers satisfy a system, and the linear Diophantine equations page describes the full solution set of ax + by = c. If your elements are written in another base, convert them first with base-N arithmetic so the matching is done on comparable values.

Frequently asked questions

Is the union of two sets ever smaller than either set?

No. The union contains every element of both, so its size is at least the size of the larger input. For the demo data the union has 6 elements, which is larger than either input of 4.

What is the difference between intersection and symmetric difference?

Intersection keeps elements in both sets, {3, 4}. Symmetric difference keeps elements in exactly one set, {1, 2, 5, 6}. Together they form the whole union with no overlap.

Why does the power set have 2 to the n subsets?

For each of the n elements you make an independent yes or no choice: in the subset or out. That is 2 \times 2 \times \cdots with n factors, which is 2^n. A 4-element set gives 16 subsets, a 20-element set gives over a million, which is why power sets stay small in practice.

Does the empty set count as a subset?

Yes. The empty set is a subset of every set, and it always appears in the power set. So does the set itself. A 3-element set therefore has 8 subsets, ranging from the empty set to the full set.

Are duplicate entries an error?

They are not rejected, but they are collapsed. Typing 2, 2, 3 produces the set {2, 3} with 2 elements. If your data relies on how many times a value repeats, use a frequency tally instead.