Clock arithmetic
This dial counts 0 to 11, then starts again. Start at 9 and add 5 hours: 10, 11, 0, 1, 2. You land on 2, not 14. Counting that wraps around like this is called modular arithmetic.
14 mod 12 means: divide 14 by 12 and keep the remainder. 14 ÷ 12 = 1, remainder 2, so 14 mod 12 = 2. The 12 is called the modulus. Python writes mod as %: 14 % 12 gives 2.
Any whole number splits into full laps of the dial plus a leftover: 14 = 1 × 12 + 2. The leftover is always 0 to 11, never 12 or more. divmod(14, 12) gives both parts: (1, 2).
Same remainder
2, 14 and 26 all land on the same spot, because each is 2 more than some full laps. We write 26 ≡ 2 (mod 12) and say 26 is congruent to 2, mod 12. They share the remainder 2.
Big jumps can shrink first. 29 hours is 2 full laps plus 5, because 29 % 12 = 5. So 9 + 29 lands where 9 + 5 does: on 2. In code, (9 + 29) % 12 equals (9 + 5) % 12.
Subtracting walks the other way round. From 0, step back 3: 11, 10, 9. So -3 mod 12 is 9. Python agrees: -3 % 12 gives 9, because Python's % always answers 0 to 11 when the modulus is 12.
In the machine
A byte has 8 bits, so it holds 0 to 255, then wraps like a dial with 256 spots. 250 + 10 = 260 needs a ninth bit, worth 256. A byte has no room for it, so it keeps 260 % 256 = 4.
Mod by a power of two is cheap. Because 256 = 2⁸, x % 256 is just the lowest 8 bits of x. The & operator keeps a bit only where both numbers have a 1, so 260 & 0xFF (eight 1s) gives 4.
Programs use % to cycle through slots forever. With 12 slots, i = (i + 1) % 12 counts 10, 11, 0, 1: it never runs past the last slot. Ring buffers (lists reused in a circle), clocks and calendars all work this way.
Try it in the Python prompt
;; step 1/9 · Clock arithmetic >>> 9 + 5 14 >>> (9 + 5) % 12 2
A real clock writes 12 where this dial writes 0. In maths the remainders mod 12 are counted from 0, so the spots are 0 to 11. Languages disagree about negative numbers. Python's % takes the sign of the modulus, so -3 % 12 is 9; in C, Java and JavaScript, -3 % 12 is -3.