Skip to content
LoveToCalc

Definition — what does that mean?

Congruence and modular arithmetic

The remainder when a whole number is divided by n, and what it means for two numbers to be congruent. Including negative numbers, where a calculator often gives the wrong answer.

In Swedish: Kongruens och moduloräkning

amodn=a−n⌊an⌋

a
Whole number
n
Modulus

Practice questions

Work out

−8mod4

What the definition says

for a whole number a and a whole number n ≥ 1. ⌊a/n⌋ is the largest whole number not greater than a/n, that is a/n rounded down. The result is the remainder when a is divided by n, and it lies between 0 and n − 1.

Two whole numbers a and b are congruent modulo n, written a ≡ b (mod n), when they leave the same remainder:

So a congruence is a statement about two numbers, while a mod n is a number.

Worked examples

A positive number. 47 mod 5: 47/5 = 9.4 and ⌊9.4⌋ = 9, so 47 mod 5 = 47 − 5 · 9 = 2. Check: 47 = 5 · 9 + 2.

A negative number. −7 mod 3: −7/3 ≈ −2.33. Rounded down, that is −3, not −2. So −7 mod 3 = −7 − 3 · (−3) = −7 + 9 = 2. Check: −7 = 3 · (−3) + 2, and 2 lies between 0 and 2.

A congruence. 38 ≡ 14 (mod 12), because 38 mod 12 = 2 and 14 mod 12 = 2. The difference 38 − 14 = 24 is divisible by 12. This is clock arithmetic: 38 hours after midnight, a 12-hour clock shows the same as 14 hours after midnight, 2 o’clock.

The negative remainder

Negative numbers are where most mistakes happen. Many calculators and programming languages divide and cut off the decimals, so −7/3 becomes −2 instead of −3. The remainder then comes out as −7 − 3 · (−2) = −1 instead of 2.

a n a/n Cut off Rounded down Wrong remainder a mod n
47 5 9.4 9 9 2 2
−7 3 −2.33 −2 −3 −1 2
−23 6 −3.83 −3 −4 −5 1
−8 4 −2 −2 −2 0 0

For positive numbers the two methods agree. For negative numbers that do not divide evenly they differ by n. A negative remainder is corrected by adding n: −1 + 3 = 2.

Calculating with remainders

Sums and products can be worked remainder by remainder:

Days of the week. If today is a Thursday, which day is it in 100 days? 100 mod 7 = 2, so it is two days after Thursday: Saturday.

A large power. 2¹⁰ mod 7: since 2³ = 8 ≡ 1 (mod 7), 2⁹ = (2³)³ ≡ 1, and 2¹⁰ = 2⁹ · 2 ≡ 2 (mod 7). Check: 1,024 = 7 · 146 + 2.

Common mistakes

Common questions

What does mod stand for? Mod is short for the Latin modulus, roughly “measure”. a mod n is the remainder on division by n, and n is called the modulus.

How can I tell that a number is divisible by n? A number a is divisible by n exactly when a mod n = 0, that is a ≡ 0 (mod n). The greatest common divisor rests on the same idea.

Why do spreadsheets and programming languages disagree? The MOD function in Excel and Google Sheets returns a remainder with the sign of the divisor, so MOD(−7, 3) is 2. The % operator in several programming languages, JavaScript and C among them, returns −1 instead, because it cuts the quotient off.

Last reviewed October 8, 2026 ·How pages are reviewed

ArithmeticAll formulas