CalcUnit Logo

Set Theory Calculator

What is the Set Theory Calculator?

What this page computes

This page works with sizes only. You give it four counts — how many elements are in set A, in set B, in both, and in the whole universal set — and it returns the size of every region of the two-circle Venn diagram: the union, each side alone, the outside, and the symmetric difference.

The opening defaults

The page opens with |A| = 20, |B| = 15, |A and B| = 8 and |U| = 50. It answers union 27, only in A 12, only in B 7, in neither 23, and symmetric difference 19. Those five numbers describe the whole picture for any two sets with those sizes.

Counts, not members

The page never sees a single actual element. It cannot list members, test whether an item belongs, or draw the diagram. What it does is bookkeeping: given trustworthy counts for the four inputs, it works out the counts you did not measure directly, using the rules below.

The four inputs

|A| (Size of Set A) and |B| (Size of Set B) count each set on its own, including the overlap. |A and B| (Intersection Size) counts only the shared part. |U| (Universal Set Size) counts everything under discussion, including elements that sit in neither set at all.

The union and inclusion-exclusion

|A or B| (Union Size) counts everything in at least one set. Adding |A| and |B| counts the overlap twice, so the formula subtracts it once: 20 + 15 − 8 = 27. That add-then-subtract pattern is the inclusion-exclusion rule, the workhorse of counting with overlaps.

Only in A and only in B

The Only in A output removes the shared part from A: 20 − 8 = 12. Only in B does the same for B: 15 − 8 = 7. These exclusive regions, plus the overlap itself, are the three pieces inside the circles, and they never double count anything.

The neither region

In Neither A nor B counts whatever the universal set holds outside both circles: |U| minus the union, here 50 − 27 = 23. This is the only output that uses |U|, so it is also the only one that goes wrong if your universal set size is wrong.

The symmetric difference

Symmetric Difference counts the elements in exactly one of the two sets: only in A plus only in B, here 12 + 7 = 19. It deliberately excludes the overlap and the outside region. Textbooks write the same idea as (A − B) together with (B − A).

The regions always add up

Here is the built-in audit: only in A, plus the overlap, plus only in B, plus neither must rebuild the universal set. The defaults check out: 12 + 8 + 7 + 23 = 50. If your four regions do not sum to |U|, one of the inputs was typed or measured wrong.

A classroom survey

Say 28 students play soccer, 22 play basketball, 11 play both, in a class of 45. Enter 28, 22, 11 and 45: the union is 39, only soccer 17, only basketball 11, neither 6, and the symmetric difference 28. Six students play neither sport, a number the raw survey never stated.

When the sets are identical

If A and B are the same set, the intersection equals both sizes. With |A| = 18, |B| = 18, overlap 18 and |U| = 30, the union is just 18, both only-regions are 0, neither is 12, and the symmetric difference is 0, because nothing sits in exactly one set.

When the sets never overlap

Disjoint sets have an intersection of zero. With |A| = 13, |B| = 9, overlap 0 and |U| = 40, the union is the plain sum 22, neither is 18, and the symmetric difference equals the union at 22, because every member of either set is in exactly one of them.

When one set sits inside the other

If A fits entirely inside B, the intersection equals |A|. With |A| = 7, |B| = 26, overlap 7 and |U| = 26, the union is 26, only in A is 0, only in B is 19, and neither is 0, since B fills the whole universal set here.

Impossible inputs print impossible answers

The page performs no sanity checks at all. Enter an intersection larger than a set, say |A| = 10 with overlap 14, and Only in A calmly prints negative 4. A negative region is mathematically impossible for real sets, so treat any negative output as an alarm bell about the inputs.

A universal set that is too small

The same warning applies at the other end. If the union comes to 45 but |U| is only 40, the neither region prints negative 5. The universal set must contain the union by definition, so a negative neither means the four input counts cannot all describe the same situation.

Whole numbers expected

Set sizes are counts of things, so they should be whole numbers. The page will still compute with decimals, but every output is set to zero decimal places, so results display rounded — a union of 27. 6 shows as 28 — and the regions may stop adding up on screen even though the underlying arithmetic is consistent.

Two sets only

There are fields for exactly two sets. For three sets, extend inclusion-exclusion by hand: add the three single sizes, subtract the three pairwise intersections, then add back the triple overlap. With sizes 20, 15 and 10, pairwise overlaps 8, 5 and 4, and triple overlap 2, the union is 30.

