Modulo Calculator (a mod b)

Type the dividend and the divisor to get the remainder (a mod b), the quotient and the check b × q + r = a.

a mod b

2

Quotient (q)
3
Check: b × q + r
5 × 3 + 2 = 17
Show working
  1. 17 ÷ 5 = 3.4
  2. q = 3
  3. r = 17 − 5 × 3 = 2
  4. 17 mod 5 = 2

How to use

  1. Type a (the number being divided) and b (the divisor).
  2. Read a mod b and the quotient.
  3. For negative numbers, choose the convention you need under More options.

Good to know

a mod b is the remainder when a is divided by b: 17 mod 5 = 2 because 17 = 5 × 3 + 2. Modulo is used for clock time (15:00 mod 12 = 3 o'clock), days of the week (today + 100 days: 100 mod 7 = 2 days ahead), check digits and in programming.

With negative numbers, languages disagree. The maths convention keeps the remainder between 0 and |b| − 1 (−7 mod 3 = 2). Python and Excel's MOD give the remainder the sign of the divisor b. C, C++, Java and JavaScript's % give it the sign of the dividend a (−7 % 3 = −1). Pick the one that matches where you'll use the result.

Decimals work too: 5.5 mod 2 = 1.5. Whole-number inputs are exact; decimals are tidied to remove binary rounding noise. For divisibility rules and very long numbers, use the divisibility calculator.

Questions

What is 10 mod 3?

1, because 10 = 3 × 3 + 1.

What is −7 mod 3?

2 in maths and Python (−7 = 3 × (−3) + 2). It is −1 in C, Java and JavaScript.

What if a is smaller than b?

Then a mod b = a (for positive numbers). 3 mod 8 = 3.

What is a mod 0?

Not defined, because you can't divide by 0.

How do I find what day it will be after 100 days?

100 mod 7 = 2, so it will be 2 days of the week after today.

Last updated: