Modular arithmetic is a way of working with numbers where results wrap around after reaching a certain value called the modulus. It appears in number theory, cryptography and many algorithms in computer science.
In this module you will see how mod works through remainders and how to build a strong intuition using clock style visualisations.
"If normal arithmetic is a straight line, modular arithmetic is a circle. Once you reach the end, you loop back to the start."
β Understanding modulus
The modulus operation finds the remainder when one number is divided by another. If A is the dividend and B is the divisor, then A mod B = R, where R is the remainder.
Example: 8 mod 4 = 0 because 8 divided by 4 is exactly 2 with no remainder.
π Modulo on a clock
You can think of modular arithmetic as counting around a circle with numbers from 0 up to B - 1. To find A mod B, start at 0 and move A steps around the circle. The number you land on is the result.
Example: 5 mod 3 = 2. Count 5 steps around a circle marked 0, 1, 2.
If A is negative, you move in the opposite direction around the circle. The goal is still to find where you land after wrapping around.
π What you will learn
- How the modulus operator relates to division with remainder
- How to reason about modular arithmetic using clock style diagrams
- How wrapping around makes patterns repeat in cycles
- Why mod is useful in computer science and number theory
β Key takeaway
Modular arithmetic lets you focus on remainders instead of full division results. This idea of wrapping around is a core tool for hashing, cryptography and many algorithmic tricks.