Modulo Calculator

Calculate the modulo of two numbers (a mod b) — the result always takes the sign of the divisor, matching the convention used in mathematics and languages like Python.

  • Free to use
  • Accurate results
  • No registration required
  • Works on all devices
Enter a dividend and divisor to calculate a mod b, where the result takes the sign of the divisor.
The number being divided.
The number you're dividing by.

Your result

2

a mod b

Remainder (a % b, sign follows dividend)-1

AI explanation

Formula

modulo = a − b × floor(a / b) — the result takes the sign of the divisor b

Worked example

-7 mod 3

Worked example: -7 mod 3
FieldValue
Dividend (a)-7
Divisor (b)3
a mod b2
Remainder (a % b, sign follows dividend)-1

Assumptions

  • The divisor cannot be zero.
  • When the dividend and divisor have the same sign, modulo and remainder give the same result — they only differ when the signs differ. See the Remainder Calculator for the other convention.

Frequently asked questions

What is the difference between modulo and remainder?

They agree when the dividend and divisor have the same sign. When the signs differ, modulo (this calculator's primary result) always takes the sign of the divisor, while remainder (see the Remainder Calculator) always takes the sign of the dividend.

Why does -7 mod 3 equal 2, not -1?

Modulo is defined using floor division: -7 ÷ 3 floors to -3, and -7 − (3 × -3) = -7 + 9 = 2. This convention (used by Python's % operator) always returns a result with the same sign as the divisor.

Where is modulo commonly used?

It's used for cyclic calculations like clock arithmetic, checking divisibility, hashing, and wrapping array indices — anywhere a value needs to "wrap around" within a fixed range.

Related calculators

Report a calculation issue