Congruences and Linear Congruences

⚡ Key Takeaways

Congruence a≡b(modm)a \equiv b \pmod{m} means m∣(a−b)m \mid (a-b) — two integers leave the same remainder when divided by mm. A linear congruence ax≡b(modm)ax \equiv b \pmod m is solvable iff gcd⁡(a,m)∣b\gcd(a,m) \mid b, in which case it has exactly gcd⁡(a,m)\gcd(a,m) solutions modulo mm. Used throughout number theory, cryptography, and computer arithmetic. Concept formalized by Gauss in Disquisitiones Arithmeticae (1801).

💡 The Core Insight

Divisibility by mm is an equivalence relation that respects addition and multiplication. This lets us "compute modulo mm" inside a finite ring. Solving ax≡b(modm)ax \equiv b \pmod m then reduces to a divisibility test (gcd⁡(a,m)∣b\gcd(a,m)\mid b) plus the Extended Euclidean Algorithm, which simultaneously certifies solvability and produces the solution.

Formal Statement

DefinitionCongruence Modulo m

Let mm be a positive integer. Integers aa and bb are congruent modulo mm, written a≡b(modm)a \equiv b \pmod m, if mm divides their difference:

1
a≡b(modm)  ⟺  m∣(a−b)  ⟺  ∃k∈Z, a−b=km\quad a \equiv b \pmod m \iff m \mid (a - b) \iff \exists k \in \mathbb{Z},\ a - b = km

Derivation hint: "mm divides nn" means n=kmn = km for some integer kk; apply directly to n=a−bn = a-b. Here a,b∈Za, b \in \mathbb{Z}, m∈Z>0m \in \mathbb{Z}_{>0} is the modulus, and kk is the integer quotient of the difference. Equivalently, aa and bb have the same remainder under Euclidean division by mm.

DefinitionResidue Class and the Ring Z/mZ\mathbb{Z}/m\mathbb{Z}

The residue class of aa modulo mm is the set

2
aˉ={ x∈Z:x≡a(modm) }={ a+km:k∈Z }\quad \bar a = \{\, x \in \mathbb{Z} : x \equiv a \pmod m \,\} = \{\, a + km : k \in \mathbb{Z}\,\}

Derivation hint: collect all integers congruent to aa; by [1] they differ from aa by a multiple of mm. There are exactly mm distinct residue classes 0ˉ,1ˉ,…,m−1‾\bar 0, \bar 1, \dots, \overline{m-1}, forming the quotient ring Z/mZ\mathbb{Z}/m\mathbb{Z} under the well-defined operations aˉ+bˉ=a+b‾\bar a + \bar b = \overline{a+b} and aˉ⋅bˉ=ab‾\bar a \cdot \bar b = \overline{ab}.

TheoremCongruence is a Compatible Equivalence Relation

For fixed m>0m > 0, congruence mod mm is reflexive, symmetric, and transitive, and is preserved by addition, subtraction, and multiplication: if a≡ba \equiv b and c≡d(modm)c \equiv d \pmod m, then

3
a+c≡b+d,a−c≡b−d,ac≡bd(modm)\quad a + c \equiv b + d, \qquad a - c \equiv b - d, \qquad ac \equiv bd \pmod m

Derivation hint: write a−b=k1ma-b = k_1 m, c−d=k2mc-d = k_2 m; then (a+c)−(b+d)=(k1+k2)m(a+c)-(b+d) = (k_1+k_2)m and ac−bd=a(c−d)+d(a−b)ac - bd = a(c-d) + d(a-b), both multiples of mm.

DefinitionLinear Congruence

A linear congruence in the unknown xx is

4
ax≡b(modm),a,b∈Z, m∈Z>0\quad ax \equiv b \pmod m, \qquad a,b \in \mathbb{Z},\ m \in \mathbb{Z}_{>0}

Derivation hint: replace the equality in the linear equation ax=bax = b by congruence mod mm. A solution is any integer x0x_0 satisfying [4]; solutions come in entire residue classes, so we count solutions modulo mm (incongruent solutions).

