Congruence as an Equivalence Relation: Residue Classes and the Algebra They Permit

The definition and why it is stated as a divisibility condition

Let n be a positive integer. For integers a and b we write


a ≡ b (mod n)   if and only if   n divides a − b.


An equivalent formulation is that a and b leave the same remainder on division by n, and it is worth seeing why the two agree. By the division algorithm write a = q1n + r1 and b = q2n + r2 with 0 ≤ r1, r2 < n.


Then a − b = (q1 − q2)n + (r1 − r2), so n divides a − b exactly when n divides r1 − r2; and since that difference lies strictly between −n and n, the only multiple of n available is 0, forcing r1 = r2.


The divisibility form is the one to work with in proofs, because it immediately supplies an integer to manipulate: a ≡ b (mod n) means a − b = kn for some integer k. Almost every proof in this topic begins by writing that equation down.


Note also what the definition does not require. It does not say that b is a remainder, so it does not require 0 ≤ b < n: the statements 17 ≡ 5 (mod 12) and 17 ≡ −7 (mod 12) are both correct, since 12 divides 12 and 12 divides 24.


Negative and large representatives are entirely legitimate, and choosing a convenient one often shortens a computation.

Congruence modulo n is an equivalence relation

Fix n ≥ 1 and consider the relation on the integers given by congruence modulo n.


  • Reflexive: a − a = 0 = 0 · n, so n divides a − a and a ≡ a (mod n).
  • Symmetric: if a − b = kn then b − a = (−k)n, and −k is an integer, so b ≡ a (mod n).
  • Transitive: if a − b = kn and b − c = mn then a − c = (a − b) + (b − c) = (k + m)n, and k + m is an integer, so a ≡ c (mod n).


Each step uses closure of the integers under negation and addition, which is where the argument actually gets its force.

Residue classes and the partition they create

Because congruence modulo n is an equivalence relation, it partitions the integers into disjoint residue classes. The class of a is


[a]n = { a + kn : k an integer } = { …, a − 2n, a − n, a, a + n, a + 2n, … }.


There are exactly n classes, represented by 0, 1, …, n − 1, and every integer lies in precisely one. The set of classes is written Z/nZ. Modulo 7, for instance, [3] contains 3, 10, 17, −4, and −11, and these are interchangeable for every purpose congruence modulo 7 can express.


Two habits follow. First, a class has many names: [3] = [10] = [−4] modulo 7, and no name is more correct than another, though 0 through n − 1 is the conventional set of representatives.


Second, whenever a problem asks a question that depends only on a number modulo n, you may replace any integer by any member of its class before computing.

Arithmetic on congruences: what is permitted

Suppose a ≡ b (mod n) and c ≡ d (mod n). Then


  • a + c ≡ b + d (mod n),
  • a − c ≡ b − d (mod n),
  • ac ≡ bd (mod n),
  • ak ≡ bk (mod n) for every positive integer k.


The multiplication rule is the one worth proving, since the others follow similarly. Write a = b + kn and c = d + mn.


Then ac = (b + kn)(d + mn) = bd + n(bm + kd + kmn), and the bracket is an integer, so n divides ac − bd.


The power rule then follows by induction on k, taking the base case k = 1 and multiplying the inductive hypothesis ak ≡ bk by a ≡ b.


Stated in the language of classes, these rules say that addition and multiplication are well defined on Z/nZ: the class of a sum or product depends only on the classes of the inputs, not on which representatives were chosen. That is exactly what licenses the reduce-as-you-go technique that makes modular computations tractable.

Arithmetic on congruences: what is not permitted

Two operations that look harmless are invalid, and knowing precisely why is most of the content of this topic.


Cancellation of a common factor. From ac ≡ bc (mod n) one may not generally conclude a ≡ b (mod n). The correct statement is


if ac ≡ bc (mod n), then a ≡ b (mod n / gcd(c, n)).


In particular, cancellation is valid without changing the modulus exactly when gcd(c, n) = 1. Here is the reason: ac ≡ bc (mod n) means n divides c(a − b).


Writing g = gcd(c, n), the factor n/g shares no factor with c/g, so n/g must divide a − b.


As an example, 3 · 5 ≡ 3 · 1 (mod 12) is true, since 15 − 3 = 12. Cancelling the 3 outright would give the false statement 5 ≡ 1 (mod 12). The rule instead gives 5 ≡ 1 (mod 12/3), that is modulo 4, which is correct.


Reduction in an exponent. From a ≡ b (mod n) one may not conclude ca ≡ cb (mod n). The rules above let you replace the base, not the exponent, because the exponent counts repetitions rather than contributing a factor.


Exponents are governed by a different modulus, related to the multiplicative order, and substituting one for the other is a frequent and costly error.

Working technique

Three moves handle most computations. Reduce every quantity modulo n before multiplying, so the numbers stay small. Choose the most convenient representative in a class, including negative ones: working with −1 instead of n − 1 often collapses a calculation immediately.


And for a large power, compute successive squares and look for the first exponent at which the value returns to 1, which reveals a cycle that reduces the exponent to a small case.

Let n be a positive integer and let a and b be integers. Which statement is equivalent to a ≡ b (mod n)?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

It is true that 6 · 4 ≡ 6 · 9 (mod 10), since both sides equal 4 modulo 10, yet 4 is not congruent to 9 modulo 10. Which statement correctly explains the situation?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

Let n be a positive integer. Prove each of the following directly from the definition that a ≡ b (mod n) means n divides a − b.

(a) Congruence modulo n is an equivalence relation on the integers.

(b) If a ≡ b (mod n) and c ≡ d (mod n), then ac ≡ bd (mod n).

(c) State what part (b) means in the language of residue classes, and explain why that statement is what makes modular arithmetic possible.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors