Find a mod b — the remainder left over after dividing a by b, using the standard mathematical (floored) definition of modulo.
How it works
The formula is a mod b = a − b × floor(a ÷ b). This “floored” modulo always returns a result with the same sign as the divisor b, which is the convention used in mathematics — some programming languages instead return a result with the same sign as the dividend a, which can look different for negative numbers.
What this does not include
This uses the mathematical convention throughout. If you’re checking a specific programming language’s `%` operator against negative numbers, note that not every language follows this same convention.
How to use this calculator
- Enter a.
- Enter b, the modulus.
A worked example
17 mod 5 = 2 — the remainder after dividing 17 by 5 three times.
−7 mod 3 = 2 — a negative dividend still returns a non-negative remainder under this convention.
10 mod −3 = −2 — a negative divisor flips the sign of the result.
What the variables mean
| Variable | Meaning |
|---|---|
| a | The dividend |
| b | The divisor |
Edge cases worth knowing
Negative number modulo behaves differently across programming languages — some always return a non-negative result, others match the sign of the divisor. The second and third examples above show this calculator’s specific convention, which is worth checking against whatever system this result needs to match.
A divisor of zero has no defined remainder, so the calculator declines to show a result for that case.
Why is −7 mod 3 equal to 2, not −1?
Floored modulo always returns a result with the same sign as the divisor (here, positive 3), so the result must be a non-negative number less than 3 — 2 fits that requirement, while −1 does not.
What’s modulo used for?
Wrapping values around a fixed range (like clock arithmetic), checking divisibility, and cycling through a repeating sequence of indices are all common uses.
What happens if b is zero?
Modulo by zero is undefined, the same as ordinary division by zero — this calculator returns no result for that input.