Skip to content

Modulo Calculator — Step-by-Step Solutions

The Modulo Calculator computes remainders and performs modular arithmetic. It supports basic modulo operations, modular addition and subtraction, modular exponentiation using fast repeated squaring, and clock arithmetic with an interactive visualisation.

Enter your values to see step-by-step working. The clock arithmetic mode displays results on an SVG clock face, making modular concepts visual and intuitive.

Remainder
—

Your calculations will appear here

How to Use the Modulo Calculator

  1. Choose a mode: a mod b for a remainder, Modular Add/Subtract for arithmetic inside a modulus, Modular Exponentiation for large powers, or Clock Arithmetic for time problems.
  2. For a mod b, enter the dividend a and the divisor b. For modular arithmetic, enter a, b and the modulus m and choose addition or subtraction. For exponentiation, enter the base, a non-negative exponent and the modulus.
  3. For Clock Arithmetic, pick a 12-hour or 24-hour clock, enter the start hour and the number of hours to add (a negative number goes back in time).
  4. The step-by-step working shows the division, the quotient and the remainder, and for exponentiation the repeated squaring that keeps numbers small.

Formula and Theory

The modulo operation gives the remainder after division. a mod b is the amount left over when a is divided by b as many whole times as possible: a = b x q + r, with 0 <= r < |b|. For example, 17 mod 5 = 2 because 17 = 3 x 5 + 2.

Two numbers are congruent modulo m if they leave the same remainder, written a = b (mod m). Congruence behaves like equality for addition, subtraction and multiplication: you can reduce at any stage. That is why (23 + 19) mod 7 can be done as (2 + 5) mod 7.

This calculator returns a non-negative remainder for a negative dividend, the usual convention in mathematics and number theory: -7 mod 5 = 3, because -7 = (-2) x 5 + 3. Many programming languages instead return -2 for -7 % 5, so results can differ from code you have seen.

Modular exponentiation uses repeated squaring, reducing after each multiplication, so even enormous powers can be computed quickly. It is the basis of public-key cryptography and of checks such as finding the last digit of a power.

Worked Examples

Example 1: Basic remainder

Problem: Calculate 17 mod 5, and then -7 mod 5.

Solution: 17 = 3 x 5 + 2, so 17 mod 5 = 2. For -7: choose the largest multiple of 5 not above -7, which is -10, so -7 = (-2) x 5 + 3 and the remainder is 3.

Answer: 17 mod 5 = 2 and -7 mod 5 = 3

Example 2: Day of the week

Problem: Today is Monday. What day is it 100 days from now?

Solution: The weekdays repeat every 7 days, so only the remainder matters. 100 = 14 x 7 + 2, so 100 mod 7 = 2. Two days after Monday is Wednesday.

Answer: Wednesday

Example 3: Modular addition and subtraction

Problem: Calculate (23 + 19) mod 7 and (4 - 9) mod 7.

Solution: 23 + 19 = 42 = 6 x 7, so the remainder is 0. For the subtraction, 4 - 9 = -5, and adding 7 gives 2, which lies in the range 0 to 6.

Answer: (23 + 19) mod 7 = 0 and (4 - 9) mod 7 = 2

Example 4: Last digit of a large power

Problem: Find the last digit of 7^222, that is 7^222 mod 10.

Solution: The last digits of powers of 7 cycle through 7, 9, 3, 1 with period 4. Since 222 = 55 x 4 + 2, 7^222 behaves like 7^2 = 49, which ends in 9. This also follows from 7^4 = 2401 = 1 (mod 10), so 7^222 = 7^2 = 49 = 9 (mod 10).

Answer: 9

Example 5: Clock arithmetic

Problem: It is 10 o'clock on a 12-hour clock. What time is it 5 hours later? On a 24-hour clock, what is 7 hours after 22:00?

Solution: 10 + 5 = 15, and 15 - 12 = 3 on a 12-hour clock. For 24 hours, 22 + 7 = 29, and 29 - 24 = 5.

Answer: 3 o'clock, and 05:00

Frequently Asked Questions

What does mod mean?
It means the remainder after division. 17 mod 5 = 2 because 5 goes into 17 three times (15) with 2 left over.
How do I calculate modulo by hand?
Divide a by b and keep the whole-number part q. The remainder is a - b x q. For a = 100 and b = 7, q = 14, so the remainder is 100 - 98 = 2.
What is a negative number mod something?
In mathematics the remainder is taken from 0 up to b - 1, so -7 mod 5 = 3. Some programming languages return a negative result for the % operator, so check the language convention before comparing.
What is the difference between modulo and division?
Division gives the quotient (how many times b fits) and modulo gives what is left. Together they satisfy a = b x quotient + remainder.
What happens when a is smaller than b?
The remainder is a itself. For example, 3 mod 7 = 3, because 7 does not fit into 3 even once.
Can the modulus be zero?
No. Dividing by zero is undefined, so a mod 0 has no value and the calculator reports an error. A modulus of 1 always gives 0.

Related General Calculators

Related Articles