Discrete Mathematics Module 4: Modular Arithmetic

Learn how the modulus operator works, how to calculate remainders and how to visualise modular arithmetic using circles and clocks.

← Back to Module Overview

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

βœ… 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.

🧠 Quick Quiz: Modular Arithmetic

1. What does the modulus operator return?


2. What is the result of 7 mod 3?


3. What is the value of 12 mod 4?


4. How can you visualise modular arithmetic?


5. What happens in modular arithmetic when you reach the modulus value while counting?


Celestial Ant
β€œNeed guidance?”