Home · Everyday · Arithmetic · Modulo Calculator
Modulo Calculator
Compute the mathematical modulo, whose result takes the divisor's sign, and compare it side by side with truncated remainders.
What this calculator does
Compute the mathematical modulo, whose result takes the divisor's sign, and compare it side by side with truncated remainders. Where a measure is involved, US and metric units are both accepted — flip the unit toggle and the figures convert with the same definitions the formula uses. Every result on this page is computed from the formula stated below, with no hidden rounding steps.
The formula and method
The mathematical modulo returns the remainder of floor division: a mod b = a − b × floor(a ÷ b). Because the quotient is rounded down, the result always carries the sign of the divisor, so with a positive modulus the answer lies in [0, b). That is why −7 mod 3 = 2: floor(−7 ÷ 3) = −3, and −7 − 3 × (−3) = 2.
Many programming languages instead truncate the quotient toward zero, which makes their % operator return −1 for the same inputs, as the third output shows. The two conventions agree whenever a is non-negative, and differ only for negative dividends. Use the mathematical version for clock arithmetic, weekday cycles, and hashing, where a result that can go negative breaks the logic.
Worked example
With the example inputs this page opens with (number (a) -7, modulus (b) 3), the result is 2 — a mod b (mathematical). Computed from the inputs on this page with the formula below — change any figure and every result updates.
Quick reference
| Number (a) | a mod b (mathematical) | Floor quotient floor(a / b) | Truncated remainder (C/Java style) |
|---|---|---|---|
| -13 | 2 | -5 | -1 |
| -7 | 2 | -3 | -1 |
| -1 | 2 | -1 | -1 |
| 0 | 0 | 0 | 0 |
| 5 | 2 | 1 | 2 |
| 11 | 2 | 3 | 2 |
| 20 | 2 | 6 | 2 |
Computed with the same formulas as the calculator above — enter any values there for figures beyond this table.
Common questions
Why does −7 mod 3 equal 2 and not −1?
Modulo here uses floor division: −7 = 3 × (−3) + 2, and the remainder must sit between 0 and the divisor. Languages that truncate toward zero write −7 = 3 × (−2) − 1 instead.
How does the Modulo Calculator work?
Compute the mathematical modulo, whose result takes the divisor's sign, and compare it side by side with truncated remainders. Number a · Modulus b → a mod b. The result updates as you type, and the formula and method on this page state the exact definitions used, so you can reproduce the calculation by hand.
What inputs does the Modulo Calculator need?
Number a · Modulus b → a mod b. Invalid entries — such as a zero denominator, an out-of-range value or a malformed list — produce a plain-language message instead of a misleading number.
Is the Modulo Calculator free to use?
Yes. It runs entirely in your browser with no sign-up, and the same calculator is available as an embeddable widget via the Embed button, so it can be placed on another site with its calculation intact.