core28 min studyLesson 124 in Mathematics

Modular arithmetic and invertible residues

Compute with congruence classes while recognizing exactly when cancellation and division are valid.

On this page

What you’ll understand

  • Interpret congruence as divisibility of a difference.
  • Construct a modular inverse from a Bézout identity.
  • Solve linear congruences without invalid cancellation.

A clock does not forget how much time has passed by making an arithmetic mistake. It deliberately identifies times whose difference is a whole number of turns. Congruence formalizes this choice for any positive integer modulus. Addition and multiplication survive the identification, but division needs special care. Our goal is to replace the vague instruction “wrap around” with exact rules for representatives, inverse elements, and the number of solutions of an equation.

Work with classes, compute with representatives

Fix an integer modulus m at least two. Integers a and b are congruent modulo m if m divides their difference. The class containing a consists of a plus all integer multiples of m. Choosing a different representative changes the written integer but not its class. The usual representatives from zero through m − 1 are convenient, not mathematically privileged; negative representatives can simplify calculations considerably.

Addition and multiplication are well defined because replacing an input by a multiple of m changes the result by another multiple of m. For multiplication, expand the two replaced representatives and inspect each extra term. This is the reason that one may reduce intermediate products before they grow large. Equality of integers is stronger than congruence: 17 and 5 are not equal integers, although they represent the same class modulo 12.

a≡b(modm) ⟺ m∣(a−b),[a]+[b]=[a+b],[a][b]=[ab]a\equiv b\pmod m\ \Longleftrightarrow\ m\mid(a-b),\qquad [a]+[b]=[a+b],\quad[a][b]=[ab]
The square brackets denote congruence classes for the fixed modulus. Operations do not depend on the chosen representatives.↔ Scroll wide equations horizontally.

Division means multiplication by an inverse

A residue a is invertible when some integer u satisfies au congruent to one modulo m. Such a u exists exactly when gcd(a, m) is one. One direction follows because a common divisor would divide both au and m, and hence one. Conversely, a Bézout equation au + mv = 1 immediately supplies an inverse. The inverse is unique as a residue class, though it has infinitely many integer representatives.

Do not cancel a nonunit while keeping the same modulus. For example 2 × 1 and 2 × 4 are congruent modulo 6, but 1 and 4 are not. A general linear congruence ax congruent to b modulo m has solutions exactly when d = gcd(a, m) divides b. When m/d is greater than one, dividing a, b, and m by d gives an invertible reduced coefficient; the original modulus then contains d distinct lifted solutions. If d = m and d divides b, both original coefficients are zero modulo m, and every residue x is a solution; the reduced congruence modulo one is automatic.

ax≡b(modm)⟺adx≡bd(modm/d)(d=gcd⁡(a,m), d∣b)ax\equiv b\pmod m\quad\Longleftrightarrow\quad \frac ad x\equiv\frac bd\pmod{m/d}\qquad(d=\gcd(a,m),\ d\mid b)
Division is performed on the corresponding integer divisibility equation and changes the modulus. The resulting reduced congruence has a unique class modulo m/d.↔ Scroll wide equations horizontally.

Zero divisors reveal a different arithmetic

A nonzero residue can multiply another nonzero residue to zero when the modulus is composite. Modulo six, two times three is zero. This does not contradict ordinary integer arithmetic; the result six belongs to the zero class. For a prime modulus every nonzero class is invertible, because no smaller positive representative shares a prime factor with the modulus. This is the basic reason prime-modulus arithmetic is especially regular.

Keep the object of a computation visible: a representative, a residue class, or an integer equation. If an application requires an actual range of values, a modular solution must be intersected with that range afterward. Efficient modular exponentiation similarly depends on reducing products, never on replacing an exponent without justification. Later exponent theorems will provide legitimate periods, but they require invertibility assumptions that cannot be inferred from the notation alone.

One congruence, several residue solutions

Solve 8x ≡ 12 modulo 20 and list the solutions among 0 through 19.

  1. Compute gcd(8, 20) = 4. Because 4 divides 12, solutions exist. Divide the integer divisibility relation by 4 to obtain 2x ≡ 3 modulo 5.

  2. The inverse of 2 modulo 5 is 3, since 2 × 3 = 6 ≡ 1. Multiply to get x ≡ 9 ≡ 4 modulo 5.

  3. Lift this class into the original range: x = 4, 9, 14, or 19. Check that their products with 8 all differ from 12 by multiples of 20; there are exactly four such classes modulo 20.

The result

The solutions modulo 20 are 4, 9, 14, and 19. Dividing the coefficient without changing the modulus would lose valid solutions.

Explore the model

Interactive lab

Interactive lab · modular

An inverse inside an additive orbit

Pause and reset the lab, then set both controls: modulus m = 15 and additive step a = 4. Predict the first return to zero after fifteen steps and the visit to residue one at index four, since 4 × 4 ≡ 1 modulo 15. For a fresh comparison, pause and reset again, then set modulus m = 15 and additive step a = 6. Predict only five visited residues because gcd(6, 15) = 3. The lab repeatedly adds the step; its additive period must not be confused with multiplicative order or primitive-root generation.

An inverse inside an additive orbitAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA full additive orbit corresponds to a unit step, while a modular inverse identifies the index where that orbit reaches one.

Check your understanding

Which residue has an inverse modulo 15?

Try it yourself

Solve 6x ≡ 9 modulo 15, and explain why simply canceling 3 while retaining modulus 15 gives the wrong problem.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

First use the gcd criterion, then reduce the modulus along with both coefficients.

Compare with the solution

The gcd is 3 and divides 9. Dividing the divisibility equation 15 divides 6x − 9 by 3 gives 5 divides 2x − 3. Thus 2x ≡ 3 modulo 5, whose inverse coefficient gives x ≡ 4 modulo 5. The original solutions modulo 15 are 4, 9, and 14. Retaining modulus 15 after cancellation would require 15 to divide 2x − 3, which is a stronger condition and would wrongly discard solutions such as x = 4.

Take it with you

  • A congruence identifies integers whose difference is divisible by the modulus.
  • A residue can be divided out only when its inverse exists, or after a justified modulus reduction.
  • Composite moduli can have nonzero zero divisors and multiple linear-congruence solutions.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.