Maths in Real Life

Modular Arithmetic: Clock Maths, Remainders and Secret Codes

EuclidCurve Smart Team · 2026-11-13 · 8 min read

For young mathematicians in the UK, USA, UAE, Singapore and Hong Kong

You already do modular arithmetic every day. If it is 10 o'clock now, in 5 hours it will be 3 o'clock, not 15 o'clock. A clock forgets everything except the remainder after dividing by 12. Mathematicians call this "working mod 12", and the same idea powers calendars, check digits and the encryption behind every secure website.

Guess first: It is 9 o'clock. What time will the clock show 100 hours from now?

  • 1 o'clock
  • 9 o'clock
  • 5 o'clock

100 = 8 × 12 + 4, so the hand moves 4 hours on from 9: that is 13, which the clock shows as 1 o'clock.

What "mod" means

We write a \equiv b \pmodn, read "a is congruent to b mod n", when a and b leave the same remainder on division by n. Equivalently, n divides a - b. So 17 \equiv 5 \pmod12 and -23 \equiv 2 \pmod5, because -23 = 5 × (-5) + 2.

The golden rule: reduce early

You may add, subtract and multiply congruences, and replace any number by its remainder at any moment. To find the last digit of 7^2026, work mod 10: the powers of 7 end in 7, 9, 3, 1 and then repeat every 4 steps. Since 2026 = 4 × 506 + 2, the last digit is the second in the cycle, 9. No calculator could even display 7^2026, which has more than 1700 digits.

Your turn

What is the remainder when 123456 is divided by 11?

Solution: 6 - 5 + 4 - 3 + 2 - 1 = 3, so 123456 \equiv 3 \pmod11. The same idea gives the digit-sum test for 9, because 10 \equiv 1 \pmod 9.

Dividing needs care: inverses

Division is the one operation you cannot do freely. Mod 6, 2 × 3 \equiv 2 × 0, yet 3 \not\equiv 0. You can "divide by a" only when a has an inverse: a number a^-1 with a × a^-1 \equiv 1 \pmodn. This happens exactly when \gcd(a, n) = 1, and Euclid's algorithm run backwards finds it. For example 7 × 15 = 105 \equiv 1 \pmod26, so 7^-1 \equiv 15 \pmod26.

Your turn

Find the inverse of 3 modulo 11: the number x from 1 to 10 with 3x \equiv 1 \pmod11.

Solution: 3 × 4 = 12 = 11 + 1, so 3^-1 \equiv 4 \pmod11.

Fermat's little theorem

If p is prime and p does not divide a, then a^p-1 \equiv 1 \pmodp. Euler extended this to any modulus: a^\varphi(n) \equiv 1 \pmodn when \gcd(a, n) = 1, where \varphi(n) counts the numbers from 1 to n that are coprime to n. In practice this means huge exponents can be cut down: reduce the exponent mod p - 1 (never mod p).

Your turn

What is the remainder when 2^100 is divided by 13?

Solution: 100 = 12 × 8 + 4, so 2^100 = (2^12)^8 × 2^4 \equiv 1 × 16 \equiv 3 \pmod13.

Secret codes

In the Diffie–Hellman key exchange, two people publish g^a and g^b mod a large prime and both end up with the same secret g^ab, while an eavesdropper who sees everything cannot work it out. RSA encryption sends c = m^e \bmod n and decrypts with c^d \bmod n, where d is the inverse of e modulo (p - 1)(q - 1) and n = pq. Both rely on fast powers by repeated squaring, inverses from Euclid's algorithm, and Fermat's little theorem.

Practice: master modular arithmetic

Guess first: Practice 1: Today is a Friday. What day of the week will it be 100 days from today?

  • Sunday
  • Saturday
  • Monday

100 = 7 × 14 + 2, so 100 \equiv 2 \pmod 7: two days after Friday is Sunday.

Your turn

Practice 2: What is the remainder when 1! + 2! + 3! + … + 50! is divided by 12?

Solution: Every factorial from 4! = 24 on contains 3 × 4 = 12. Only 1! + 2! + 3! = 9 is left, so the remainder is 9.

Your turn

Practice 3: What is the units digit of 3^2026?

Solution: 2026 = 4 × 506 + 2, so the units digit is the second in the cycle 3, 9, 7, 1: it is 9.

Guess first: Practice 4: Which remainders can a perfect square leave when divided by 4?

  • Only 0 or 1
  • 0, 1 or 2
  • Only 1 or 3

Even: (2k)² = 4k² \equiv 0. Odd: (2k+1)² = 4k² + 4k + 1 \equiv 1. So a number like 2027, which is 3 mod 4, can never be a perfect square.

Your turn

Practice 5: What number do the last two digits of 7^100 form?

Solution: 7^4 = 2401 \equiv 1 \pmod100, so 7^100 = (7^4)^25 \equiv 1. The number ends in 01.

Where this shows up in exams: AMC 10 / 12

Remainders, last digits, days of the week and "for how many n" questions appear on almost every AMC 10 and AMC 12 paper. Our AMC course has a 50-question modular arithmetic test with worked solutions.

Explore AMC preparation

Try it at home: the remainder clock

  1. Draw a clock face with the numbers 0 to 6 instead of 1 to 12. This is a mod 7 clock.
  2. Start at 1 and keep multiplying by 3, moving to the remainder mod 7 each time: 1, 3, 2, 6, ...
  3. Write down where you land until you are back at 1. How many steps did it take?
  4. Try multiplying by 2 instead. Do you visit every number this time?
  5. A number that visits every non-zero spot is called a primitive root. Which numbers on your mod 7 clock are primitive roots?

Quick questions

What is modular arithmetic?

Arithmetic with remainders. a ≡ b (mod n) means a and b leave the same remainder when divided by n, or equivalently n divides a − b. A 12-hour clock is arithmetic mod 12.

How do you find the remainder of a huge power?

Reduce the base, find a power that is ≡ 1 (Fermat: a^(p−1) ≡ 1 mod a prime p), and reduce the exponent. For example 2^100 mod 13: 2^12 ≡ 1 and 100 = 12 × 8 + 4, so 2^100 ≡ 2^4 = 16 ≡ 3.

When does a number have an inverse mod n?

Exactly when gcd(a, n) = 1. The inverse can be found by running Euclid's algorithm backwards. For example 3 × 4 = 12 ≡ 1 (mod 11), so the inverse of 3 mod 11 is 4.

Written by the EuclidCurve Smart Team. We are the maths and physics tutors behind EuclidCurve. We teach IB, AMC, ESAT and TMUA students in the UK, USA, UAE, Singapore and Hong Kong, and we write about the maths hiding in everyday life.

Keep exploring

Book a free class · Try today's IMO problem