Courses / Mathematics I
Arithmetic and Number Theory

Modular Arithmetic

Mathematics I 333 words Free to read

Arithmetic That Wraps Around

Modular arithmetic is arithmetic with remainders — the mathematics of things that cycle, like clocks, days of the week, and digital registers. We say aa is congruent to bb modulo nn, written ab(modn),a \equiv b \pmod{n}, when aa and bb leave the same remainder on division by nn — equivalently, when n(ab)n \mid (a - b). On a 12-hour clock, 153(mod12)15 \equiv 3 \pmod{12}: 15:00 shows as 3 o'clock.

Congruence modulo nn is an equivalence relation (Unit 1): it partitions the integers into nn residue classes, one per possible remainder 0,1,,n10, 1, \dots, n-1. All integers in a class are interchangeable for mod-nn purposes.

The power of the notation is that congruence is compatible with arithmetic. If aba \equiv b and cd(modn)c \equiv d \pmod n, then: a+cb+d,acbd(modn).a + c \equiv b + d, \qquad a \cdot c \equiv b \cdot d \pmod{n}. You may add, subtract, and multiply congruences just like equations — which means you can reduce as you go, replacing any number by its remainder at any step. To find 1717mod517 \cdot 17 \bmod 5, note 17217 \equiv 2, so 171722=4(mod5)17 \cdot 17 \equiv 2 \cdot 2 = 4 \pmod 5 — no need to compute 289. This is what makes modular arithmetic computationally tame even for huge numbers.

Division is the exception. You cannot freely divide congruences: ab(modn)a \equiv b \pmod n does not always let you cancel a common factor. Division mod nn works only via multiplicative inverses, which exist only when the number is coprime to nn — the reason coprimality (Lesson 4) matters here.

Common pitfall: assuming you can divide or cancel in congruences as freely as you add and multiply. Addition, subtraction, and multiplication respect congruence, but cancellation does not in general: 62(mod4)6 \equiv 2 \pmod 4 but you cannot cancel the common factor 2 to get 31(mod4)3 \equiv 1 \pmod 4 (which is false). Division mod nn requires a multiplicative inverse, available only for numbers coprime to nn.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes
Start Mathematics I free

Arithmetic and Number Theory