The Mod Operation

What is Mod?

The mod operation gives you the remainder after division.


Example:

17÷5=3 remainder 217 \div 5 = 3 \text{ remainder } 2

So:

17mod5=217 \mod 5 = 2

That’s it. Mod = remainder.


Reading Mod

When you see amodna \mod n, ask yourself:

“If I divide aa by nn, what’s left over?”


Examples:

ExpressionDivisionRemainder
10mod310 \mod 310÷3=310 \div 3 = 3 r 11
15mod515 \mod 515÷5=315 \div 5 = 3 r 00
7mod107 \mod 107÷10=07 \div 10 = 0 r 77
23mod723 \mod 723÷7=323 \div 7 = 3 r 22

The Clock Analogy

Think of a 12-hour clock.

What time is it 15 hours after 12 o’clock?

15mod12=315 \mod 12 = 3

It’s 3 o’clock. The hour hand wrapped around past 12.


What about 27 hours after 12?

27mod12=327 \mod 12 = 3

Still 3 o’clock. It wrapped around twice, but landed in the same spot.


The Key Insight

Numbers that differ by the modulus land on the same spot.

33, 1515, 2727, 3939 all give remainder 33 when divided by 1212.

We say these numbers are congruent modulo 12.


The Range of Results

The result of xmodnx \mod n is always between 00 and n1n - 1.

ModulusPossible results
mod5\mod 50, 1, 2, 3, 4
mod12\mod 120, 1, 2, 3, …, 11
mod2\mod 20, 1

Mod keeps numbers in a fixed range. They wrap around instead of growing forever.


Why This Matters for Cryptography

In cryptography, we work with huge numbers.

RSA encryption computes things like:

M65537modnM^{65537} \mod n

Without mod, that exponentiation would produce a number with millions of digits.

With mod, the result stays manageable. Always less than nn.