Part of the Maths & Statistics suite · 235 calculators

Modulo Calculator

The remainder after division — with both conventions, because programming languages disagree about negative numbers.

a mod b is what is left over after dividing a by b.

Results update as you type
Results
a mod b (floored)
3
Truncated remainder (JavaScript, C, Java)
Quotient (floored)
Quotient (truncated)
Divides exactly?
Reviewed September 2026. Pure mathematics: the result does not depend on where you are. Terminology follows the national curriculum (maths, brackets, decimal point).
No account required · Google Analytics off unless allowedCalculator arithmetic runs in your browserResults update as you type
All calculations run 100% in your browser. The calculator code does not submit your figures to GlobalCalc to obtain a result.
About modulo

How the modulo calculator works

a mod b is what is left over after dividing a by b. For positive numbers everyone agrees: 17 mod 5 is 2.

Negatives are where languages split. JavaScript, C and Java truncate the quotient toward zero — trunc(−17/5) is −3, leaving −17 − (−15) = −2. Python, Ruby and mathematicians floor it instead — floor(−17/5) is −4, leaving −17 − (−20) = 3, a result that always carries the sign of the divisor. Both are shown here, because picking the wrong one silently breaks anything that wraps around: clock arithmetic, array indices, hash buckets.

Formula: truncated: a − b·trunc(a/b); floored: a − b·floor(a/b)

Worked examples

Inputsa mod b (floored)Note
17 mod 522
−17 mod 5 — the two conventions differ33 floored, −2 truncated
100 mod 722

Frequently asked questions

What is the modulo operator?

It gives the remainder after division. 17 mod 5 is 2, because 5 goes into 17 three times with 2 left over.

What is −17 mod 5?

It depends on the convention: 3 in Python and in mathematics, −2 in JavaScript, C and Java. Both are shown above.

Why do languages disagree on negative numbers?

Because they round the quotient differently — toward zero (truncated) or downward (floored). Both satisfy a = bq + r; they just choose different q.

Which one should I use?

The floored version for anything cyclic — clock faces, angles, wrapping indices — because it never returns a negative.

Can the divisor be zero?

No. Division by zero is undefined, so there is no remainder to give.

Where these figures come from

Last checked: September 2026. Formulas are fixed by mathematics and do not change with tax years or regulations.