Skip to main content

Union and Intersection Calculator

Calculate union intersection instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods.

Skip to calculator
Mathematics

Union and Intersection Calculator

Calculate union, intersection, difference, and symmetric difference of two sets. Find Jaccard similarity, verify the Inclusion-Exclusion Principle, and analyze set relationships.

Last updated: December 2025Reviewed by NovaCalculator Mathematics Team

Calculator

Adjust values & calculate
A U B (Union)
{ 1, 2, 3, 4, 5, 6, 7 }
7 elements
A n B (Intersection)
{ 3, 4, 5 }
3 elements
A - B (Difference)
{ 1, 2 }
B - A (Difference)
{ 6, 7 }
Symmetric Difference (A delta B)
{ 1, 2, 6, 7 }
|A|
5
|B|
5
Jaccard Similarity
0.4286
Inclusion-Exclusion Check
5 + 5 - 3 = 7
Set Relationships
Disjoint: No (sets share elements)
A subset of B: No
B subset of A: No
Equal sets: No
Your Result
Union: { 1, 2, 3, 4, 5, 6, 7 } (7 elements) | Intersection: { 3, 4, 5 } (3 elements)
Share Your Result
Understand the Math

Formula

|A U B| = |A| + |B| - |A n B|

The Inclusion-Exclusion Principle: the size of the union equals the sum of individual set sizes minus the size of the intersection. This avoids double-counting elements that appear in both sets.

Last reviewed: December 2025

Worked Examples

Example 1: Numeric Set Operations

Find the union, intersection, and differences of A = {1, 2, 3, 4, 5} and B = {3, 4, 5, 6, 7}.
Solution:
A U B = {1, 2, 3, 4, 5, 6, 7} (all unique elements) A n B = {3, 4, 5} (common elements) A - B = {1, 2} (in A but not B) B - A = {6, 7} (in B but not A) Symmetric Difference = {1, 2, 6, 7} Verify: |A U B| = 7 = |A| + |B| - |A n B| = 5 + 5 - 3 = 7
Result: Union: 7 elements, Intersection: 3 elements, Jaccard Similarity: 3/7 = 0.4286

Example 2: Disjoint Sets Example

Find operations for A = {a, b, c} and B = {x, y, z}.
Solution:
A U B = {a, b, c, x, y, z} A n B = {} (empty set - no common elements) A - B = {a, b, c} = A B - A = {x, y, z} = B Symmetric Difference = {a, b, c, x, y, z} = A U B |A U B| = 6 = 3 + 3 - 0
Result: Sets are disjoint. Union has 6 elements. Intersection is empty. Jaccard Similarity: 0.
Expert Insights

Background & Theory

The Union and Intersection Calculator applies the following established principles and formulas. Mathematics rests on a hierarchy of number systems, each extending the previous. The natural numbers (1, 2, 3, ...) support counting and ordering. The integers add negative values and zero, enabling subtraction without restriction. The rational numbers, expressible as p/q where p and q are integers and q is nonzero, close the system under division. The real numbers fill the gaps left by irrationals such as the square root of 2 or pi, forming a complete ordered field. The complex numbers, written as a + bi where i is the square root of negative one, complete the algebraic closure of the reals and allow every polynomial to have a root. Prime factorization states that every integer greater than one is uniquely expressible as a product of primes, a result known as the Fundamental Theorem of Arithmetic. Computing the greatest common divisor (GCD) of two integers relies most efficiently on the Euclidean algorithm: repeatedly replace the larger number with the remainder when it is divided by the smaller, until the remainder is zero. The last nonzero remainder is the GCD. The least common multiple (LCM) follows from the identity LCM(a, b) = |a * b| / GCD(a, b). Modular arithmetic defines equivalence classes of integers that share the same remainder under division by a modulus n. Fermat's Little Theorem and Euler's Theorem arise from this structure and underpin modern cryptography. Logarithms are the inverses of exponential functions. If b raised to the power x equals y, then the logarithm base b of y equals x. The natural logarithm uses base e, approximately 2.71828. Combinatorics counts arrangements and selections. The number of ordered arrangements (permutations) of r objects from n distinct objects is nPr = n! / (n - r)!. The number of unordered selections (combinations) is nCr = n! / (r! * (n - r)!). Pascal's triangle arranges these binomial coefficients so that each entry equals the sum of the two entries directly above it. The Fibonacci sequence, defined by F(1) = 1, F(2) = 1, and F(n) = F(n-1) + F(n-2), appears throughout nature and connects deeply to the golden ratio via Binet's formula.

