No ads, no sign-upChecked 2026-08-24

Modulo Calculator

Result

2.000000

Result: 2.000000
How the result moves

The answer is a mod n, the remainder after dividing a by n: a − n × floor(a ÷ n). This is the floored convention, so the remainder takes the sign of the divisor — −17 mod 5 is 3 here, while JavaScript and C print −2. That single difference is why people look this up.

Worked examples

How it's calculated

a mod n = a − n × floor(a ÷ n)

  1. StepEnter the dividend a and the divisor n.
  2. StepDivide a by n and round the quotient down, towards minus infinity.
  3. StepMultiply that quotient by n and subtract the product from a.
  4. ResultWhat is left is the remainder, carrying the sign of the divisor.

Reference table

a, nQuotient floor(a ÷ n)a mod n
0, 500
9.5, 241.5
17, 532
100, 7142
-8, 3-31
-17, 5-43
17, -5-4-3

Questions

How do I calculate the modulo of two numbers?

Divide the dividend by the divisor, round the quotient down, then subtract the divisor times that quotient from the dividend: a mod n = a − n × floor(a ÷ n). For example, 17 mod 5 = 17 − 5 × 3 = 2.

What is the modulo operation?

It returns the remainder left after dividing one number by another — what is left once as many whole multiples of n as fit have been taken out of a. Programmers use it for wrapping values, cycling through lists and testing divisibility.

How does modulo work with negative numbers?

This calculator uses the floored definition, so the remainder always takes the sign of the divisor: −17 mod 5 = 3, because floor(−17 ÷ 5) = −4 and −17 − 5 × (−4) = 3. Most programming languages use the truncated definition instead and would print −2. Always check which convention your language follows.

What is the difference between modulo and remainder?

For positive numbers they are identical. They part company with negatives: the floored modulo matches the sign of the divisor, while the truncated remainder matches the sign of the dividend.

What happens if the divisor is zero?

Modulo by zero has no standard meaning, so this calculator follows Knuth and returns the dividend unchanged: x mod 0 = x. The older calculator showed no result at all in that case. Every other divisor works, positive or negative, whole or decimal.

Sources and last check

  1. mathworld.wolfram.com

Information, not professional advice.