Modular Addition Calculator

Enter two numbers and a modulus to compute (a + b) mod m.

How it is calculated

The tool adds the two numbers and wraps the sum into the range 0 to m − 1: sum = a + b, then result = ((sum mod m) + m) mod m. The second step matters for negative sums: a plain remainder in programming can be negative, but this tool always gives the mathematical answer between 0 and m − 1. The modulus m must be a whole number of at least 1, and a and b must be whole numbers too, though they may be zero or negative. A decimal such as 2.5 or 7.5 returns no result rather than being rounded, as does a modulus below 1. Values beyond about 9 × 1015 (253) are also rejected, so no digits are silently lost. The tool shows three values: the result, the ordinary sum, and the modulus. With m = 1 every result is 0.

Worked example

Take a = 47, b = −38 and m = 12. The ordinary sum is 47 + (−38) = 9. Dividing by 12 gives remainder 9, which is already in the range 0 to 11, so the result is 9. Now try a = −7, b = 3, m = 5: the sum is −4, and −4 + 5 = 1, so the result is 1 (not −4). A clock is the everyday case: 10 o'clock plus 5 hours is the sum 15, and 15 mod 12 = 3, so 3 o'clock.

Try this example →

Common mistakes

  • Expecting a negative remainder for a negative sum. Here −4 mod 5 is 1, because the result is always from 0 to m − 1.
  • Entering a decimal such as 7.5 and expecting it to be rounded. Modular addition is defined for integers, so a decimal in a or b gives no result.
  • Using m = 0, a negative modulus or a decimal modulus; the modulus must be a whole number of at least 1.
  • Mixing up the sum with the result. The "sum" line is the ordinary a + b; the answer to the problem is the "result" line.
  • Treating modulus 12 as giving 0 to 12 on a clock. The results run 0 to 11, so a clock showing 12 corresponds to 0.

About this calculator

Modular addition computes (a + b) mod m — the remainder left after dividing the ordinary sum a + b by the modulus m — and always returns a normalized result in the range 0 to m−1, no matter how large or negative a and b are. It follows the familiar rule of "wrapping around" once the sum reaches m, exactly like a clock face wraps from 12 back to 1.

This operation is the basis of modular arithmetic, taught alongside congruences in number theory, and it underlies practical systems from clock and calendar arithmetic to cyclic redundancy checks, hash table indexing, and cryptographic algorithms such as RSA and elliptic-curve schemes, where all arithmetic is deliberately confined to a fixed modulus.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Weekday arithmetic is an easy real use. Number the days with Monday as 0, so Thursday is 3. Adding 45 days and using modulus 7 gives 6 (sum 48), which is Sunday. The same trick works for any cyclic count: hours with modulus 24, or array positions in a circular buffer. Remember that the tool only accepts whole numbers. What cycle are you wrapping around: dates, hash buckets, something from a number theory course?

Popular calculators

All Calculators