Modular Arithmetic
Finding a Remainder
Find $47 \bmod 6$.
Find the largest multiple of 6 that is not more than 47: $6 \times 7 = 42$, while $6 \times 8 = 48$ is already too big = $42$
Write 47 as quotient times 6 plus remainder: $47 = 7 \times 6 + 5$ = remainder $5$
Check that the remainder is between 0 and 5: $0 \leq 5 \leq 5$, so it is a valid remainder = $47 \bmod 6 = 5$
Answer: $47 \bmod 6 = 5$, so $47 \equiv 5 \pmod{6}$. The quotient $7$ is not part of the answer.
100 Hours on a Clock
It is 9 o'clock. Where will the hour hand point 100 hours from now?
Remove the full turns: one turn of the clock is 12 hours: $100 = 8 \times 12 + 4$, and 8 full turns change nothing = $100 \bmod 12 = 4$
Add the remaining hours to the start: $9 + 4 = 13$ = $13$
Reduce again, because the dial has no 13: $13 = 1 \times 12 + 1$ = $13 \bmod 12 = 1$
Answer: The hand points at 1. In one line: $9 + 100 = 109 = 9 \times 12 + 1$, so $109 \equiv 1 \pmod{12}$.
Reduce First, Then Multiply
Find $(38 \times 27) \bmod 5$ without multiplying the large numbers.
Reduce each factor modulo 5: $38 = 7 \times 5 + 3$ and $27 = 5 \times 5 + 2$ = $38 \equiv 3$ and $27 \equiv 2 \pmod{5}$
Multiply the remainders: $3 \times 2 = 6$ = $6$
Reduce the product: $6 = 1 \times 5 + 1$ = $1$
Check with the full product: $38 \times 27 = 1026 = 205 \times 5 + 1$ = same remainder $1$
Answer: $(38 \times 27) \bmod 5 = 1$. Reducing first gave the same result with only $3 \times 2$.
Going Back in the Calendar
Today is Wednesday. Which day of the week was it 30 days ago? Number the days Monday $= 0$, Tuesday $= 1$, and so on up to Sunday $= 6$.
Give today its number: Monday $= 0$, Tuesday $= 1$, Wednesday $= 2$ = $2$
Going back in time means subtracting: $2 - 30 = -28$ = $-28$
Find the remainder 0 to 6 of the negative number: $-28 = (-4) \times 7 + 0$ = $-28 \bmod 7 = 0$
Turn the number back into a day: Day $0$ is Monday = Monday
Answer: 30 days ago it was a Monday. Check: 28 days ago was a Wednesday (exactly 4 weeks), and two more days back is Monday.
The Last Digit of a Huge Power
What is the last digit of $3^{100}$?
The last digit is the remainder modulo 10. List the first powers: $3^1 = 3$, $3^2 = 9$, $3^3 = 27$, $3^4 = 81$ = last digits $3, 9, 7, 1$
Spot the cycle: $3^5 = 243$ ends in 3 again, because the next last digit depends only on the previous one = cycle length $4$
Find where the exponent 100 lands in the cycle: $100 = 25 \times 4 + 0$ = $100 \bmod 4 = 0$
Remainder 0 means the last place of the cycle: $3^{100} = (3^4)^{25} \equiv 1^{25} = 1 \pmod{10}$ = last digit $1$
Answer: $3^{100}$ ends in $1$, even though it has 48 digits.
Mistake: Writing $-3 \bmod 12 = -3$ (or $3$)
Why: A remainder must be one of $0, 1, \ldots, n - 1$. Going 3 hours back from 12 o'clock does not land on a negative number, and not on 3 either.
Correct: Add the modulus until the number is in range: $-3 + 12 = 9$, so $-3 \bmod 12 = 9$.
Mistake: Saying that 9 o'clock plus 4 hours is 13 o'clock on a 12-hour clock
Why: The sum $9 + 4 = 13$ is right, but the last reduction is missing. Every result has to be reduced again.
Correct: $13 \bmod 12 = 1$: the clock shows 1.
Mistake: Giving the quotient instead of the remainder: $47 \bmod 6 = 7$
Why: $47 \div 6 = 7$ remainder $5$. The mod operation keeps only what is left over, not how many times 6 fits into 47.
Correct: $47 \bmod 6 = 5$, because $47 = 7 \times 6 + 5$.
Mistake: Reducing the exponent by the modulus: $2^9 \bmod 7$ becomes $2^2 = 4$ because $9 \bmod 7 = 2$
Why: You may reduce the base modulo $n$, but not the exponent. The exponent follows the length of the power cycle, which here is 3, not 7.
Correct: Powers of 2 modulo 7 are $2, 4, 1, 2, 4, 1, \ldots$ (cycle length 3). $9 \bmod 3 = 0$, so $2^9 \equiv 1 \pmod{7}$. Check: $512 = 73 \times 7 + 1$.
Calendars: Which Day Will It Be?
A week has 7 days, so the days of the week repeat modulo 7. Calendar apps, timetables and birthday puzzles use this all the time.
A normal year has $365$ days and $365 = 52 \times 7 + 1$. So a birthday on a Monday this year falls on a Tuesday next year (unless 29 February comes in between).
Barcodes and Check Digits
The last digit of every EAN-13 barcode is a check digit, chosen with arithmetic modulo 10. The scanner computes it again and rejects a code with a misread digit.
For the book code $978030640615$ the weighted sum (weights $1, 3, 1, 3, \ldots$) is $93$, and $93 \bmod 10 = 3$. The check digit is $10 - 3 = 7$, so the full code is $9780306406157$.
Shift Work and the 24-Hour Clock
Train timetables, hospital shifts and flight plans use the 24-hour clock, which is arithmetic modulo 24.
A night shift starts at 22:00 and lasts 9 hours: $22 + 9 = 31$ and $31 \bmod 24 = 7$, so it ends at 07:00.
$a \bmod n$ is the remainder of $a \div n$ and is always one of $0, 1, \ldots, n - 1$
$a \equiv b \pmod{n}$ means that $a$ and $b$ leave the same remainder, which is the same as $n$ dividing $a - b$
A clock is arithmetic modulo 12, the 24-hour clock modulo 24, the days of the week modulo 7 and even/odd modulo 2
In sums, differences and products you may reduce every number first, then reduce the result once more
For a negative number add $n$ until it lands in $0, \ldots, n - 1$: $-3 \bmod 12 = 9$
Powers repeat in cycles modulo $n$: find the cycle length and reduce the exponent modulo that length, not modulo $n$
Q: Is $a \bmod n$ the same as the remainder my calculator or computer shows?
A: For positive numbers, yes. For negative numbers many programming languages give a negative result, for example $-3$ for $-3$ divided by $12$. In mathematics the remainder is always between $0$ and $n - 1$, so $-3 \bmod 12 = 9$. The calculator on this page works that way: mod(-3, 12) gives 9.
Q: What does the symbol $\equiv$ mean?
A: It is read as "is congruent to". $17 \equiv 5 \pmod{12}$ says that 17 and 5 leave the same remainder when you divide by 12 (both leave 5). It is weaker than $=$: congruent numbers can be different numbers that land on the same spot of the dial.
Q: Why may I reduce the numbers first?
A: Write $a = pn + r$ and $b = qn + s$. Then $a + b = (p + q)n + (r + s)$ and $a \times b = (pqn + ps + qr)n + rs$. The parts with $n$ are multiples of $n$ and leave no remainder, so only $r + s$ and $r \times s$ decide the result.
Q: Where is modular arithmetic used outside of school?
A: In check digits (barcodes, ISBN, the IBAN of a bank account, which is checked modulo 97), in computer science (hash tables, random number generators) and in cryptography: the RSA method that protects online banking computes with huge numbers modulo a product of two primes.
Modular Arithmetic
1 / 14
Modular Arithmetic
Learn clock arithmetic: remainders, a mod n, congruence modulo n, and how to use them for calendars, check digits and the last digit of huge powers.