1 of 4

Your RightSignal

Cryptography from zero · 2 of 111 / 3

Modular arithmetic

The concept

Why 9 hours after 10 o'clock is 7, not 19

Modular arithmetic is maths where numbers wrap around at a fixed size n, called the modulus. 'a mod n' is the remainder of a ÷ n. A clock is mod 12: 10 + 9 = 19, which wraps around to 7.

Numbers with the same remainder are called congruent, written 19 ≡ 7 (mod 12). To add, subtract or multiply, work it out as usual and then take the remainder. Subtraction wraps backwards, so 1 − 3 ≡ 10 (mod 12).

To divide, you multiply by an inverse, the number that gives 1 when you multiply by it. Mod 7, 3 × 5 = 15 ≡ 1, so 5 acts as 1/3. With a prime modulus, every non-zero number has an inverse.