How to Calculate Modulo (Including Negatives)
To calculate a modulo, enter the dividend a and the divisor n into the ByteTools Modulo Calculator; it returns the remainder of a ÷ n, the quotient, and — crucially for negatives — both the truncated remainder that languages like JavaScript return and the floored, always-non-negative modulo used in mathematics. Seeing both side by side removes the confusion that comes from -7 mod 3 giving different answers in different tools.
Modulo is simple for positive numbers but famously tricky once a minus sign appears. This guide shows how to use the calculator and how to read every value it gives you.
What modulo actually computes
The modulo operation returns what is left over after dividing one number by another. For 17 mod 5, seventeen divided by five is three with two left over, so the result is 2. It underpins cycles (clock arithmetic), hashing, checking divisibility, and wrapping array indexes. The calculator pairs the remainder with the quotient so you see the full picture of the division.
Step-by-step
- Enter the dividend a — the number being divided, such as
17or-7. - Enter the divisor n — the modulus, such as
5or3. This is the number you divide by. - Read the truncated remainder — the value most programming languages (JavaScript, C, Java) return from the
%operator. - Compare the floored modulo — the always-non-negative result used in mathematics and Python.
- Note the quotient and click Copy to grab the results for your notes or code.
Reading the two negative-number results
The whole point of showing two answers is that negatives split the conventions. Here is how a few inputs resolve:
| a | n | Truncated (JS %) | Floored (math/Python) |
|---|---|---|---|
| 17 | 5 | 2 | 2 |
| -7 | 3 | -1 | 2 |
| 7 | -3 | 1 | -2 |
| -7 | -3 | -1 | -1 |
For positive numbers the two columns match. They diverge only with negatives: the truncated remainder keeps the sign of the dividend, while the floored modulo matches the sign of the divisor. Pick the column that matches the language or maths you are working in.
Everything runs privately in your browser
Each calculation is performed locally in JavaScript. No numbers are sent anywhere, so results are instant, the tool works offline, and there is nothing to sign up for. It also guards against a zero divisor — dividing by zero has no meaningful remainder, so the calculator shows a message rather than an invalid result.
Try the Modulo Calculator — free and 100% in your browser.
FAQ
Which result should I use in my code?
Use the truncated column if your language's % operator follows C or JavaScript behaviour, and the floored column if you are in Python or need a mathematically non-negative result. The calculator labels both so you can match your environment exactly.
How do I compute modulo by hand?
Divide a by n, take the whole-number quotient, multiply it back and subtract from a. For negatives, decide whether you truncate the quotient toward zero (giving the remainder) or floor it downward (giving the mathematical modulo). The calculator does both instantly.
What is the quotient shown alongside the remainder?
The quotient is how many whole times n fits into a. Together with the remainder it reconstructs the original number, which is useful when you need both parts of a division.
Can I use decimals?
Modulo is defined for the integer division shown here. Enter whole numbers for the dividend and divisor to get meaningful remainder and quotient results.
Related free tools
- GCD & LCM Calculator — find greatest common divisors and least common multiples.
- Prime Number Checker — test whether a number is prime.
- Binary Calculator — do arithmetic in binary.
- Exponent Calculator — compute powers quickly.
Built by ByteVancer
ByteTools is a free product of ByteVancer, a software and web development studio building web apps, SaaS and custom software. If you are building something that needs solid engineering behind it, explore how ByteVancer can help.
Recommended reading
Modulo Negative-Number Mistakes and How to Avoid
The negative-modulo bugs that catch programmers out — and best practices for getting an always-positive result for indexing and clock arithmetic.
Real-World Uses of the Modulo Operation
Worked examples of where modulo shows up — clock arithmetic, array wrapping, hashing, alternating rows and even-odd checks — with the numbers to match.
Yes or No Generator: Real Use Cases and Examples
From beating decision paralysis to games and classrooms, see real use cases and examples for a random yes or no generator.
Yes or No Generator Tips and Common Mistakes
Get better decisions from a random yes or no generator. Pro tips, when to add Maybe, and the common mistakes to avoid when picking answers.