History

The history behind the Union and Intersection Calculator traces back through the following developments. Mathematics as a systematic discipline traces to ancient Mesopotamia. Babylonian clay tablets dating to around 1800 BCE demonstrate knowledge of quadratic equations, Pythagorean triples, and base-60 arithmetic, suggesting a practical mathematical tradition far preceding Greek formalism. Euclid of Alexandria compiled the Elements around 300 BCE, establishing the axiomatic method that would define rigorous mathematics for over two thousand years. His work organized plane geometry, number theory, and proportion into logically chained propositions derived from a small set of postulates. The algorithm bearing his name for computing GCDs appears in Book VII and remains in use today. In the 9th century, the Persian scholar Muhammad ibn Musa Al-Khwarizmi wrote Al-Kitab al-mukhtasar fi hisab al-jabr wal-muqabala, the treatise whose title gave algebra its name. He systematized the solution of linear and quadratic equations and described procedures that operated on unknowns as objects, a conceptual leap away from purely numerical calculation. Rene Descartes introduced coordinate geometry in 1637 by uniting algebra and Euclidean geometry, allowing curves to be studied through equations. This synthesis set the stage for calculus. Isaac Newton and Gottfried Wilhelm Leibniz independently developed calculus during the 1660s and 1670s, triggering a priority dispute that lasted decades and divided British and Continental mathematicians. Carl Friedrich Gauss proved the Fundamental Theorem of Algebra in 1799, showing that every nonconstant polynomial has at least one complex root. His Disquisitiones Arithmeticae of 1801 established modern number theory. David Hilbert's formalist program at the turn of the 20th century sought to place all of mathematics on an explicit axiomatic foundation, a project that Kurt Godel's incompleteness theorems of 1931 showed to be fundamentally limited. Alan Turing's work in the 1930s on computability introduced the theoretical model of the stored-program computer and linked mathematical logic directly to the limits of algorithmic calculation. His proof that no algorithm can decide in general whether an arbitrary program will halt or run forever placed fundamental boundaries on what mathematics can mechanically determine, and it opened the discipline now known as theoretical computer science.

Share this calculator

Explore More

Frequently Asked Questions

The union of two sets A and B, written as A U B, is the set containing all elements that are in A, in B, or in both. No element is repeated in the result even if it appears in both sets. For example, if A = {1, 2, 3} and B = {2, 3, 4}, then A U B = {1, 2, 3, 4}. The union operation combines both sets while eliminating duplicates. This concept is fundamental in database queries (SQL UNION), probability theory (where P(A or B) relates to set union), and data analysis when merging datasets from different sources.
The intersection of two sets A and B, written as A n B or A and B, contains only the elements that appear in BOTH sets simultaneously. For example, if A = {1, 2, 3, 4} and B = {3, 4, 5, 6}, then A n B = {3, 4}. The intersection identifies the common elements shared between sets. In database terms, this corresponds to an INNER JOIN. In probability, the intersection relates to the probability of both events occurring. In everyday language, the intersection answers questions like which customers appear in both the online and in-store purchase lists.
A set A is a subset of B (written A is a subset of B) if every element of A is also in B. When A is a subset of B, interesting simplifications occur: A n B = A (the intersection equals the smaller set) and A U B = B (the union equals the larger set). Every set is a subset of itself, and the empty set is a subset of every set. If A is a subset of B AND B is a subset of A, then A and B are equal sets. Testing subset relationships is essential in access control systems, data validation, and mathematical proofs. Understanding subset relationships helps predict the results of union and intersection operations.
Venn diagrams use overlapping circles to represent sets and their relationships visually. Each circle represents a set, and the overlapping region represents the intersection (elements in both sets). The union is represented by the entire area covered by both circles combined. The non-overlapping parts of each circle represent the set differences (A - B and B - A). The symmetric difference is the total shaded area excluding the overlap. Venn diagrams make abstract set operations intuitive and are particularly helpful for teaching probability, logic, and data analysis concepts. For three sets, the diagram shows seven distinct regions, each representing a unique combination of membership.
You may use the results for reference and educational purposes. For professional reports, academic papers, or critical decisions, we recommend verifying outputs against peer-reviewed sources or consulting a qualified expert in the relevant field.
All calculations use established mathematical formulas and are performed with high-precision arithmetic. Results are accurate to the precision shown. For critical decisions in finance, medicine, or engineering, always verify results with a qualified professional.
Educational Note: This calculator is provided for educational and informational purposes. Results are based on the formulas and inputs provided. Always verify important calculations independently. NovaCalculator processes calculator inputs client-side; optional analytics follow visitor consent settings.Reviewed by: NovaCalculator Mathematics Team โ€” Verified against standard mathematical and scientific references. Last reviewed: December 2025. ยฉ 2024โ€“2026 NovaCalculator.

