Skip to content
Math & Scientific

Modulo Calculator

Modulo Calculator

Split any division into quotient and remainder — shown with both the truncated and the floored sign rule.

Any non-zero number.

Both rules satisfy divisor × quotient + remainder = dividend. They only differ in sign when the dividend is negative.

Division has two natural questions: how many full times does the divisor fit, and what is left over? The quotient answers the first and the remainder answers the second, and together they reconstruct the original division exactly.

The calculator above performs that split for any dividend and divisor, then shows it twice: once with the truncated rule that most programming languages use, and once with the floored rule that mathematics prefers. For positive numbers the two agree; for negatives they part ways.

This guide explains the division algorithm, the two sign rules, and why the check line at the bottom of the result is the most trustworthy part of the whole page.

What Does the Modulo Calculator Do?

You enter a dividend and a divisor. The calculator returns the quotient and remainder under two conventions: truncated, where the quotient is chopped toward zero, and floored, where the quotient is rounded down.

Each convention gets its own row, so you can compare them side by side. The check line then verifies both: divisor × quotient + remainder equals the dividend in each case.

Decimals are accepted for both inputs. The only forbidden input is a zero divisor, which the calculator rejects with a clear message.

How to Use the Modulo Calculator

Type the number being divided into the “Dividend” box and the number dividing it into the “Divisor” box. Either may be negative, and either may be a decimal.

Press Calculate. The headline names the division, the four rows give both quotients and both remainders, and the check line proves that each pair reconstructs the dividend.

Press Reset to try another pair. Comparing a positive dividend with its negative twin is the fastest way to see the two sign rules diverge.

The Division Algorithm

Every division of a by d can be written as a = d × q + r, where q is the quotient and r is the remainder. This single identity is the whole subject, and everything else is a choice about how to pick q.

For positive numbers there is no real choice: 17 ÷ 5 gives q = 3 and r = 2, because 5 × 3 + 2 = 17. The quotient counts full fits and the remainder is what is left, both non-negative.

Negatives force a decision, because −17 ÷ 5 can be written as 5 × (−3) + (−2) or as 5 × (−4) + 3. Both are arithmetically correct, and the two conventions simply pick different ones.

The Truncated Rule: Quotient Toward Zero

The truncated rule chops the quotient toward zero. For −17 ÷ 5, the true quotient −3.4 becomes −3, and the remainder is whatever is needed to balance: −17 − 5 × (−3) = −2.

This is the rule behind the % operator in C, Java, JavaScript, and many other languages. Its signature is that the remainder takes the sign of the dividend: negative dividend, negative remainder.

The calculator labels these rows “Truncated quotient (Math.trunc)” and “Remainder, truncated rule,” so you always know which convention you are reading.

Truncation feels natural because it mirrors how most people do long division in their heads: you fit the divisor in as many whole times as possible and the leftover keeps the original sign. The rule only surprises people when they expected the mathematical residue instead.

The Floored Rule: Quotient Rounded Down

The floored rule rounds the quotient down toward negative infinity. For −17 ÷ 5, −3.4 becomes −4, and the remainder is −17 − 5 × (−4) = 3.

This is the rule mathematics prefers, because the remainder is always non-negative when the divisor is positive. It matches the Mod Calculator’s residue exactly.

Python’s % operator uses this rule, which is why −17 % 5 is 3 in Python but −2 in JavaScript. The calculator shows both so the language difference stops being mysterious.

Flooring is the kinder rule for wrap-around uses. Array indices, clock positions, and hash buckets all need non-negative results, and the floored remainder delivers them without any extra fix-up arithmetic afterward.

Worked Example: −17 ÷ 5

You want the quotient and remainder of −17 divided by 5.

First: enter −17 as the dividend and 5 as the divisor, then press Calculate.

The truncated rows read: quotient −3, remainder −2. The floored rows read: quotient −4, remainder 3.

The check line reads: 5 × −3 + −2 = −17 and 5 × −4 + 3 = −17.

Answer: truncated gives −3 remainder −2; floored gives −4 remainder 3.

Worked Example: 17 ÷ 5

You want the quotient and remainder of 17 divided by 5.

First: enter 17 as the dividend and 5 as the divisor, then press Calculate.

Both conventions agree here: quotient 3, remainder 2, because the dividend is positive and no sign decision arises.

The check line reads: 5 × 3 + 2 = 17 and 5 × 3 + 2 = 17.

Answer: quotient 3, remainder 2, under either rule.

Worked Example: 10 ÷ −3

You want the quotient and remainder of 10 divided by −3.

First: enter 10 as the dividend and −3 as the divisor, then press Calculate.

The truncated rows read: quotient −3, remainder 1. The floored rows read: quotient −4, remainder −2.

The check line reads: −3 × −3 + 1 = 10 and −3 × −4 + −2 = 10.

Answer: the rules diverge again, this time because the divisor is negative.

Worked Example: 7.5 ÷ 2

You want the quotient and remainder of 7.5 divided by 2.

First: enter 7.5 as the dividend and 2 as the divisor, then press Calculate.

Both conventions give quotient 3 and remainder 1.5, since 2 × 3 + 1.5 = 7.5 and the quotient needs no rounding decision.

The check line reads: 2 × 3 + 1.5 = 7.5 and 2 × 3 + 1.5 = 7.5.

Answer: quotient 3, remainder 1.5. Remainders need not be whole numbers when the dividend is not.

Reading the Check Line

The check line is the calculator auditing itself. It substitutes each quotient-remainder pair back into a = d × q + r and prints the full equation, so any arithmetic slip would be visible immediately.

Get in the habit of glancing at it. If the equation balances, the rows above it are correct by construction, because the identity is what defines a valid quotient-remainder pair.

This is also the fastest way to settle arguments about which remainder is “right.” Both pairs satisfy the identity; they just answer different questions about rounding.

Students sometimes ask why the check line prints both equations instead of one. The answer is that each convention is a complete, self-consistent arithmetic of its own, and verifying both keeps the comparison honest.

Common Modulo Mistakes

The most common mistake is assuming % means the same thing everywhere. It does not: JavaScript truncates, Python floors, and the answers differ on negative dividends. Know your language’s rule before trusting its %.

The second is expecting the remainder to be smaller than the divisor in absolute value but forgetting the sign. Under the truncated rule the remainder can be negative, which breaks code that assumes a non-negative result.

The third is dividing by zero and expecting a remainder. Division by zero is undefined, so there is no quotient and no remainder; the calculator refuses it outright rather than guessing.

Where Quotient-Remainder Splits Are Useful

Unit conversion leans on this split constantly: minutes into hours and leftover minutes, inches into feet and leftover inches, cents into dollars and leftover cents. The quotient is the big unit, the remainder the small one.

Programming uses it for cycling through arrays, alternating patterns, and pagination. “Item 27 on pages of 10” is quotient 2, remainder 7, which every paginator computes.

Number theory builds on it too. The Euclidean algorithm for greatest common divisors is just repeated quotient-remainder splits, each step feeding the next.

Scheduling uses it quietly as well. Rotating shifts, round-robin tournaments, and repeating calendar events all reduce to “which position in the cycle,” and the remainder is the position while the quotient counts completed cycles.

How to Interpret Your Result Correctly

First decide which convention your context needs. Debugging JavaScript? Read the truncated rows. Doing number theory or matching the Mod Calculator? Read the floored rows.

Then check the signs. A negative remainder is not an error under the truncated rule; it is the rule working as designed. Only treat it as a bug if your use case required the floored behavior.

Finally, trust the check line over your intuition. If the equation balances, the result is correct under its stated convention, whatever your gut says about the sign.

Keep the calculator open while you work through the examples below. Typing each division yourself, then comparing the rows with the write-up, turns an abstract sign rule into something your hands remember.

Frequently Asked Questions

1. What is −17 mod 5?

It depends on the convention. The truncated rule gives −2, matching JavaScript’s % operator, while the floored rule gives 3, matching Python and mathematical mod. The calculator shows both with the check line proving each.

2. What is the quotient and remainder of 17 ÷ 5?

The quotient is 3 and the remainder is 2, because 5 × 3 + 2 = 17. Both the truncated and floored conventions agree whenever the dividend and divisor are positive.

3. Why do JavaScript and Python disagree on negative remainders?

JavaScript’s % truncates the quotient toward zero, so the remainder keeps the dividend’s sign. Python’s % floors the quotient, so the remainder keeps the divisor’s sign. Same division, different rounding choice, different remainder.

4. Can the divisor be zero?

No. Division by zero is undefined, so there is no meaningful quotient or remainder. The calculator rejects a zero divisor with an explanatory message.

5. Can I use decimals?

Yes. Both the dividend and divisor accept decimals, and the remainder can be fractional too: 7.5 ÷ 2 gives quotient 3 and remainder 1.5 under both conventions.

6. What does the check line prove?

It substitutes each quotient-remainder pair back into the identity a = d × q + r and prints the full equation. A balanced equation means the pair is arithmetically valid under its convention.

7. Which remainder should I use in my code?

Match your language: use the truncated row for C, Java, or JavaScript, and the floored row for Python or Ruby. If you need a non-negative remainder regardless of language, the floored row with a positive divisor is the safe choice.

8. What is the difference between this and the Mod Calculator?

The Modulo Calculator decomposes a division into quotient and remainder and compares the two sign conventions. The Mod Calculator explores modular arithmetic, residues, and whether two numbers are congruent, always under the mathematical convention.

9. Is the remainder always smaller than the divisor?

In absolute value, yes: the remainder always satisfies |r| < |d|. That is what makes the quotient “how many full times it fits” and the remainder “what is left.”

10. What happens with a negative divisor?

The conventions diverge again. For 10 ÷ −3, truncation gives quotient −3 remainder 1, while flooring gives quotient −4 remainder −2. The check line verifies both against the identity.

11. Why is it called the division algorithm?

Because it is a guaranteed procedure: for any integers a and d with d non-zero, there exist unique integers q and r satisfying a = d × q + r with the remainder in the proper range. The name honors the guarantee, not the arithmetic.

12. How is this used in unit conversion?

Converting 130 minutes to hours uses quotient 2 and remainder 10, giving 2 hours 10 minutes. The quotient counts the big units and the remainder is the leftover in small units, which is the division algorithm in everyday clothes.

13. What does Math.trunc do differently from Math.floor?

Math.trunc chops toward zero, turning −3.4 into −3, while Math.floor rounds down, turning −3.4 into −4. They agree on positive numbers and differ on negatives, which is exactly why the two remainder rows diverge there.

14. Can the remainder be zero?

Yes, whenever the divisor fits evenly. Then the quotient is exact and the remainder is 0 under both conventions, which is also the definition of divisibility.

15. How do I get a non-negative remainder in JavaScript?

Use the floored row’s formula, ((a % d) + d) % d, which converts the truncated remainder into the floored one for positive d. The calculator’s floored remainder row shows the value this produces.