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:

17mod  5=217 \mod 5 = 2

That’s it. Mod = remainder.


Reading Mod

When you see amod  na \mod n, ask yourself:

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


Examples:

ExpressionDivisionRemainder
10mod  310 \mod 310÷3=310 \div 3 = 3 r 11
15mod  515 \mod 515÷5=315 \div 5 = 3 r 00
7mod  107 \mod 107÷10=07 \div 10 = 0 r 77
23mod  723 \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?

15mod  12=315 \mod 12 = 3

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


What about 27 hours after 12?

27mod  12=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 xmod  nx \mod n is always between 00 and n−1n - 1.

ModulusPossible results
mod  5\mod 50, 1, 2, 3, 4
mod  12\mod 120, 1, 2, 3, …, 11
mod  2\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:

M65537mod  nM^{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.