Share this calculator

Formula

|A U B| = |A| + |B| - |A n B|

The Inclusion-Exclusion Principle: the size of the union equals the sum of individual set sizes minus the size of the intersection. This avoids double-counting elements that appear in both sets.

Worked Examples

Example 1: Numeric Set Operations

Problem: Find the union, intersection, and differences of A = {1, 2, 3, 4, 5} and B = {3, 4, 5, 6, 7}.

Solution: A U B = {1, 2, 3, 4, 5, 6, 7} (all unique elements)\nA n B = {3, 4, 5} (common elements)\nA - B = {1, 2} (in A but not B)\nB - A = {6, 7} (in B but not A)\nSymmetric Difference = {1, 2, 6, 7}\nVerify: |A U B| = 7 = |A| + |B| - |A n B| = 5 + 5 - 3 = 7

Result: Union: 7 elements, Intersection: 3 elements, Jaccard Similarity: 3/7 = 0.4286

Example 2: Disjoint Sets Example

Problem: Find operations for A = {a, b, c} and B = {x, y, z}.

Solution: A U B = {a, b, c, x, y, z}\nA n B = {} (empty set - no common elements)\nA - B = {a, b, c} = A\nB - A = {x, y, z} = B\nSymmetric Difference = {a, b, c, x, y, z} = A U B\n|A U B| = 6 = 3 + 3 - 0

Result: Sets are disjoint. Union has 6 elements. Intersection is empty. Jaccard Similarity: 0.

Frequently Asked Questions

What is the union of two sets and how is it calculated?

The union of two sets A and B, written as A U B, is the set containing all elements that are in A, in B, or in both. No element is repeated in the result even if it appears in both sets. For example, if A = {1, 2, 3} and B = {2, 3, 4}, then A U B = {1, 2, 3, 4}. The union operation combines both sets while eliminating duplicates. This concept is fundamental in database queries (SQL UNION), probability theory (where P(A or B) relates to set union), and data analysis when merging datasets from different sources.

What is the intersection of two sets and what does it represent?

The intersection of two sets A and B, written as A n B or A and B, contains only the elements that appear in BOTH sets simultaneously. For example, if A = {1, 2, 3, 4} and B = {3, 4, 5, 6}, then A n B = {3, 4}. The intersection identifies the common elements shared between sets. In database terms, this corresponds to an INNER JOIN. In probability, the intersection relates to the probability of both events occurring. In everyday language, the intersection answers questions like which customers appear in both the online and in-store purchase lists.

What is a subset and how does it relate to union and intersection?

A set A is a subset of B (written A is a subset of B) if every element of A is also in B. When A is a subset of B, interesting simplifications occur: A n B = A (the intersection equals the smaller set) and A U B = B (the union equals the larger set). Every set is a subset of itself, and the empty set is a subset of every set. If A is a subset of B AND B is a subset of A, then A and B are equal sets. Testing subset relationships is essential in access control systems, data validation, and mathematical proofs. Understanding subset relationships helps predict the results of union and intersection operations.

How do Venn diagrams represent union and intersection visually?

Venn diagrams use overlapping circles to represent sets and their relationships visually. Each circle represents a set, and the overlapping region represents the intersection (elements in both sets). The union is represented by the entire area covered by both circles combined. The non-overlapping parts of each circle represent the set differences (A - B and B - A). The symmetric difference is the total shaded area excluding the overlap. Venn diagrams make abstract set operations intuitive and are particularly helpful for teaching probability, logic, and data analysis concepts. For three sets, the diagram shows seven distinct regions, each representing a unique combination of membership.

Is my data stored or sent to a server?

No. All calculations run entirely in your browser using JavaScript. No data you enter is ever transmitted to any server or stored anywhere. Your inputs remain completely private.

How do I verify Union and Intersection Calculator's result independently?

The Formula section on this page shows the equation used. You can reproduce the calculation manually or in a spreadsheet using those steps. Compare your answer against the worked examples in the Examples section, which use known reference values so you can confirm the calculator is behaving as expected.

References

Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy