In short

A relation from a set A to a set B is any subset of the Cartesian product A \times B = \{(a, b) \mid a \in A,\, b \in B\}. The domain is the set of first coordinates that actually appear, the codomain is B, and the range is the set of second coordinates that actually appear. Relations come in named types — reflexive (every element is related to itself), symmetric (if a relates to b then b relates to a), and transitive (if a relates to b and b relates to c, then a relates to c). A relation that is all three at once is an equivalence relation, and it partitions its set into non-overlapping classes. If |A| = m and |B| = n, the total number of relations from A to B is 2^{mn}.

Think about your school timetable. Each row pairs a time slot with a subject: (Monday 8 am, Mathematics), (Monday 9 am, English), (Tuesday 8 am, Science), and so on. The timetable is not a set of times, and not a set of subjects — it is a set of pairings. Each pairing links one element from the set of time slots to one element from the set of subjects.

That linking idea — "this element from set A is paired with that element from set B" — is exactly what a relation is. A relation is a collection of ordered pairs, and each pair records one specific link between the two sets. The concept is deceptively simple: it is just a subset of all possible pairs. But from this one idea, you get the language to describe timetables, family trees, divisibility, congruence, "less than," "equal to," and eventually functions themselves (which are just relations with an extra rule).

The Cartesian product

Before you can pick certain pairs, you need the full menu of all possible pairs.

Cartesian product

For two sets A and B, the Cartesian product A \times B is the set of all ordered pairs (a, b) where a \in A and b \in B:

A \times B = \{(a, b) \mid a \in A \text{ and } b \in B\}

Take A = \{1, 2\} and B = \{x, y, z\}. Then:

A \times B = \{(1, x),\, (1, y),\, (1, z),\, (2, x),\, (2, y),\, (2, z)\}

There are |A| \times |B| = 2 \times 3 = 6 pairs. Every element of A gets paired with every element of B, and the pairing is ordered — the pair (1, x) is different from (x, 1) (in fact, (x, 1) would live in B \times A, not A \times B).

You can visualise A \times B as a grid. Put the elements of A along one axis and the elements of B along the other. Each cell in the grid is one ordered pair.

Cartesian product of {1, 2} and {x, y, z} shown as a gridA grid with two rows labelled 1 and 2 on the left, and three columns labelled x, y, and z along the top. Each of the six cells contains a red dot and is labelled with the corresponding ordered pair. The grid shows all six elements of the Cartesian product. A x y z B → 1 2 (1, x) (1, y) (1, z) (2, x) (2, y) (2, z)
The Cartesian product $\{1, 2\} \times \{x, y, z\}$ visualised as a $2 \times 3$ grid. Each dot is one ordered pair — there are $2 \times 3 = 6$ of them. A relation from $A$ to $B$ is any selection of dots from this grid.

Two things to note:

Definition of a relation

Relation

A relation R from a set A to a set B is any subset of A \times B:

R \subseteq A \times B

If (a, b) \in R, you say "a is related to b by R" and write a\, R\, b. When B = A, you call R a relation on A.

Every subset of the grid above is a valid relation. The subset \{(1, x), (2, y)\} is a relation that pairs 1 with x and 2 with y. The empty set \varnothing is a relation (no element is related to anything). The full product A \times B is also a relation (every element is related to every element). Everything in between is a relation too.

Here is a concrete example. Let A = \{1, 2, 3, 4\} and define the relation R on A by the rule "a divides b" — that is, (a, b) \in R if and only if a divides b with no remainder. Then:

R = \{(1,1), (1,2), (1,3), (1,4), (2,2), (2,4), (3,3), (4,4)\}

The number 1 divides everything, so it pairs with all four elements. The number 2 divides 2 and 4. The numbers 3 and 4 divide only themselves (within the set \{1,2,3,4\}).

Domain, codomain, and range

Three pieces of vocabulary describe the "reach" of a relation.

The range is always a subset of the codomain: \text{range}(R) \subseteq B. The domain is always a subset of A: \text{dom}(R) \subseteq A. When R is the empty relation, both are empty.

For the divisibility relation above: domain = \{1, 2, 3, 4\} (every element divides something), codomain = \{1, 2, 3, 4\} (same set), and range = \{1, 2, 3, 4\} (every element is divisible by something). In this case domain and range coincide with A, but that is not always the case.

Take a different example: let A = \{1, 2, 3\}, B = \{a, b, c, d\}, and R = \{(1, a), (3, c)\}. Then domain = \{1, 3\} (the element 2 from A does not appear as a first coordinate), codomain = \{a, b, c, d\} (all of B), and range = \{a, c\} (only two of the four elements of B actually appear).

Arrow diagram showing domain codomain and range for a relationTwo ovals side by side. The left oval is labelled A and contains elements 1, 2, 3. The right oval is labelled B and contains elements a, b, c, d. An arrow goes from 1 to a, and another arrow goes from 3 to c. The domain is highlighted as 1 and 3. The range is highlighted as a and c. Element 2 in A has no arrow, and elements b and d in B have no arrows pointing to them. A B (codomain) 1 2 3 a b c d domain = {1, 3} range = {a, c}
The relation $R = \{(1, a), (3, c)\}$ drawn as an arrow diagram. Arrows go from domain elements to range elements. Element $2$ in $A$ has no arrow — it is not in the domain. Elements $b$ and $d$ in $B$ have no arrow pointing to them — they are not in the range. The codomain is all of $B$.

Types of relations on a set

When R is a relation on a set A (that is, R \subseteq A \times A), three properties classify its behaviour. These properties will show up everywhere in later mathematics — in equivalence relations, in order relations, and in the definition of congruence.

Reflexive

A relation R on A is reflexive if every element is related to itself:

\text{For all } a \in A, \quad (a, a) \in R

The divisibility relation on \{1, 2, 3, 4\} is reflexive because every number divides itself: (1,1), (2,2), (3,3), (4,4) are all in R.

The relation "is strictly less than" on \mathbb{R} is not reflexive, because no number is strictly less than itself: (a, a) \notin R for any a.

On the grid picture, reflexive means every diagonal cell is filled.

Symmetric

A relation R on A is symmetric if the direction of the pairing never matters:

\text{For all } a, b \in A, \quad (a, b) \in R \implies (b, a) \in R

The relation "has the same birthday as" is symmetric: if Priya has the same birthday as Rahul, then Rahul has the same birthday as Priya.

The divisibility relation is not symmetric: 1 divides 2 (so (1, 2) \in R) but 2 does not divide 1 (so (2, 1) \notin R).

Transitive

A relation R on A is transitive if the links chain:

\text{For all } a, b, c \in A, \quad (a, b) \in R \text{ and } (b, c) \in R \implies (a, c) \in R

The relation "is an ancestor of" is transitive: if your grandmother is an ancestor of your mother, and your mother is an ancestor of you, then your grandmother is an ancestor of you.

The divisibility relation is transitive: if a divides b and b divides c, then a divides c. (Proof: b = ka and c = lb for some integers k, l, so c = l(ka) = (lk)a, which means a divides c.)

Equivalence relation

A relation that is reflexive, symmetric, and transitive all at once is called an equivalence relation. It is the mathematical version of "is the same as" — not literal identity, but sameness in some particular respect.

The relation "has the same remainder when divided by 3" on \mathbb{Z} is an equivalence relation. It is reflexive (every integer has the same remainder as itself), symmetric (if a and b have the same remainder, so do b and a), and transitive (if a and b share a remainder and b and c share a remainder, then a and c share that remainder too). This particular equivalence relation is called congruence modulo 3, and it partitions \mathbb{Z} into three classes: numbers with remainder 0, numbers with remainder 1, and numbers with remainder 2.

Every equivalence relation on a set A partitions A into non-overlapping equivalence classes, and conversely, every partition of A defines an equivalence relation (where two elements are related if and only if they are in the same part). This one-to-one correspondence between equivalence relations and partitions is one of the most important ideas in algebra.

Partition of integers 0 through 8 into three equivalence classes modulo 3Three rounded rectangles side by side inside a larger rectangle representing the set of integers from 0 to 8. The first box contains 0, 3, 6 labelled remainder 0. The second contains 1, 4, 7 labelled remainder 1. The third contains 2, 5, 8 labelled remainder 2. Every integer from 0 to 8 appears in exactly one box. A = {0, 1, 2, …, 8} remainder 0 0 3 6 remainder 1 1 4 7 remainder 2 2 5 8
The equivalence relation "same remainder mod $3$" partitions $\{0, 1, 2, \dots, 8\}$ into three classes. Every element belongs to exactly one class — no overlaps, no gaps. The three classes are $\{0, 3, 6\}$, $\{1, 4, 7\}$, and $\{2, 5, 8\}$.

Number of relations

Here is a counting question that appears on every exam. If |A| = m and |B| = n, how many relations are there from A to B?

A relation is a subset of A \times B. The Cartesian product has mn elements. From Sets — Introduction, the number of subsets of a set with k elements is 2^k. So the number of relations from A to B is:

2^{mn}

For A = \{1, 2\} and B = \{x, y, z\}: there are 2^{2 \times 3} = 2^6 = 64 possible relations. One of them is the empty relation, one is the full Cartesian product, and the other 62 are everything in between.

For a relation on A (that is, from A to A), with |A| = n: the number of relations is 2^{n^2}. With n = 3, that is 2^9 = 512 relations on a three-element set. The number grows fast.

Interactive: exploring relations on a small set

Use the figure below to see how a relation on \{1, 2, 3\} looks on a grid. Each cell of the 3 \times 3 grid represents an ordered pair. The diagonal cells (shaded) correspond to reflexive pairs. Drag the red point along the line to select a value k from 0 to 9; the readout shows the binary representation of k, and each bit corresponds to one of the 9 cells being filled or empty, illustrating how each of the 2^9 = 512 relations is a subset of the grid.

Interactive slider showing a relation number from 0 to 512A number line from 0 to 512 with a draggable red point. A readout above the line shows the current value as an integer, representing one of the 512 possible relations on a three-element set. As the point moves, the displayed number changes, illustrating that each position picks a different subset of the 9-cell grid. 0 256 512 drag to pick a relation each of 512 positions = one of 2⁹ subsets of {1,2,3} × {1,2,3}
There are $2^{3 \times 3} = 512$ relations on $\{1, 2, 3\}$. Each position of the slider corresponds to a different subset of the $9$-element Cartesian product. Relation $0$ is the empty relation (no pairs), and relation $511$ is the full product (every pair). Drag the red point to see the relation number change.

Two worked examples

Example 1: List all elements of $R = \{(a, b) \in A \times A \mid a + b \le 4\}$ where $A = \{1, 2, 3\}$, and determine whether $R$ is reflexive, symmetric, or transitive

Step 1. Write out A \times A.

A \times A = \{(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)\}

There are 3^2 = 9 pairs.

Why: the Cartesian product of a 3-element set with itself always has 9 ordered pairs — one for each cell of the 3 \times 3 grid.

Step 2. Filter by the condition a + b \le 4.

Check each pair: 1+1=2\le4 (yes), 1+2=3\le4 (yes), 1+3=4\le4 (yes), 2+1=3\le4 (yes), 2+2=4\le4 (yes), 2+3=5>4 (no), 3+1=4\le4 (yes), 3+2=5>4 (no), 3+3=6>4 (no).

R = \{(1,1),(1,2),(1,3),(2,1),(2,2),(3,1)\}

Why: the rule is mechanical — compute a + b for each pair and keep only those where the sum does not exceed 4.

Step 3. Check reflexive. Are (1,1), (2,2), and (3,3) all in R?

(1,1) \in R (yes), (2,2) \in R (yes), (3,3) \notin R (no, because 3+3=6>4).

R is not reflexive — the pair (3,3) is missing.

Step 4. Check symmetric. For every (a,b) \in R, is (b,a) \in R?

(1,2) \in R and (2,1) \in R (yes). (1,3) \in R and (3,1) \in R (yes). (2,2) \in R and (2,2) \in R (yes, trivially). All pairs check out.

R is symmetric.

Why: the condition a + b \le 4 is symmetric in a and b — swapping them does not change the sum. So if (a,b) satisfies the condition, (b,a) does too.

Step 5. Check transitive. For every (a,b) \in R and (b,c) \in R, is (a,c) \in R?

(1,3) \in R and (3,1) \in R, so check (1,1): yes, in R. (2,1) \in R and (1,3) \in R, so check (2,3): 2+3=5>4, so (2,3) \notin R. Fail.

R is not transitive.

Result. R = \{(1,1),(1,2),(1,3),(2,1),(2,2),(3,1)\}. Symmetric, but not reflexive and not transitive.

Grid diagram of the relation a plus b at most 4 on {1, 2, 3}A 3 by 3 grid with rows and columns labelled 1, 2, 3. Six cells are filled with red dots representing the pairs in the relation: (1,1), (1,2), (1,3), (2,1), (2,2), and (3,1). Three cells are empty: (2,3), (3,2), and (3,3). The diagonal cells (1,1) and (2,2) are filled but (3,3) is not, showing the relation is not reflexive. b a 1 2 3 1 2 3 2+3=5 3+2=5 3+3=6
The $3 \times 3$ grid for $R$. A red dot means the pair is in $R$ (sum $\le 4$); an empty cell with the sum printed means the pair is out. The diagonal runs from top-left to bottom-right: $(1,1)$ and $(2,2)$ are filled but $(3,3)$ is empty, confirming that $R$ is not reflexive. The grid is symmetric about the diagonal (every dot above the diagonal has a mirror below it), confirming that $R$ is symmetric.

The grid makes the symmetry visible at a glance — the pattern is a mirror image across the main diagonal. The missing (3,3) on the diagonal breaks reflexivity.

Example 2: Show that the relation "is congruent to modulo $4$" on $A = \{0, 1, 2, \dots, 11\}$ is an equivalence relation, and list its equivalence classes

Two integers a and b are congruent modulo 4 if 4 divides a - b, that is, a - b is a multiple of 4. Write a \equiv b \pmod{4}.

Step 1. Check reflexive: is a \equiv a \pmod{4} for every a \in A?

a - a = 0, and 4 divides 0 (since 0 = 4 \times 0). So yes, every element is related to itself.

Why: the difference of any number with itself is 0, and 0 is a multiple of every positive integer. Reflexivity is automatic for congruence modulo anything.

Step 2. Check symmetric: if a \equiv b \pmod{4}, is b \equiv a \pmod{4}?

If 4 \mid (a - b), then a - b = 4k for some integer k. So b - a = -4k = 4(-k), which means 4 \mid (b - a). Yes, symmetric.

Why: if the difference a - b is a multiple of 4, then the negated difference b - a is also a multiple of 4 (just with the opposite sign). Divisibility does not care about the sign.

Step 3. Check transitive: if a \equiv b \pmod{4} and b \equiv c \pmod{4}, is a \equiv c \pmod{4}?

a - b = 4k and b - c = 4l for integers k, l. Add: a - c = (a - b) + (b - c) = 4k + 4l = 4(k + l). So 4 \mid (a - c). Yes, transitive.

Why: adding two multiples of 4 gives another multiple of 4. The chain from a to b to c collapses into a direct link from a to c.

Step 4. Since the relation is reflexive, symmetric, and transitive, it is an equivalence relation. Now list the equivalence classes.

Each equivalence class is the set of elements in A that have the same remainder when divided by 4:

  • Remainder 0: \{0, 4, 8\}
  • Remainder 1: \{1, 5, 9\}
  • Remainder 2: \{2, 6, 10\}
  • Remainder 3: \{3, 7, 11\}

Result. The relation is an equivalence relation with four classes: \{0,4,8\}, \{1,5,9\}, \{2,6,10\}, \{3,7,11\}.

Four equivalence classes of integers 0 to 11 modulo 4Four rounded rectangles in a row, each containing three numbers. The first box has 0, 4, 8. The second has 1, 5, 9. The third has 2, 6, 10. The fourth has 3, 7, 11. Together the four boxes contain all twelve integers from 0 to 11 with no overlaps. A = {0, 1, 2, …, 11} mod 4 r = 0 0 4 8 r = 1 1 5 9 r = 2 2 6 10 r = 3 3 7 11
The four equivalence classes under "congruent mod $4$." Each class is a box of numbers that all share the same remainder when divided by $4$. The twelve elements of $A$ are distributed across the four classes with no overlaps and no gaps — the classes form a **partition** of $A$.

The partition is clean: every element of A lands in exactly one class, and two elements are in the same class if and only if their difference is a multiple of 4. For instance, 1 and 9 are in the same class because 9 - 1 = 8 = 4 \times 2.

Common confusions

Going deeper

If you came here for the definitions of relation, domain, range, and the three named properties, you have the working toolkit for everything in the next few chapters. The rest of this section is for readers who want to see why equivalence relations matter so deeply and how the counting of special types of relations leads to interesting combinatorics.

Equivalence relations and quotient sets

When you have an equivalence relation \sim on a set A, the equivalence class of an element a is the set [a] = \{x \in A \mid x \sim a\}. The collection of all distinct equivalence classes is called the quotient set A / {\sim}. In Example 2, A / {\equiv_4} = \big\{\{0,4,8\},\, \{1,5,9\},\, \{2,6,10\},\, \{3,7,11\}\big\} — a set of four elements, each of which is itself a set.

Quotient sets are how mathematicians build new objects from old ones. The rational numbers, for instance, can be constructed as equivalence classes of ordered pairs of integers: the fraction \frac{a}{b} is the equivalence class of all pairs (a, b) where two pairs (a, b) and (c, d) are equivalent if ad = bc. So \frac{1}{2}, \frac{2}{4}, and \frac{3}{6} are all names for the same equivalence class. The rational number is the class, not any particular representative.

Counting special relation types

On a set with n elements, the total count of 2^{n^2} includes relations of every type. Counting only the relations that satisfy a given property is harder:

Partial orders

Drop the symmetry requirement and keep reflexivity and transitivity, and add antisymmetry (if a\, R\, b and b\, R\, a, then a = b). The result is a partial order. The divisibility relation on the positive integers is a partial order: if a \mid b and b \mid a, then a = b. Partial orders are the foundation of the lattice theory that underlies much of abstract algebra, and they show up again in combinatorics (Hasse diagrams) and computer science (dependency graphs).

Where this leads next

Relations are the scaffolding on which functions, order, and equivalence are all built.