Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

How to Do Modular Arithmetic

When only the remainder matters, you never need the full number. Replace each number by its remainder, add, subtract or multiply the remainders, and reduce again; for large powers, find the cycle of remainders.

Recognize the task

Wording such as "find the remainder when … is divided by nn", "last digit of", "what day of the week", or congruences like a≡b(modn)a \equiv b \pmod{n}. Typical inputs: (47⋅38+125) mod 9(47 \cdot 38 + 125) \bmod 9, 350 mod 73^{50} \bmod 7, the last digit of 71007^{100}. Test: the question asks only for a remainder, not for the value itself.
The remainder a mod na \bmod n and congruence are defined in the modulo lesson; the operations are developed in modular arithmetic.

Two ways to do it

Reduce, then operatesums and products
(a⋅b) mod n=((a mod n)⋅(b mod n)) mod n(a \cdot b) \bmod n = \big((a \bmod n) \cdot (b \bmod n)\big) \bmod n
Replacing a number by a congruent one never changes the remainder (the core principle); the same holds for ++ and −-.
Power cycleslarge powers
ak≡ak mod m(modn)(cycle of length m through 1)a^{k} \equiv a^{k \bmod m} \pmod{n} \quad (\text{cycle of length } m \text{ through } 1)
The remainders of a,a2,a3,…a, a^2, a^3, \ldots repeat; reduce the exponent by the cycle length, not by nn.

Steps

StepOn (47⋅38+125) mod 9(47 \cdot 38 + 125) \bmod 9
1Reduce each number modulo n. Divide by nn and keep the remainder (how to compute a remainder). For n=9n = 9, the digit sum gives it quickly.47≡247 \equiv 2,   38≡2\; 38 \equiv 2,   125≡8(mod9)\; 125 \equiv 8 \pmod{9}
2Do the operations on the remainders. Follow the usual order of operations.2⋅2+8=122 \cdot 2 + 8 = 12
3Reduce the result. The final answer must lie between 00 and n−1n - 1.12 mod 9=312 \bmod 9 = 3
4Check with the full numbers, if they are small. Both routes give the same remainder.47⋅38+125=1911=9⋅212+347 \cdot 38 + 125 = 1911 = 9 \cdot 212 + 3

Worked examples

Example 1 · last digit of a sum

mod 10
(1234+5678) mod 10(1234 + 5678) \bmod 10
last digit means mod 1010
4+8=124 + 8 = 12
keep only the last digits
12 mod 10=212 \bmod 10 = 2
reduce

Example 2 · a product

mod 7
53≡453 \equiv 4,   29≡1(mod7)\; 29 \equiv 1 \pmod{7}
subtract 4949 and 2828
(53⋅29) mod 7=(4⋅1) mod 7(53 \cdot 29) \bmod 7 = (4 \cdot 1) \bmod 7
multiply the remainders
44
check: 1537=7⋅219+41537 = 7 \cdot 219 + 4

Example 3 · a large power

cycle
31,32,…,36 mod 73^1, 3^2, \ldots, 3^6 \bmod 7:   3,2,6,4,5,1\; 3, 2, 6, 4, 5, 1
the cycle has length 66
50=6⋅8+250 = 6 \cdot 8 + 2
reduce the exponent by 66
350≡32=9≡2(mod7)3^{50} \equiv 3^2 = 9 \equiv 2 \pmod{7}
same place as 323^2
See how remainders wrap around a circle in the modular wheel.

See it happen

Picture a clock with nn positions, 00 to n−1n - 1. Every whole number lands on one position, and adding nn just goes once around the clock. Adding two numbers means walking the first distance and then the second, and the position you end on depends only on where each walk ends, not on how many full turns it made. That is why you can drop the full turns, which is reducing mod nn, at any point.

Common mistakes

Reducing the exponent by the modulus

✗ 350 mod 73^{50} \bmod 7: 50 mod 7=150 \bmod 7 = 1, so the answer is 33
✓ the powers repeat every 66 steps: 50 mod 6=250 \bmod 6 = 2, so 350≡32≡23^{50} \equiv 3^2 \equiv 2

Dividing remainders

✗ (42÷6) mod 4=(2÷2)=1(42 \div 6) \bmod 4 = (2 \div 2) = 1
✓ 42÷6=742 \div 6 = 7 and 7 mod 4=37 \bmod 4 = 3; division does not carry over to remainders (why division is different)

Forgetting the final reduction

✗ (7+8) mod 9=15(7 + 8) \bmod 9 = 15
✓ 15 mod 9=615 \bmod 9 = 6

Reading remainder 0 as the first place in a cycle

✗ last digit of 2202^{20}: 20=4⋅5+020 = 4 \cdot 5 + 0, first place of 2,4,8,62, 4, 8, 6, so 22
✓ remainder 00 means the last place of the cycle: the last digit is 66