Calcylator
Modular remainder

Modular remainder:
formula and worked example

The remainder is what is left over after whole divisions, and it repeats in a cycle you can exploit.

Calcylator Editorial Team

Updated · 4 min read

What a remainder tells you

Dividing 137 by 12 does not come out evenly. You can fit eleven whole twelves into 137 and there is a bit left over. That bit is the modular remainder, written 137 mod 12, and it answers the question: how far past the last complete multiple am I?

Anything that cycles uses it. Clock arithmetic is the familiar case: 137 hours after noon is 5 hours past noon, because the clock repeats every 12. Days of the week repeat every 7, so a date a hundred days away falls on the weekday that is 100 mod 7 steps forward. Round-robin scheduling, checksums on identification numbers, and hash tables use the same idea.

The remainder discards how many full cycles have passed and keeps only the position inside the current cycle.

The operation and its two inputs

The remainder is what remains of the number after repeatedly taking away the divisor, until what is left is smaller than the divisor.

Modular remainder =number%divisor
number:
Number
divisor:
Divisor
The result is the leftover after taking out as many whole multiples of the divisor as possible. It is at least zero and less than the divisor for positive inputs.
  • Number: the value being divided, 137 in the example (the dividend).
  • Divisor: the size of one cycle, 12 in the example. It must not be zero.
  • Result: the leftover, from 0 up to just under the divisor.

Equivalently, the remainder equals the number minus the divisor times the whole-number quotient. The quotient here is 11, so 137 − 12 × 11 = 5.

Worked example: 137 divided by 12

Find the remainder when 137 is divided by 12.

  • Number

    137

  • Divisor

    12

Modular remainder

5 remainder

Twelve goes into 137 eleven times, which accounts for 132, and 5 is what is left. So 137 sits 5 past a multiple of 12.

  1. Find how many whole twelves fit in 137: 12 × 11 = 132, while 12 × 12 = 144 is too big.
  2. Subtract: 137 − 132 = 5.
  3. Check the bound: 5 is at least 0 and less than 12, so it is a valid remainder.

Reading it back: 137 = 12 × 11 + 5. That identity is the best check you can run, and it should hold exactly.

What the remainder means in practice

A remainder of 0 means the number divides evenly. This is the basis of divisibility tests, such as asking whether a year is divisible by 4, or whether a stock count fills whole cartons.

A non-zero remainder tells you how much is left over. If 137 items go into boxes of 12, you fill 11 boxes and have 5 items left. If you need to ship them all, you need a twelfth box; the remainder is exactly what the last box holds.

For cyclical positions, the remainder is the position. A shift pattern of 12 days, a seating arrangement of 12 chairs, or a 12-colour palette repeating over a list all identify the 137th item by its remainder, with 0 meaning the very start of a new cycle.

How the number changes the remainder

The remainder does not rise smoothly with the number. It climbs by one for each unit and then drops back to zero every time it reaches the divisor. So a small increase in the number can move the remainder up a little or send it all the way back to the bottom.

Raising the number by 10% while the divisor stays at 12
ScenarioNumberCalculated result
Original assumptions1375 remainder
Number increased by 10%150.76.7 remainder

The 10% row shows a decimal input, 150.7, which is outside the usual whole-number use. Many tools give 6.7 here, since 12 × 12 = 144 and 150.7 − 144 = 6.7, but for strict modular arithmetic on integers you would round first.

Where remainder results go wrong

  • Negative numbers. In some tools −137 mod 12 is 7, because the result is kept non-negative; in others it is −5, because the quotient is truncated toward zero.
  • Dividing by zero, which has no remainder and gives an error.
  • Confusing the remainder with the quotient or with the decimal part of the division. The decimal part of 137 ÷ 12 is about 0.42, not 5.
  • Using a decimal number and expecting integer behaviour, which depends on the tool.

A scheduling example

A rota rotates between 7 volunteers, numbered 0 to 6, and starts with volunteer 0 on day 0. Who is on duty on day 100?

  1. Divide 100 by 7: the quotient is 14, since 7 × 14 = 98.
  2. Remainder: 100 − 98 = 2.
  3. Volunteer 2 is on duty.

The same trick works for any number of days without having to count the cycle.

Common questions

What does mod mean in maths?

It means the remainder after division. Writing 137 mod 12 asks what is left when 137 is divided by 12 and the whole quotient is removed. The answer is 5, because 12 goes in eleven times with 5 left.

How do I calculate a remainder by hand?

Find the largest multiple of the divisor that does not exceed the number, then subtract it. For 137 and 12, the multiple is 132 and the difference is 5. Check that the answer is smaller than the divisor.

Can a remainder be negative?

It depends on the convention. Mathematics usually keeps the remainder between 0 and the divisor, so -137 mod 12 is 7. Some programming languages return -5 instead. Check the documentation of the tool you use before relying on it.

What is the remainder when a number divides evenly?

It is zero. A remainder of 0 means the divisor is a factor of the number, which is how you test whether a number is a multiple of another.

Is the remainder the same as the decimal part of a division?

No. The decimal part of 137 ÷ 12 is about 0.4167, while the remainder is 5. They are related by multiplication: 0.4167 times 12 is 5, so the decimal is the remainder as a fraction of the divisor.

Was this guide helpful?

Continue reading

View all blogs