Set Operations Calculator – Union, Intersection, Difference & Complement of Sets and Intervals
Choose a mode: sets listed element by element (with a Venn diagram) or intervals and rays on the real line ℝ (with shaded number lines). Step-by-step solutions follow the grade 10 curriculum.
The calculator above performs the basic operations of set theory on two sets of real numbers: union, intersection, set difference (relative complement) and complement. It has two modes:
- Discrete Elements & Venn: enter the elements of two finite sets in roster form (integers, decimals or fractions). The tool removes duplicates, sorts each set, draws a Venn diagram and writes a five-step solution.
- Intervals & Number Line: enter subsets of the real line in interval notation, such as [−4, 1] or [1, +∞), and pick A ∩ B, A ∪ B, A \ B, B \ A, Aᶜ or Bᶜ. The tool plots three shaded number lines and explains the answer in four steps.
Sets, elements and roster notation
A set is a well-defined collection of distinct objects called elements. We write a ∈ A when a is an element of A and a ∉ A when it is not. A set can be described in two ways:
- Roster notation lists the elements between braces, for example A = {−3, 0, 1.5, 2}. Each element is listed once, and order does not matter.
- Set-builder notation states a defining property, for example B = {x ∈ ℤ | −2 ≤ x < 3}.
The set with no elements is the empty set ∅. The number of elements of a finite set A is its cardinality, written n(A) or |A|.
Subsets and equal sets
A is a subset of B, written A ⊆ B, when every element of A is also an element of B:
Two sets are equal when A ⊆ B and B ⊆ A. For every set A, ∅ ⊆ A and A ⊆ A.
Basic set operations
Intersection (A ∩ B)
The intersection of A and B is the set of elements that belong to both A and B:
If A ∩ B = ∅, the sets are disjoint.
Union (A ∪ B)
The union of A and B is the set of elements that belong to A or to B (or to both). Common elements are written once:
Set difference / relative complement (A \ B)
The difference A \ B, also called the relative complement of B in A, is the set of elements of A that are not in B. Some textbooks write it A − B:
Set difference is not commutative: in general A \ B ≠ B \ A.
Complement
All sets in a problem are usually taken inside a universal set U. The (absolute) complement of A is the set of elements of U that are not in A:
When B ⊆ A, the difference A \ B is the complement of B in A, sometimes written CAB. If you do not choose a universal set, the calculator uses U = A ∪ B, so Aᶜ = B \ A and Bᶜ = A \ B.
Venn diagram representation
A Venn diagram draws the universal set U as a rectangle and each set as a closed region inside it. Two overlapping circles split U into four regions, one for each basic operation:
- A only (blue): the elements of A \ B.
- The overlap (blended color): the elements of A ∩ B.
- B only (orange): the elements of B \ A.
- Outside both circles: the elements of U not in A ∪ B, that is (A ∪ B)ᶜ.
The union is everything inside the two circles. The diagram makes it clear that A \ B, A ∩ B and B \ A are pairwise disjoint and together form A ∪ B.
The inclusion–exclusion principle
Adding n(A) and n(B) counts every element of A ∩ B twice, so it must be subtracted once:
Example: in a class, 25 students like math, 20 like literature and 10 like both. Then 25 + 20 − 10 = 35 students like at least one of the two subjects.
Key laws of set algebra
- Commutative laws: A ∩ B = B ∩ A, A ∪ B = B ∪ A.
- Identity laws: A ∩ ∅ = ∅, A ∪ ∅ = A, A \ ∅ = A.
- If B ⊆ A, then A ∩ B = B and A ∪ B = A.
- De Morgan’s laws: (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ and (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ.
- Difference as an intersection: A \ B = A ∩ Bᶜ.
4 worked examples
Press Example in the calculator or type the same elements to check every step.
Example 1. Two overlapping sets
Let A = {−3, 0, 1.5, 2, 5, 8} and B = {0, 2, 4, 5, 9, 10}. Find A ∩ B, A ∪ B, A \ B and B \ A.
The common elements are 0, 2 and 5, so A ∩ B = {0, 2, 5}. Combining both sets and listing common elements once:
Check: n(A ∪ B) = 6 + 6 − 3 = 9. Removing the common elements from each set gives A \ B = {−3, 1.5, 8} and B \ A = {4, 9, 10}.
Example 2. Complement of a subset
Let A = {1, 2, 3, 4, 5, 6} and B = {2, 4, 6}. Show that B ⊆ A and find the complement of B in A.
Each element 2, 4, 6 of B is in A, so B ⊆ A. Hence A ∩ B = B, A ∪ B = A, B \ A = ∅, and:
In the Venn diagram, the region “B only” is empty.
Example 3. Complements in a universal set and De Morgan’s law
Let U = {0, 1, 2, …, 9}, let A be the even numbers and B the multiples of 3 in U: A = {0, 2, 4, 6, 8}, B = {0, 3, 6, 9}. Find Aᶜ and Bᶜ and verify De Morgan’s law.
We have A ∩ B = {0, 6} and A ∪ B = {0, 2, 3, 4, 6, 8, 9}. The complements in U are:
Their intersection is {1, 5, 7}, exactly the elements of U outside both circles: (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ = {1, 5, 7}.
Example 4. Fractions, decimals and duplicates
Enter A = {−2.5, 1/2, 3, 0.5, 7} and B = {0.5, 3, 4, −1}.
Since 0.5 = 1/2, A really has four elements: A = {−2.5, 1/2, 3, 7}, n(A) = 4. Sorting B gives B = {−1, 0.5, 3, 4}, n(B) = 4. Therefore:
Check: n(A ∪ B) = 4 + 4 − 2 = 6. The differences are A \ B = {−2.5, 7} and B \ A = {−1, 4}.
Subsets of the real line: intervals and rays
Many sets of real numbers are written in interval notation. For real numbers a < b:
| Name | Notation | Set-builder form | Endpoints |
|---|---|---|---|
| Open interval | (a, b) | {x ∈ ℝ | a < x < b} | Neither a nor b |
| Closed interval | [a, b] | {x ∈ ℝ | a ≤ x ≤ b} | Both a and b |
| Half-open interval | [a, b) | {x ∈ ℝ | a ≤ x < b} | a only |
| Half-open interval | (a, b] | {x ∈ ℝ | a < x ≤ b} | b only |
| Open ray | (a, +∞) | {x ∈ ℝ | x > a} | a excluded |
| Closed ray | [a, +∞) | {x ∈ ℝ | x ≥ a} | a included |
| Open ray | (−∞, b) | {x ∈ ℝ | x < b} | b excluded |
| Closed ray | (−∞, b] | {x ∈ ℝ | x ≤ b} | b included |
| Real line | (−∞, +∞) = ℝ | All real x | None |
Infinity is not a real number, so the −∞ and +∞ ends always take a parenthesis: write [1, +∞), never [1, +∞]. Some textbooks (for example in Vietnam) separate the endpoints with a semicolon, [a; b], and some European books write ]a, b[ for an open interval; the calculator accepts all of these. Type infinity as +inf, -inf, +oo, -oo or use the +∞ and −∞ keys.
Plotting a set on the number line
- Draw a horizontal number line with the arrow pointing right (towards +∞) and mark the endpoints in increasing order.
- Use a square bracket [ or ] at an included endpoint (≤ or ≥) and a parenthesis ( or ) at an excluded endpoint (< or >). The bracket faces the part that is kept.
- Shade out regions not in the set with diagonal hatching ////. The unshaded part is the set.
For an operation on two sets, draw the lines for A and B one above the other, then a third line for the result. The intersection is the part left unshaded on both lines; the union is the part left unshaded on at least one line. (Some textbooks shade the part that belongs to the set instead; this tool follows the convention of shading out what is removed, so the answer stays clean.)
Operations on real intervals
- Intersection A ∩ B: the left endpoint is the larger left endpoint and the right endpoint is the smaller right endpoint. An endpoint is included when it belongs to both A and B. If the left end passes the right end, A ∩ B = ∅.
- Union A ∪ B: if A and B overlap or touch (like (−2, 4] and [4, 7]), merge them into one interval from the smallest left endpoint to the largest right endpoint; otherwise keep the union of two pieces. An endpoint is included when it belongs to A or to B.
- Difference A \ B: remove from A the part it shares with B, i.e. A \ B = A ∩ Bᶜ. At each cut point the bracket flips: an endpoint that belongs to B (square bracket) is removed and becomes a parenthesis; an endpoint not in B (parenthesis) is kept and becomes a square bracket.
- Complement Aᶜ = CℝA = ℝ \ A: take the parts of the line outside A and flip every bracket. For a < b:
Worked examples with intervals
Switch the calculator to Intervals & Number Line, enter the sets below and pick the matching operation to see the three number lines and the four-step solution.
Example 5. Intersection and union of two intervals
Let A = [−4, 1] and B = [0, 3). Find A ∩ B and A ∪ B.
In set-builder form, A = {x ∈ ℝ | −4 ≤ x ≤ 1} and B = {x ∈ ℝ | 0 ≤ x < 3}. The endpoints in order are −4 < 0 < 1 < 3. The intersection runs from max(−4, 0) = 0 to min(1, 3) = 1, and both 0 and 1 are in A and in B, so both brackets are square:
The intervals overlap, so the union is a single half-open interval; 3 is in neither set, so it keeps its parenthesis.
Example 6. Set difference and the bracket-flip rule
Let A = [−3, 5) and B = (1, 2]. Find A \ B and B \ A.
The complement of B is Bᶜ = (−∞, 1] ∪ (2, +∞). Removing B from A:
At 1, B is open, so 1 ∉ B: the point 1 stays and gets a square bracket. At 2, 2 ∈ B, so it is removed and gets a parenthesis. Every number in B is in A (B ⊆ A), so B \ A = ∅.
Example 7. Complements of rays and a disjoint union
Let A = [1, +∞) and B = (−∞, 0). Find Aᶜ, Bᶜ and A ∪ B.
Flipping the brackets gives Aᶜ = (−∞, 1) and Bᶜ = [0, +∞). There is a gap [0, 1) between B and A, so the union cannot be merged:
Practice problems
- Interval notation. Write A = {x ∈ ℝ | −2 < x ≤ 5} and B = {x ∈ ℝ | x ≥ 3} as intervals. Answer: A = (−2, 5], B = [3, +∞).
- Intersection and union. A = (−∞, 3), B = [−1, 6]. Answer: A ∩ B = [−1, 3), A ∪ B = (−∞, 6].
- Difference. A = [0, 8], B = (2, 5). Answer: A \ B = [0, 2] ∪ [5, 8], B \ A = ∅.
- Complement. A = (−3, 4]. Answer: Aᶜ = (−∞, −3] ∪ (4, +∞).
- Parameter for A ⊆ B. A = [m, m + 2], B = (1, 5). A ⊆ B when 1 < m and m + 2 < 5, that is 1 < m < 3.
- Parameter for A ∩ B ≠ ∅. A = (−∞, m), B = [2, +∞). A ∩ B ≠ ∅ exactly when m > 2.
Enter problems 2, 3 and 4 in the calculator to check the answers and see how each number line is shaded.
Common mistakes
- Listing a common element twice in A ∪ B. Every element of a set appears only once.
- Confusing A \ B with B \ A. A \ B starts from A and removes the elements that are also in B.
- Taking a complement without a universal set. Aᶜ only makes sense relative to a stated universal set U.
- Treating 0.5 and 1/2 as different elements. They are the same real number.
- Forgetting the empty set. If two sets share no element, the answer is A ∩ B = ∅, which still is a set.
- Closing a bracket at infinity, as in [1, +∞]. Infinity is not a number, so it always takes a parenthesis.
- Forgetting to flip brackets in a complement or difference. [a, b)ᶜ = (−∞, a) ∪ [b, +∞), not (−∞, a] ∪ (b, +∞).
- Merging intervals that only nearly touch. [1, 2) ∪ (2, 3] is not [1, 3], because 2 belongs to neither piece.
🎯 Practice quiz: union, intersection, difference and complement of sets
Twelve multiple-choice questions with four options each, following the theory above section by section: the symbols ∈ and ⊆, intersection and difference of finite sets, complements in a universal set, inclusion–exclusion, interval notation, intersection, union, difference and complement of intervals, De Morgan's laws and a parameter problem. Pick an answer: the correct option turns green, a wrong one turns red, and the solution appears right below with a ⚠️ Trap note explaining why the distractors are tempting. You can enter the sets from any question into the calculator above to check them on a Venn diagram or number line.
1️⃣ The symbols ∈ and ⊆ Question 1. Let A = {1, 2, 3}. Which statement is true:
Correct answer: C. {1, 2} ⊆ A
The symbol ∈ links an element to a set, while ⊆ links two sets. Both elements 1 and 2 of the set {1, 2} belong to A, so:
The correct versions of the other three options are 1 ∈ A, {1} ⊆ A and ∅ ⊆ A.
⚠️ Trap
- A: 1 is a number, that is, an element, so write 1 ∈ A.
- B: {1} is a set with one element, so write {1} ⊆ A. The elements of A are 1, 2 and 3; none of them is the set {1}.
- D: the empty set is a subset of every set (∅ ⊆ A), but it is not an element of A.
2️⃣ Intersection of two finite sets Question 2. Let A = {0, 1, 2, 3, 4} and B = {2, 3, 4, 5, 6}. The set A ∩ B is:
Correct answer: A. {2, 3, 4}
A ∩ B contains the elements that belong to both A and B. Going through A: 0 and 1 are not in B, while 2, 3 and 4 are, so:
Check with inclusion–exclusion: n(A ∪ B) = 5 + 5 − 3 = 7, exactly the number of elements of {0, 1, 2, 3, 4, 5, 6}. Enter both sets in the Discrete Elements & Venn mode above to see 2, 3 and 4 in the overlap.
⚠️ Trap
- B: this is the union A ∪ B, the elements in A or in B.
- C: this is the difference A \ B, the part in A only.
- D: these are the elements in exactly one of the two sets, the two outer regions of the Venn diagram, the opposite of the overlap.
3️⃣ The difference B \ A Question 3. Let A = {−2, 0, 1, 3, 5} and B = {0, 3, 4, 6}. The set B \ A is:
Correct answer: D. {4, 6}
B \ A contains the elements that are in B but not in A, so start from B. Of its four elements, 0 and 3 are in A and are removed; 4 and 6 are not in A and stay:
Check: n(B \ A) = n(B) − n(A ∩ B) = 4 − 2 = 2.
⚠️ Trap
- A: this is A \ B. Set difference is not commutative, so read carefully which set comes before the backslash.
- B: this is A ∩ B, exactly the part removed from B.
- C: this combines A \ B and B \ A, the elements in exactly one of the two sets.
4️⃣ Complement in a universal set Question 4. Let U = {x ∈ ℤ | 0 ≤ x < 10}, the whole numbers below 10, and let A be the set of prime numbers in U. The complement Aᶜ of A in U is:
Correct answer: B. {0, 1, 4, 6, 8, 9}
List the universal set first: U = {0, 1, 2, …, 9}, n(U) = 10. A prime number is a whole number greater than 1 whose only divisors are 1 and itself, so A = {2, 3, 5, 7}. Remove the elements of A from U:
Check: n(Aᶜ) = 10 − 4 = 6.
⚠️ Trap
- A: 0 is missing, although U starts at 0.
- C: treats 1 as a prime. The number 1 has only one divisor, so it is not prime and belongs to the complement.
- D: makes both mistakes. A quick check: the complement must have 10 − 4 = 6 elements.
5️⃣ Inclusion–exclusion Question 5. A class of 40 students has 25 students who like football, 18 who like basketball and 7 who like neither sport. How many students like both sports:
Correct answer: C. 10
Let A and B be the sets of students who like football and basketball. The number who like at least one sport is n(A ∪ B) = 40 − 7 = 33. By inclusion–exclusion:
Check with a Venn diagram: football only 15, basketball only 8, both 10, neither 7; in total 15 + 8 + 10 + 7 = 40.
⚠️ Trap
- A: takes n(A ∪ B) = 40 and forgets the 7 students outside both circles, giving 25 + 18 − 40 = 3.
- B: 25 + 18 = 43 is n(A) + n(B), which counts the overlap twice; it is even larger than the class.
- D: 33 is the number who like at least one sport, n(A ∪ B), not the overlap.
6️⃣ Interval notation Question 6. In interval notation, the set {x ∈ ℝ | −3 < x ≤ 5} is written as:
Correct answer: D. (−3, 5]
Read each endpoint: at −3 the sign is < (strict), so −3 is excluded and takes a parenthesis; at 5 the sign is ≤, so 5 is included and takes a square bracket. This is a half-open interval:
⚠️ Trap
- A: both brackets are reversed; this is the set −3 ≤ x < 5.
- B: excludes 5, although ≤ allows x = 5.
- C: includes −3, although < does not allow x = −3.
7️⃣ Intersection of two intervals Question 7. Let A = [−1, 4) and B = (2, +∞). The set A ∩ B is:
Correct answer: A. (2, 4)
The left endpoint of the intersection is max(−1, 2) = 2 and the right endpoint is min(4, +∞) = 4. An endpoint is included only when it belongs to both A and B: 2 ∉ B and 4 ∉ A, so both ends take parentheses:
Intersecting intervals like this comes up constantly when solving a system of inequalities in one variable or finding the domain of a function. Enter A and B in the Intervals & Number Line mode to see the part left unshaded on both number lines.
⚠️ Trap
- B: this is the union A ∪ B: the intervals overlap, so they merge from −1 to +∞.
- C: 4 is in B but not in A, so it is not in the intersection.
- D: 2 is in A but not in B (B is open at 2), so it is not in the intersection either.
8️⃣ Union of two adjacent intervals Question 8. Let A = (−∞, 1] and B = (1, 6). The set A ∪ B is:
Correct answer: B. (−∞, 6)
The two sets touch at 1: the number 1 is in A (square bracket) and the numbers just above 1 are in B, so there is no gap on the number line. They merge into one interval from −∞ to 6:
6 is in neither set, so it keeps its parenthesis. Note that A ∩ B = ∅ (the sets are disjoint), yet their union is still a single interval.
⚠️ Trap
- A: drops the number 1. Since 1 ∈ A, 1 ∈ A ∪ B. Only if A were (−∞, 1) would the union have to be split like this (compare mistake 8 in the Common mistakes list).
- C: ∅ is the intersection A ∩ B, not the union.
- D: 6 is in neither set, so it cannot take a square bracket.
9️⃣ Difference of intervals and the bracket-flip rule Question 9. Let A = [−2, 6] and B = [1, 3). The set A \ B is:
Correct answer: C. [−2, 1) ∪ [3, 6]
The complement of B is Bᶜ = (−∞, 1) ∪ [3, +∞). Removing from A the part it shares with B:
At 1: 1 ∈ B, so it is removed and gets a parenthesis. At 3: 3 ∉ B, so it is kept and gets a square bracket. Pick A \ B in the Intervals & Number Line mode to see the three number lines for this problem.
⚠️ Trap
- A: copies the brackets of B into the answer without flipping them: 1 ∈ B is wrongly kept and 3 ∉ B is wrongly removed.
- B: [1, 3) is A ∩ B (equal to B, since B ⊆ A), exactly the part that is removed.
- D: flips the bracket at 1 correctly but forgets that 3 is not in B, so it still belongs to A \ B.
🔟 Complement of a half-open interval Question 10. The complement [−3, 2)ᶜ of the half-open interval [−3, 2) in ℝ is:
Correct answer: A. (−∞, −3) ∪ [2, +∞)
The complement contains the real numbers not in [−3, 2), that is x < −3 or x ≥ 2. Every bracket flips: −3 belongs to the original set, so it is excluded (parenthesis); 2 does not belong to it, so it is in the complement (square bracket):
Check with x = 2: 2 ∉ [−3, 2), so 2 must be in the complement, which matches the square bracket at 2.
⚠️ Trap
- B: forgets to flip the brackets, mistake 7 in the Common mistakes list.
- C: flips the brackets but keeps the part between −3 and 2; the complement is the part of the line outside the given set.
- D: closes the bracket at +∞. Infinity is not a number, so it always takes a parenthesis.
1️⃣1️⃣ De Morgan's laws Question 11. Let U = {1, 2, 3, 4, 5, 6, 7, 8}, A = {1, 2, 3, 4} and B = {3, 4, 5, 6}. The set Aᶜ ∪ Bᶜ is:
Correct answer: D. {1, 2, 5, 6, 7, 8}
Find each complement: Aᶜ = {5, 6, 7, 8} and Bᶜ = {1, 2, 7, 8}. Their union is {1, 2, 5, 6, 7, 8}. By De Morgan’s law, this is exactly the complement of the intersection:
The second route is quicker: find A ∩ B = {3, 4}, then take its complement in U.
⚠️ Trap
- A: {7, 8} is Aᶜ ∩ Bᶜ = (A ∪ B)ᶜ: the union was mistaken for an intersection.
- B: {3, 4} is A ∩ B itself; the complement was never taken.
- C: misses 7 and 8, which lie outside both circles of the Venn diagram but still belong to U.
1️⃣2️⃣ A parameter for a nonempty intersection Question 12. Let A = (−∞, m] and B = (3, +∞). A necessary and sufficient condition for A ∩ B ≠ ∅ is:
Correct answer: B. m > 3
A ∩ B ≠ ∅ when some real number x satisfies both x ≤ m and x > 3, that is 3 < x ≤ m. This happens exactly when:
When m > 3, the number x = m itself lies in both A and B. When m = 3, A = (−∞, 3] and B = (3, +∞): 3 is in A but not in B, so A ∩ B = ∅.
⚠️ Trap
- A: the case m = 3 was not checked separately. A shared endpoint belongs to the intersection only if it is in both sets, and B is open at 3.
- C: for m < 3, A lies entirely to the left of B, so A ∩ B = ∅.
- D: m ≤ 3 is the condition for A ∩ B = ∅, the opposite of what is asked.
Frequently asked questions
What is the difference between union and intersection?
The intersection A ∩ B contains only the elements that are in both A and B. The union A ∪ B contains every element that is in A or in B, with common elements listed once. The intersection is always a subset of the union.
Is A \ B the same as B \ A?
Not in general. A \ B is the set of elements of A that are not in B, while B \ A is the set of elements of B that are not in A. They are equal only when A = B, in which case both are empty.
What is the difference between a relative complement and an absolute complement?
The relative complement of B in A is A \ B, the elements of A outside B. The absolute complement of A, written Aᶜ or A′, is U \ A, taken relative to a universal set U. Without a stated U, the calculator uses U = A ∪ B.
How do you find the number of elements in A ∪ B?
Use the inclusion–exclusion principle: n(A ∪ B) = n(A) + n(B) − n(A ∩ B). The common elements are counted twice when you add n(A) and n(B), so they are subtracted once. The calculator checks every union with this formula.
Can I enter fractions and decimals?
Yes. The calculator accepts integers, decimals such as -2.5 and fractions such as 1/2 or -3/4. Equal values such as 0.5 and 1/2 are treated as one element, and every set is sorted in increasing order.
What is the difference between open, closed and half-open intervals?
An open interval (a, b) excludes both endpoints, a closed interval [a, b] includes both, and a half-open interval [a, b) or (a, b] includes exactly one. On a number line a square bracket includes the endpoint, a parenthesis excludes it, and the infinite end of a ray always takes a parenthesis.
How do you find the complement of an interval?
The complement Aᶜ = ℝ \ A contains the real numbers not in A: take the parts of the line outside A and flip every bracket, for example [−4, 1]ᶜ = (−∞, −4) ∪ (1, +∞). The Intervals & Number Line mode computes complements and plots them on a number line.