Modular Arithmetic and Congruences

April 12, 2026

Problem

Compute 37 mod 5 and 123 mod 7. Show clock arithmetic and the number wheel visualization.

Explanation

What is modular arithmetic?

Modular arithmetic is "clock arithmetic" — numbers wrap around after reaching a certain value (the modulus). When we write amodna \mod n, we mean the remainder when aa is divided by nn.

Step-by-step: Compute 37mod537 \mod 5

Step 1 — Divide: 37÷5=737 \div 5 = 7 remainder 22.

Step 2 — The remainder is the answer: 37mod5=237 \mod 5 = 2.

Alternatively: 37=5×7+237 = 5 \times 7 + 2, so the remainder is 22.

Interpretation: On a clock with 5 positions (0, 1, 2, 3, 4), counting to 37 lands you at position 2.

Step-by-step: Compute 123mod7123 \mod 7

123÷7=17123 \div 7 = 17 remainder 44. So 123mod7=4123 \mod 7 = 4.

Check: 7×17=1197 \times 17 = 119, and 123119=4123 - 119 = 4 ✓.

Congruence notation

We write ab(modn)a \equiv b \pmod{n} (read "aa is congruent to bb mod nn") when aa and bb have the same remainder when divided by nn. Equivalently, nn divides (ab)(a - b).

Examples: 372(mod5)37 \equiv 2 \pmod{5}, 3712(mod5)37 \equiv 12 \pmod{5}, 373(mod5)37 \equiv -3 \pmod{5}.

Arithmetic with mods

You can add, subtract, and multiply before or after taking the mod — the result is the same:

  • (a+b)modn=[(amodn)+(bmodn)]modn(a + b) \mod n = [(a \mod n) + (b \mod n)] \mod n
  • (a×b)modn=[(amodn)×(bmodn)]modn(a \times b) \mod n = [(a \mod n) \times (b \mod n)] \mod n

Example: 37×123mod5=(2×4)mod5=8mod5=337 \times 123 \mod 5 = (2 \times 4) \mod 5 = 8 \mod 5 = 3.

Check: 37×123=455137 \times 123 = 4551. 4551/5=9104551 / 5 = 910 remainder 11... let me recalculate. 37×123=455137 \times 123 = 4551. 4551=5×910+14551 = 5 \times 910 + 1. So 4551mod5=14551 \mod 5 = 1. And (2×4)mod5=8mod5=3(2 \times 4) \mod 5 = 8 \mod 5 = 3. Wait — 123mod5=3123 \mod 5 = 3 (not 4, that was mod 7). Let me redo: 123mod5=3123 \mod 5 = 3 because 123=5×24+3123 = 5 \times 24 + 3. So (2×3)mod5=6mod5=1(2 \times 3) \mod 5 = 6 \mod 5 = 1 ✓.

Real-world uses

  • Clock time: Hours are mod 12 (or 24). 15:00 = 3:00 PM = 15mod12=315 \mod 12 = 3.
  • Days of the week: mod 7. If today is Wednesday (day 3), what day is it in 100 days? (3+100)mod7=103mod7=5(3 + 100) \mod 7 = 103 \mod 7 = 5 = Friday.
  • ISBN check digits, credit card validation (Luhn algorithm), cryptography (RSA).

Try it in the visualization

Enter a number and modulus. The "number wheel" shows positions 0 to n1n-1, and an arrow points to amodna \mod n. Animate counting around the wheel to see the wrapping. Toggle arithmetic operations to see how mod distributes over addition and multiplication.

Interactive Visualization

Parameters

37.00
5.00
23.00
Your turn

Got your own math or physics problem?

Turn any problem into an interactive visualization like this one — powered by AI, generated in seconds. Free to try, no credit card required.

Sign Up Free to Try It30 free visualizations every day
Modular Arithmetic and Congruences | MathSpin