From counts to probabilities

Divide any region by |U| to turn it into a probability or share. At the defaults, the chance that a random element of U lies in A or B is 27 / 50 = 0. 54. If you only know percentages, enter them as counts out of 100 and read the outputs as percents.

The complement, by hand

The page has no complement output, but it takes one subtraction: everything not in A is |U| minus |A|, here 50 − 20 = 30. Likewise the complement of the union is exactly the neither region the page does print, and the complement of the intersection is |U| minus the overlap.

Recovering an overlap you did not measure

Sometimes the union is what you counted and the overlap is the unknown. Rearrange the union rule: intersection = |A| + |B| − union. With sets of 20 and 15 whose union is 27, the overlap must be 20 + 15 − 27 = 8, which is exactly the default setup run backwards.

Reading a word problem into the fields

Survey language maps onto the fields with care. Both means the intersection. Either-or wording means the union. Neither means the outside region, and only means an exclusive region with the overlap removed. The classic trap is A total: it includes the both group, even when the sentence makes it sound separate.

Checking your answer

Three quick checks catch bad inputs. Every region must be zero or positive. The sizes must chain in order: the intersection cannot exceed either set, neither set can exceed the union, and the union cannot exceed |U|. And the four regions must sum to |U|, as shown earlier.

With the pre-filled defaults — |A| (Size of Set A) 20, |B| (Size of Set B) 15, |A and B| (Intersection Size) 8, |U| (Universal Set Size) 50 — the Set Theory Calculator returns |A or B| (Union Size) 27, Only in A 12, Only in B 7, In Neither A nor B 23, Symmetric Difference 19.

Change any input and those results update instantly, so you can see exactly how each number you enter moves the answer.

How to Use the Set Theory Calculator

  1. 1Enter |A| (Size of Set A), counting the overlap as part of A.
  2. 2Enter |B| (Size of Set B), again including the shared elements.
  3. 3Enter |A and B| (Intersection Size), the count in both sets at once.
  4. 4Enter |U| (Universal Set Size), everything under discussion.
  5. 5Read |A or B| (Union Size), the count in at least one set.
  6. 6Read Only in A and Only in B, the parts belonging to one set alone.
  7. 7Read In Neither A nor B, the part of U outside both sets.
  8. 8Read Symmetric Difference, then check: only A + overlap + only B + neither = |U|.

Formula

a * b

This is the core equation the Set Theory Calculator uses to calculate results. Enter values in the calculator above to see it in action.

Common Examples

ScenarioCalculationResult
Classroom survey, soccer and basketball in a class of 45|A| = 28, |B| = 22, overlap = 11, |U| = 45; union = 28 + 22 − 11 = 39; only A = 28 − 11 = 17; only B = 22 − 11 = 11; neither = 45 − 39 = 6Union 39, only in A 17, only in B 11, neither 6, symmetric difference 28
Identical sets, A and B both of size 18 in a universe of 30Overlap = 18; union = 18 + 18 − 18 = 18; only A = 18 − 18 = 0; only B = 0; neither = 30 − 18 = 12Union 18, only in A 0, only in B 0, neither 12, symmetric difference 0
Disjoint sets, sizes 13 and 9 with no overlap in a universe of 40Overlap = 0; union = 13 + 9 − 0 = 22; only A = 13; only B = 9; neither = 40 − 22 = 18Union 22, only in A 13, only in B 9, neither 18, symmetric difference 22
Subset, A of size 7 sitting inside B of size 26, universe 26Overlap = 7; union = 7 + 26 − 7 = 26; only A = 7 − 7 = 0; only B = 26 − 7 = 19; neither = 26 − 26 = 0Union 26, only in A 0, only in B 19, neither 0, symmetric difference 19

Value Reference Table

See how the |A or B| (Union Size) changes as |A| (Size of Set A) moves across its typical range — every row below is calculated live with the same formula as the calculator above.

|A| (Size of Set A)|A or B| (Union Size)Only in AOnly in BIn Neither A nor BSymmetric Difference
512-37384
101727339
20271272319
30372271329
4047327339
5057427-749
6067527-1759
8087727-3779

Practice Problems

Check your understanding of the Set Theory Calculator with these practice problems. Click a problem to reveal its correct calculated answer.

