Core answer: a mod n is the remainder when a is divided by n: 17 mod 5 = 2. It's clock arithmetic — 22:00 plus 5 hours is (22 + 5) mod 24 = 3 AM. Modular arithmetic powers week cycles, checksums (ID card last digit), hash tables, and all of modern public-key cryptography.

The clock intuition

Arithmetic "mod 12" is clock arithmetic: 9 + 8 = 17 ≡ 5 (mod 12). Two numbers are congruent mod n when they differ by a multiple of n: 17 ≡ 5 ≡ 29 (mod 12). You may add, subtract, and multiply freely then reduce — (25 × 34) mod 7 = (4 × 6) mod 7 = 24 mod 7 = 3.

Everyday uses

ApplicationModulusExample
12/24-hour clock12 / 2422 + 5 ≡ 3 (mod 24)
Weekday cycles7100 days from Monday = Thursday (100 mod 7 = 2)
ID card check digit11GB 11643 weighted sum mod 11
ISBN-1011last digit validates the rest
Credit card (Luhn)10catches any single-digit typo
Hash tablestable sizekey mod m picks the bucket

Worked examples

Example 1 — Weekday. Today is Wednesday; what day is it in 45 days? 45 mod 7 = 3 → Wednesday + 3 = Saturday.

Example 2 — Even/odd and divisibility. mod 2 splits parity instantly; mod 9 gives the digit-sum test: 7,281 → 7+2+8+1 = 18 → divisible by 9. "Casting out nines" checks arithmetic: 47×53 = 2,491? 47≡2, 53≡8, product≡16≡7 (mod 9); 2,491 → 16 → 7 ✓.

Example 3 — RSA in one line. Encryption: c = mᵉ mod n; decryption: m = cᵈ mod n. The trapdoor is that factoring n = pq is hard — modular exponentiation is easy to do, impossible to undo without the factors.

Common mistakes and myths

  1. Negative remainders — −7 mod 3: math convention gives 2 (remainder in [0, n)), but C/Java's % gives −1; know your language before hashing negatives.
  2. Dividing in modular arithmetic — division needs the modular inverse, which exists only when gcd(a, n) = 1; "just divide" fails mod composites.
  3. (a × b) mod n ≠ (a mod n) × (b mod n) forgetting the final reduce — the intermediate can overflow; reduce at every step in code.
  4. Assuming mod distributes over exponents directly — use Fermat's little theorem: aᵖ⁻¹ ≡ 1 (mod p) for prime p, so exponents reduce mod (p−1).
  5. Using mod for crypto without care — timing leaks and weak padding break naive implementations; use vetted libraries, never hand-rolled ciphers.