,

A congruence compares integers by divisibility of their difference. Solving a congruence means finding every residue class that satisfies that relation, not simply one integer that happens to work.

This lesson develops the algebra behind modular arithmetic: when cancellation is allowed, when several classes solve an equation, and how two remainder conditions can be combined.

On this page

State the relation and its domain

For integers a,ba,b and a positive modulus mm,

a≡b(modm)⇔m∣(a−b).a\equiv b\pmod m\quad\Longleftrightarrow\quad m\mid(a-b).

Congruence is reflexive, symmetric and transitive. For transitivity, if a−b=kma-b=km and b−c=ℓmb-c=\ell m, then a−c=(k+ℓ)ma-c=(k+\ell)m, so a≡c(modm)a\equiv c\pmod m.

These properties explain why each residue class is a coherent group of equivalent representatives. They do not turn congruence into ordinary equality. The modulus remains part of the statement.

Find a modular inverse when it exists

For m≥2m\ge2, an inverse of aa modulo mm is an integer uu satisfying au≡1(modm)au\equiv1\pmod m. It exists exactly when gcd(a,m)=1\gcd(a,m)=1.

For a=7a=7 and m=26m=26, Euclid’s algorithm gives

26=3×7+5,7=5+2,5=2×2+1.26=3\times7+5,\quad7=5+2,\quad5=2\times2+1.

Back-substitution yields 1=3×26−11×71=3\times26-11\times7. Thus −11-11 is an inverse of 7 modulo 26; its least non-negative representative is 15. Check: 7×15=105=4×26+17\times15=105=4\times26+1.

To solve 7x≡5(mod26)7x\equiv5\pmod{26}, multiply by that inverse:

x≡15×5≡23(mod26).x\equiv15\times5\equiv23\pmod{26}.

Every integer 23+26k23+26k is a solution, and no other residue class is. The check 7×23=161=6×26+57\times23=161=6\times26+5 confirms the representative.

Explain the greatest-common-factor condition

For m≥2m\ge2, let d=gcd(a,m)d=\gcd(a,m). The congruence

ax≡b(modm)ax\equiv b\pmod m

has an integer solution exactly when d∣bd\mid b. Necessity follows from ax−b=kmax-b=km: both axax and kmkm are divisible by dd, so bb must be too.

When d∣bd\mid b, divide the corresponding integer equation by dd. This gives

adx≡bd(modm/d).\frac ad x\equiv\frac bd\pmod{m/d}.

When m/d≥2m/d\ge2, the reduced coefficient and modulus are coprime, so an inverse solves the reduced congruence. If its solution is x≡x0(modm/d)x\equiv x_0\pmod{m/d}, it represents dd distinct classes modulo the original mm.

Handle the remaining case directly: if d=md=m, then m∣am\mid a. Every integer solves the original congruence when m∣bm\mid b, and none does otherwise. For example, 14x≡0(mod14)14x\equiv0\pmod{14} permits all fourteen residue classes; 14x≡1(mod14)14x\equiv1\pmod{14} permits none. There is no need to perform an inverse calculation modulo 1. This is the structure of linear congruence solutions.

Solve a congruence with several classes

Consider 6x≡8(mod14)6x\equiv8\pmod{14}. The GCF is 2, and 2 divides 8. Divide all three entries, including the modulus:

3x≡4(mod7).3x\equiv4\pmod7.

The inverse of 3 modulo 7 is 5, so x≡20≡6(mod7)x\equiv20\equiv6\pmod7. In the range 0≤x<140\le x<14, this gives two representatives, 6 and 13:

x≡6 or 13(mod14).x\equiv6\text{ or }13\pmod{14}.

Their products with 6 are 36 and 78; both leave remainder 8 modulo 14. By contrast, 6x≡5(mod14)6x\equiv5\pmod{14} has no solution because every value of 6x−14k6x-14k is even while 5 is odd.

Keep every solution class in the original modulus

