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.

Your figures

Example result — edit the figures to make it yours

2

a mod b (mathematical)

Computed from the inputs on this page with the formula below — change any figure and every result updates.

Floor quotient floor(a / b)-3
Truncated remainder (C/Java style)-1

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

a mod b = a − b × floor(a / b)

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

Quick reference — varying Number (a)
Number (a)a mod b (mathematical)Floor quotient floor(a / b)Truncated remainder (C/Java style)
-132-5-1
-72-3-1
-12-1-1
0000
5212
11232
20262

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.