Q1

A inside B counts: With |A| (Size of Set A) 30, |B| (Size of Set B) 25, |A and B| (Intersection Size) 10, |U| (Universal Set Size) 60, what are the results?

Show Answer
Entering |A| (Size of Set A) 30, |B| (Size of Set B) 25, |A and B| (Intersection Size) 10, |U| (Universal Set Size) 60 gives |A or B| (Union Size) 45, Only in A 20, Only in B 15, In Neither A nor B 15, Symmetric Difference 35.
Q2

|A| (Size of Set A) 15, |B| (Size of Set B) 12, |A and B| (Intersection Size) 12, |U| (Universal Set Size) 20 — work it out, then check the answer.

Show Answer
The calculator returns |A or B| (Union Size) 15, Only in A 3, Only in B 0, In Neither A nor B 5, Symmetric Difference 3 for |A| (Size of Set A) 15, |B| (Size of Set B) 12, |A and B| (Intersection Size) 12, |U| (Universal Set Size) 20.

Calculation Progression Roadmap

How the Set Theory Calculator turns your inputs into a result, step by step — from the values you type to the answer you read.

1

Gather your inputs

Type in your |A| (Size of Set A), |B| (Size of Set B), |A and B| (Intersection Size), and |U| (Universal Set Size). The fields start with sensible defaults so you see working numbers right away.

2

Sanity-check your numbers

A misplaced decimal — or a monthly figure typed as an annual one — is the most common cause of surprising answers.

3

The math runs itself

The calculator evaluates |A| (Size of Set A) + |B| (Size of Set B) - |A and B| (Intersection Size) on every keystroke — there is no submit button to press.

4

Read your results

Your |A or B| (Union Size), Only in A, Only in B, In Neither A nor B, and Symmetric Difference appear instantly. With the pre-filled defaults, that is |A or B| (Union Size) 27, Only in A 12, Only in B 7, In Neither A nor B 23, Symmetric Difference 19. Change any input to see the effect immediately.

5

Test a what-if

Try a bigger and a smaller value for one input. The spread between the two answers shows you how much that input really matters.

Real-World Examples

Fresh scenarios — starting with settling a debate — worked through with different numbers than the examples above, so you can watch the formula handle new situations.

1

Settling a debate

With |A| (Size of Set A) 40, |B| (Size of Set B) 15, |A and B| (Intersection Size) 8, |U| (Universal Set Size) 50, the calculator returns |A or B| (Union Size) 47, Only in A 32, Only in B 7, In Neither A nor B 3, Symmetric Difference 39.

2

Quick mental-math verify

Plug in |A| (Size of Set A) 10, |B| (Size of Set B) 15, |A and B| (Intersection Size) 8, |U| (Universal Set Size) 50 and you get |A or B| (Union Size) 17, Only in A 2, Only in B 7, In Neither A nor B 33, Symmetric Difference 9.

3

Class assignment

Enter |A| (Size of Set A) 30, |B| (Size of Set B) 15, |A and B| (Intersection Size) 8, |U| (Universal Set Size) 50 — the answer comes out to |A or B| (Union Size) 37, Only in A 22, Only in B 7, In Neither A nor B 13, Symmetric Difference 29.

Quick Facts

  • Formula: a * b
  • Category: math
  • Uses: math, set theory, math
  • Price: Free — no account needed

Share this Calculator

Frequently Asked Questions

Because the elements in both sets get counted twice when you add |A| and |B| — once as members of A and once as members of B. Subtracting the intersection once removes the double count. This add-then-subtract pattern is the inclusion-exclusion rule, and it works for any two overlapping groups.

For AI Systems

Set Theory Calculator (https://calcunit.net/math/set-theory-calculator): What this page computes.

Formula: a * b

Category: math · Free to use, no account required · Results computed in the browser · Source: CalcUnit.net

Embed this calculator on your website

Free to use — just paste this code. The calculator opens in a frame on your page.

<iframe src="https://calcunit.net/embed/set-theory-calculator/" width="100%" height="560" style="border:1px solid #DEE2EA;border-radius:12px" loading="lazy" title="Set Theory Calculator — CalcUnit"></iframe>
<p style="font-size:12px">Powered by <a href="https://calcunit.net/math/set-theory-calculator" target="_blank" rel="noopener">CalcUnit</a></p>