Two solution residues modulo fourteenThe residues from zero to thirteen are shown. Only six and thirteen satisfy six x congruent to eight modulo fourteen.6x ≡ 8 (mod 14)012345678910111213After dividing by 2: 3x ≡ 4 (mod 7)x ≡ 6 (mod 7)The original modulus has two classes: 6 and 13.Only the filled points are solutions in 0 ≤ x < 14.
Filled points mark residues, not the interval between them.
Diagram explanation and exact data

The reduced equation is modulo 7. Its solutions are integers 6+7k; two of them lie between 0 and 13. Checking all fourteen residues confirms there are no other solutions.

Keep every solution class in the original modulus: exact reference data
Residue x Remainder of 6x modulo 14 Solution?
0 0 No
1 6 No
2 12 No
3 4 No
4 10 No
5 2 No
6 8 Yes
7 0 No
8 6 No
9 12 No
10 4 No
11 10 No
12 2 No
13 8 Yes

For a simpler cancellation warning, 2x≡2(mod6)2x\equiv2\pmod6 reduces to x≡1(mod3)x\equiv1\pmod3, not x≡1(mod6)x\equiv1\pmod6. The original residue classes are 1 and 4. Changing the modulus is what preserves the full solution set.

Combine two coprime remainder conditions

Solve

x≡2(mod3),x≡3(mod5).x\equiv2\pmod3,\qquad x\equiv3\pmod5.

The first condition gives x=2+3kx=2+3k. Substitute into the second:

2+3k≡3(mod5)⇒3k≡1(mod5).2+3k\equiv3\pmod5\quad\Longrightarrow\quad3k\equiv1\pmod5.

Multiplying by the inverse 2 of 3 modulo 5 gives k≡2(mod5)k\equiv2\pmod5. Write k=2+5tk=2+5t and substitute back:

x=2+3(2+5t)=8+15t.x=2+3(2+5t)=8+15t.

Thus x≡8(mod15)x\equiv8\pmod{15}. The solution is unique modulo the product 15 because 3 and 5 are coprime. This is a two-modulus instance of the Chinese remainder theorem, not a claim that every pair of conditions is compatible.

Check compatibility for non-coprime moduli

The conditions x≡1(mod4)x\equiv1\pmod4 and x≡3(mod6)x\equiv3\pmod6 are compatible. Their first shared non-negative value is 9, and all solutions have the form 9+12k9+12k. The combined repeat interval is the LCM 12.

The conditions x≡1(mod4)x\equiv1\pmod4 and x≡2(mod6)x\equiv2\pmod6 are incompatible: the first demands an odd integer and the second an even integer. In general, x≡a(modm)x\equiv a\pmod m and x≡b(modn)x\equiv b\pmod n are compatible exactly when a−ba-b is divisible by gcd(m,n)\gcd(m,n). When compatible, the solution class is unique modulo lcm(m,n)\operatorname{lcm}(m,n).

For the examples, the common divisor 2 tests whether the remainders have the same parity. A numerical answer should always be substituted into every original condition, not just the last transformed equation.

Practice questions

  1. Solve 5x≡3(mod7)5x\equiv3\pmod7.
  2. Give every solution residue modulo 6 for 4x≡2(mod6)4x\equiv2\pmod6.
  3. Find the least non-negative integer with remainder 1 modulo 3 and remainder 2 modulo 4.
Check your answers
  1. The inverse of 5 modulo 7 is 3, so x≡9≡2(mod7)x\equiv9\equiv2\pmod7.
  2. Divide by 2 to obtain 2x≡1(mod3)2x\equiv1\pmod3, then x≡2(mod3)x\equiv2\pmod3. The original residues are 2 and 5 modulo 6.
  3. The value is 10. It satisfies both conditions, and the full class is x≡10(mod12)x\equiv10\pmod{12}.

Related topics

Use Greatest Common Factor for the Euclidean and Bézout calculations. Rational and Irrational Numbers connects divisibility and prime exponents to exact number classification.

Sources and further reading