MODULO CALCULATOR

Modulo calculator

Enter a number and a divisor, get the remainder.

What does mod mean?

a mod n is the remainder after dividing a by n: 17 mod 5 = 2, because 17 = 3 × 5 + 2.

What is a negative number mod n?

It depends on the convention. Mathematically (and in Python), −17 mod 5 = 3, since −17 = −4 × 5 + 3. In C, Java and JavaScript, the % operator gives −2, the same sign as −17. The calculator shows both.

How is modulo used in everyday life?

Clock time is mod 12 or mod 24: 15:00 is 3 PM because 15 mod 12 = 3. A number is even when n mod 2 = 0.

Can I use very large numbers?

Yes — whole numbers of any length are handled exactly, for example 123456789012345678901234567890 mod 97 = 52.

Does it work with decimals?

Yes: 5.5 mod 2 = 1.5, because 5.5 = 2 × 2 + 1.5.

What is a mod n when a is smaller than n?

It is a itself, because n goes into a zero times: 2 mod 7 = 2 with a quotient of 0.

How do I find the day of the week with mod 7?

Weeks repeat every 7 days, so only the remainder matters. 100 days after a Monday is 100 mod 7 = 2 days past Monday, which is a Wednesday. For exact dates use the days from today calculator.

What does 38 ≡ 14 (mod 12) mean?

Two numbers are congruent modulo n when n divides their difference (Wolfram MathWorld, “Congruence”). Here 38 − 14 = 24 = 2 × 12, and both numbers leave the same remainder: 38 mod 12 = 2 and 14 mod 12 = 2.

The division behind the remainder

Dividing a by n gives a quotient q and a remainder r with a = q × n + r. The only question is how q is rounded. The floored (mathematical) convention rounds q down, so the remainder takes the sign of the divisor; this is Python’s rule, x == (x // y) × y + (x % y). The truncated convention rounds q toward zero, so the remainder takes the sign of the dividend; this is what % does in JavaScript, whose documentation calls it a remainder, not a modulo operator. The two agree when a and n have the same sign or a divides evenly. With decimals the answer is rounded to 10 places to hide binary floating-point noise, as in Python’s documented 3.14 mod 0.7 = 0.34.

Worked example: −13 mod 5

The MDN page uses −13 % 5. Rounding −13 ÷ 5 = −2.6 down gives a quotient of −3, and −13 = (−3) × 5 + 2, so the floored result is 2. Rounding toward zero gives −2, and −13 = (−2) × 5 + (−3), so JavaScript and C report −3. A negative divisor flips the pattern: 17 mod −5 is −3 floored and 2 truncated.

Common mistakes

Using % in JavaScript for a true modulo. Wrapping the index −1 around a list of 5 gives 4 mathematically but −1 in JavaScript, which is not a valid position; MDN suggests ((n % d) + d) % d. Expecting a result from 0 to n − 1 when the divisor is negative: the floored result is then zero or negative. Dividing by 0, which has no remainder and is rejected. And reading the quotient shown for a negative a as the truncated one; it follows the floored convention.

Sources: Python documentation, “The Python Language Reference”, Binary arithmetic operations; MDN Web Docs, “Remainder (%)”; Wolfram MathWorld, “Congruence”. Related tools: long division calculator, LCM and GCF calculator, days from today calculator and prime number calculator. How we check our calculators.