KitQuarter

Modulo Calculator

Find the remainder when one number is divided by another, with the full working shown: the quotient, the multiply-and-subtract steps, and a verification equation. It handles decimals and negative numbers, and shows both the mathematical (floored) and JavaScript-style (truncated) answers so you always know which convention you are looking at.

James Carter, Math and Tools Editor
Reviewed by James Carter, Math and Tools Editor
Formulas verified against standard references. Calculator logic tested with verified worked examples. Last reviewed: October 2026. Our methodology

How the Modulo Works, Step by Step

The modulo operation answers one question: after dividing a by b as many whole times as possible, what is left over? The calculator finds the floored quotient q = floor(a / b), multiplies it back (b × q), and subtracts from a. The leftover is the remainder r.

Every result comes with its verification equation, a = b × q + r, so you can check the answer in one glance. For 17 mod 5: q = floor(17/5) = 3, then r = 17 − 5 × 3 = 2, and indeed 17 = 5 × 3 + 2.

Step17 mod 5-17 mod 5
1. Divide and floorfloor(17/5) = 3floor(-17/5) = -4
2. Multiply back5 x 3 = 155 x -4 = -20
3. Subtract17 - 15 = 2-17 - (-20) = 3
Check17 = 5x3 + 2-17 = 5x-4 + 3
Modulo hero: 3D numbers 17 and 5 with mod symbol and remainder 2 over a division diagram
17 mod 5 = 2: the leftover after the biggest whole division.

Negative Numbers: Two Conventions

Positive dividends are unambiguous, but negatives split the world into two conventions. Mathematical (floored) modulo, used by Python and this calculator, always returns a remainder between 0 and |b|: -17 mod 5 = 3. Truncated modulo, used by JavaScript, C, and Java, keeps the sign of the dividend: -17 % 5 = -2.

Neither is wrong; they are different definitions. Bugs appear when code written for one convention runs on the other, for example array index wrapping. The calculator shows both results side by side whenever they differ, so you can match the convention your language or textbook uses.

Modulo chart: step-by-step worked calculation of 17 mod 5 with divide multiply subtract verify
Divide, floor, multiply, subtract, then verify with a = bq + r.

Decimals and Large Numbers

Modulo is not limited to integers. The same floor-multiply-subtract steps work for decimals: 8.7 mod 2.5 gives q = floor(3.48) = 3, so r = 8.7 − 7.5 = 1.2. Very large numbers, including scientific-notation inputs like 1.5e10, work the same way.

For huge integers beyond about 15 digits, floating-point arithmetic starts rounding, so treat those remainders as approximate. If you are working with big-number cryptography by hand, that is a sign to use a dedicated big-integer tool.

ExampleWorkingResult
17 mod 517 - 5x32
-17 mod 5 (floored)-17 - 5x-43
8.7 mod 2.58.7 - 2.5x31.2
100 mod 7100 - 7x142

Where Modulo Shows Up in Real Life

Clock arithmetic is modulo 12 in disguise: 17 o'clock is 5 PM because 17 mod 12 = 5. Calendars use mod 7 for weekdays, which is why the same date shifts weekday each year. Programmers use modulo to wrap indexes, alternate row colors (i % 2), and test evenness (n mod 2 = 0).

Hash tables and checksums lean on modulo to map huge key spaces into fixed-size tables, and ISBN and credit-card check digits use modular arithmetic to catch typos. Whenever something cycles, repeats, or wraps around, modulo is usually the math underneath.

Common Mistakes

The classic mistake is confusing the remainder with the decimal part of the division: 17 / 5 = 3.4, but 17 mod 5 = 2, not 0.4. The remainder is a whole leftover, not the fractional tail.

Second, dividing by zero: a mod 0 is undefined, not zero, and the calculator rejects it. Third, assuming negative results behave like the positive case: -17 mod 5 is 3 in floored math, not -2, which surprises anyone coming from JavaScript. When a negative remainder looks wrong, check which convention your context expects.

Modulo second hero: clock arithmetic circle showing 17 mod 12 equals 5
Clock math is modulo in disguise: 17 o'clock is 5 PM.

Related Tools for Number Work

When the modulo involves a percent of a value rather than a remainder, the percentage calculator handles percent-of, percent change, and reverse percentages.

For converting fractional results into decimals, the fraction to decimal converter shows terminating and repeating forms, which pairs well with the quotient side of a modulo problem.

Frequently asked questions

What is modulo?

Modulo finds the remainder after integer division. 17 mod 5 = 2, because 17 = 5 x 3 + 2 with 2 left over.

How do you calculate a mod b by hand?

Divide a by b, round the quotient down (floor), multiply back, and subtract: r = a - b x floor(a/b). For 17 mod 5: floor(3.4) = 3, then 17 - 15 = 2.

Why is -17 mod 5 equal to 3 and not -2?

This calculator uses the mathematical floored convention, where the remainder always lies between 0 and the divisor. JavaScript's % operator truncates instead and gives -2. Both are valid conventions.

Can you do modulo with decimals?

Yes. 8.7 mod 2.5 = 1.2, using the same floor-multiply-subtract steps as integers.

What is the difference between mod and remainder?

In everyday use they mean the same thing, but strictly the remainder can follow different sign conventions for negative numbers, while mod usually means the floored, always-non-negative version.

Where is modulo used in programming?

Wrapping indexes, cycling through arrays, alternating patterns, testing even/odd numbers, hash functions, and calendar math all rely on modulo.

What happens with mod 0?

It is undefined. Division by zero has no meaning, so the calculator rejects a zero divisor.