CalcHub

Free calculator tools. Fast, simple, no sign up.

The Modulo Operator in Maths and Programming

The modulo operator gives the remainder after division. In maths it is written as mod, and in most programming languages it is the percent sign. It...

The modulo operator gives the remainder after division. In maths it is written as mod, and in most programming languages it is the percent sign. It is small, but it runs clocks, calendars, and many everyday checks.

How it works

17 mod 5 is 2, because 17 divided by 5 is 3 with remainder 2. Clock arithmetic is modulo 12: 10 o'clock plus 5 hours is 3 o'clock, because 15 mod 12 is 3. The same idea works for days of the week: if today is Tuesday, then 10 days from now is Friday, because 10 mod 7 is 3 days forward. In code, n mod 2 tells you whether n is even (0) or odd (1), and n mod 10 gives the last digit of n.

Modulo also checks divisibility: a number is divisible by 3 exactly when the number mod 3 is 0. That is why it appears in checksums, hash functions, and the rules that decide leap years.

Worked example

A shop rotates 4 staff on a weekly rota. Week 23 falls to staff member 23 mod 4, which is 3, so the third person on the rota takes that week.

Common mistakes

The most common confusion is between division and modulo. Division asks how many whole times one number fits into another; modulo asks what is left over.

Try it yourself

What is 29 mod 6, and what day is 29 days after a Monday? (Answer: 29 mod 6 = 5; 29 mod 7 = 1, so Tuesday.)

Putting it together

The best way to make this stick is to use it three times: once while reading this guide, once tomorrow from memory, and once on a fresh problem. Each round takes a few minutes, and by the third the steps feel natural. If a step feels unclear, go back to the worked example and cover the answer while you redo it. Maths is a skill built from small correct repetitions, and this topic is a good place to practise that habit.

A question to ask yourself

Why does this method work? Because each step keeps both sides equal, or keeps the value unchanged. Methods that preserve equality or value are safe to use again and again, and that is why they appear in so many topics.