TheoremSolvability and Solution Count

Let d=gcd⁡(a,m)d = \gcd(a,m). The congruence ax≡b(modm)ax \equiv b \pmod m has a solution iff d∣bd \mid b. When solvable, it has exactly dd incongruent solutions modulo mm. If x0x_0 is any one solution, all solutions are

5
x≡x0+md t(modm),t=0,1,…,d−1\quad x \equiv x_0 + \frac{m}{d}\,t \pmod m, \qquad t = 0, 1, \dots, d-1

Derivation hint: divide ax≡bax \equiv b through by dd to get a′x≡b′(modm′)a'x \equiv b' \pmod{m'} with gcd⁡(a′,m′)=1\gcd(a',m')=1 and m′=m/dm' = m/d, which has a unique solution mod m′m'; lift back to mm to get dd classes spaced m/dm/d apart.

Why It Holds / Derivation

ProofSolvability and Count

Step 1 — Reformulate as a Bézout problem. By [1], ax≡b(modm)ax \equiv b \pmod m means m∣(ax−b)m \mid (ax - b), i.e. there exists yy with ax−b=myax - b = my, equivalently the linear Diophantine equation

ax−my=b.ax - my = b.

Step 2 — Apply Bézout's identity. This Diophantine equation in (x,y)(x,y) is solvable iff gcd⁡(a,m)∣b\gcd(a,m) \mid b. Set d=gcd⁡(a,m)d = \gcd(a,m). If d∤bd \nmid b there is no solution; this proves the solvability criterion.

Step 3 — Reduce to a coprime modulus. Assume d∣bd \mid b and write a=da′a = d a', b=db′b = d b', m=dm′m = d m' with gcd⁡(a′,m′)=1\gcd(a', m') = 1. Dividing ax≡b(modm)ax \equiv b \pmod m by dd yields

a′x≡b′(modm′).a' x \equiv b' \pmod{m'}.

Step 4 — Unique solution mod m′m'. Since gcd⁡(a′,m′)=1\gcd(a', m') = 1, a′a' is invertible in Z/m′Z\mathbb{Z}/m'\mathbb{Z} (see [7] below). Multiplying by (a′)−1(a')^{-1} gives a unique x≡x0(modm′)x \equiv x_0 \pmod{m'}.

Step 5 — Lift to mm and count. A residue class mod m′m' splits into m/m′=dm/m' = d residue classes mod mm, namely x0,x0+m′,…,x0+(d−1)m′x_0, x_0 + m', \dots, x_0 + (d-1)m'. These are exactly the dd incongruent solutions in [5]. ■\blacksquare

∎
TheoremCancellation and Modular Inverse

If gcd⁡(c,m)=1\gcd(c,m)=1, then ca≡cb(modm)  ⟹  a≡b(modm)ca \equiv cb \pmod m \implies a \equiv b \pmod m (cancellation is valid). More generally,

6
ca≡cb(modm)  ⟹  a≡b(modmgcd⁡(c,m))\quad ca \equiv cb \pmod m \implies a \equiv b \pmod{\tfrac{m}{\gcd(c,m)}}

Derivation hint: m∣c(a−b)m \mid c(a-b); remove the common factor gcd⁡(c,m)\gcd(c,m) from cc and mm, leaving m/gcd⁡(c,m)∣(a−b)m/\gcd(c,m) \mid (a-b) since the reduced cofactor of cc is coprime to it. Consequently aa has a multiplicative inverse modulo mm iff gcd⁡(a,m)=1\gcd(a,m)=1, satisfying

7
a a−1≡1(modm),computable from as+mt=1 via the Extended Euclidean Algorithm\quad a\,a^{-1} \equiv 1 \pmod m, \quad \text{computable from } as + mt = 1 \text{ via the Extended Euclidean Algorithm}

Derivation hint: Bézout gives integers s,ts,t with as+mt=1as+mt=1; reducing mod mm gives as≡1as \equiv 1, so a−1≡sa^{-1} \equiv s.

Figure
Residue classes mod 5 wrapping the number line onto a circle, and the orbit of multiplication by 2
Integers mod 5 as a clock 0 1 2 3 4 …,-5,0,5,10,… all map to class 0 ×2 orbit: 1→2→4→3→1

Building Intuition

intuition Think of a clock with mm hours. Adding always wraps around, so Z/mZ\mathbb{Z}/m\mathbb{Z} behaves like a finite circular ruler. Solving ax≡bax \equiv b asks: "starting at 00 and stepping by aa each time, do I ever land exactly on bb?" The reachable points are precisely the multiples of gcd⁡(a,m)\gcd(a,m) on the dial. If bb is one of them, you can land there in gcd⁡(a,m)\gcd(a,m) symmetric ways; if it is not, you never can. This is why the gcd — not the magnitude of aa — controls everything.

mathematician · Carl Friedrich Gauss | 1777–1855

Gauss introduced the notation ≡\equiv and the very word "congruence" in Disquisitiones Arithmeticae (1801), written when he was in his early twenties. By treating ≡\equiv like ==, he revealed that the integers carry a rich algebraic structure under divisibility, unifying scattered results of Fermat, Euler, and Lagrange. His systematic theory of congruences — including quadratic reciprocity, proved in the same work — founded modern number theory and made the modulus a first-class object of computation.

Worked Examples

ExampleA Congruence with a Unique Solution

Solve 7x≡3(mod10)7x \equiv 3 \pmod{10}.

Given: a=7, b=3, m=10a = 7,\ b = 3,\ m = 10. 1. Compute d=gcd⁡(7,10)=1d = \gcd(7,10) = 1. Since 1∣31 \mid 3, a solution exists, and it is unique mod 1010. 2. Find 7−1(mod10)7^{-1} \pmod{10} via Extended Euclid: 7⋅3=21≡1(mod10)7 \cdot 3 = 21 \equiv 1 \pmod{10}, so 7−1≡37^{-1} \equiv 3. 3. Multiply: x≡3⋅3=9(mod10)x \equiv 3 \cdot 3 = 9 \pmod{10}. 4. Check: 7⋅9=63=60+3≡3(mod10)7 \cdot 9 = 63 = 60 + 3 \equiv 3 \pmod{10}. ✓

x≡9(mod10)\boxed{x \equiv 9 \pmod{10}}
ExampleA Congruence with Several Solutions

Solve 6x≡9(mod15)6x \equiv 9 \pmod{15}.

Given: a=6, b=9, m=15a = 6,\ b = 9,\ m = 15. 1. d=gcd⁡(6,15)=3d = \gcd(6,15) = 3. Since 3∣93 \mid 9, the congruence is solvable with exactly 33 incongruent solutions mod 1515. 2. Divide through by 33: 2x≡3(mod5)2x \equiv 3 \pmod 5. 3. Solve the reduced congruence: 2−1≡3(mod5)2^{-1} \equiv 3 \pmod 5 (since 2⋅3=6≡12\cdot 3 = 6 \equiv 1), so x≡3⋅3=9≡4(mod5)x \equiv 3\cdot 3 = 9 \equiv 4 \pmod 5. Take x0=4x_0 = 4. 4. Lift using [5] with m/d=5m/d = 5: x≡4, 4+5, 4+10(mod15)x \equiv 4,\ 4+5,\ 4+10 \pmod{15}. 5. Check x=4x=4: 6⋅4=24=15+9≡96\cdot4 = 24 = 15+9 \equiv 9. ✓

x≡4, 9, 14(mod15)\boxed{x \equiv 4,\ 9,\ 14 \pmod{15}}

Common Misconceptions

⚠️ Common mistake

You cannot always cancel a common factor. From 6≡6(mod4)6 \equiv 6 \pmod{4}... harmless, but from 2⋅3≡2⋅1(mod4)2 \cdot 3 \equiv 2 \cdot 1 \pmod 4 you may not conclude 3≡1(mod4)3 \equiv 1 \pmod 4 — it happens to be false (3≢1(mod4)3 \not\equiv 1 \pmod 4). Cancellation of cc is legal only when gcd⁡(c,m)=1\gcd(c,m)=1; otherwise the modulus must shrink to m/gcd⁡(c,m)m/\gcd(c,m) as in [6]. A second frequent error is treating ax≡b(modm)ax \equiv b \pmod m as if it always has a unique solution like a real equation; the solution count is gcd⁡(a,m)\gcd(a,m), which may be 00 (no solutions) or larger than 11.

Counterexample

Consider 2x≡3(mod4)2x \equiv 3 \pmod 4. Here d=gcd⁡(2,4)=2d = \gcd(2,4) = 2 but 2∤32 \nmid 3, so no solution exists. Indeed 2x2x is always even, hence 2x  4∈{0,2}2x \bmod 4 \in \{0, 2\} and can never equal 33. This shows the criterion d∣bd \mid b is genuinely necessary: an innocent-looking linear congruence can be outright unsolvable.

Connections

connection

Congruences are the foundation of Modular Arithmetic and the ring structure of Quotient Rings: Z/mZ\mathbb{Z}/m\mathbb{Z} is the prototypical quotient. Systems of simultaneous congruences with coprime moduli are solved by the Chinese Remainder Theorem, which reassembles the ring as a product Z/m1×⋯×Z/mk\mathbb{Z}/m_1 \times \cdots \times \mathbb{Z}/m_k. The invertibility criterion gcd⁡(a,m)=1\gcd(a,m)=1 identifies the Units in Modular Arithmetic, whose count is Euler's Totient Function φ(m)\varphi(m), and whose order theory yields Fermat's Little Theorem and Euler's Theorem. The constructive engine throughout is the Extended Euclidean Algorithm.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- 3rd c. CE — Sun Tzu's Sunzi Suanjing poses the first recorded simultaneous-congruence problem (counting an unknown by remainders), seeding the Chinese Remainder Theorem.
- 1247 — Qin Jiushao gives a general procedure (Dayan rule) for solving simultaneous congruences with non-coprime moduli.
- 1640 — Fermat states his little theorem ap≡a(modp)a^{p} \equiv a \pmod p in correspondence.
- 1736 — Euler publishes the first proof of Fermat's little theorem and later generalizes it via φ(m)\varphi(m).
- 1801 — Gauss's Disquisitiones Arithmeticae introduces the ≡\equiv notation, the term "congruence," and the systematic theory of linear and quadratic congruences.
- 1832 — Gauss extends congruences to Gaussian integers, broadening the modulus concept beyond Z\mathbb{Z}.
- 1801–1900s — Dirichlet, Dedekind, and Kronecker recast congruences as ideal-theoretic statements, birthing the ring Z/mZ\mathbb{Z}/m\mathbb{Z} and modern algebra.
- 1949 — D. H. Lehmer formalizes the linear congruential generator for computing.
- 1977 — Rivest, Shamir, and Adleman base RSA on linear and exponential congruences, turning the theory into critical infrastructure.

Subtleties & Limits

open-problem

While linear congruences are completely solved by the gcd criterion, their nonlinear cousins remain deep. Solving ax≡b(modm)ax \equiv b \pmod m is trivial, but solving the discrete logarithm ax≡b(modm)a^x \equiv b \pmod m has no known efficient classical algorithm and underlies modern cryptography; Shor's quantum algorithm solves it in polynomial time, so its real-world hardness is conditional. Likewise, counting or finding solutions to general polynomial congruences mod composite mm is intimately tied to integer factorization. Even the distribution of solutions of ax≡bax \equiv b as a,b,ma, b, m vary feeds open questions in analytic number theory about equidistribution of residues and the spacing of modular inverses (the Lehmer problem on ∑\sum of x⋅x−1x \cdot x^{-1}).

See Also

Modular Arithmetic · Chinese Remainder Theorem · Extended Euclidean Algorithm · Euler's Totient Function · Fermat's Little Theorem · Quadratic Reciprocity · Quotient Rings · Discrete Logarithm