Modulo Calculator
Compute a mod b for any integers, positive or negative. See the quotient, remainder and step-by-step working — with both the mathematical and the programming sign conventions.
What is modulo?
The modulo operation returns the remainder after dividing one integer by another. Written a mod b, it answers: "after taking out as many whole copies of b as fit inside a, what's left over?"
Formally, given integers a and b ≠ 0, we write a = q · b + r with 0 ≤ r < |b|. That r is the value of a mod b. A familiar case is clock arithmetic — if it's 10 AM now, 15 hours later is (10 + 15) mod 12 = 1. The clock forgets everything except the remainder.
Modulo, piece by piece
Each card explains one thing this tool decides for you — how the remainder is defined, how it handles negative inputs, and why the two common conventions can disagree.
Definition — how the remainder is chosen
Write a = q · b + r and pick the integer quotient q that makes 0 ≤ r < |b|. That r is a mod b — the "leftover" after taking out whole copies of b.
Negative dividends — sign follows the divisor
For negatives we still require 0 ≤ r < |b|, so the mathematical result has the same sign as the divisor b. The tool follows this convention.
Math vs programming — where they disagree
Many programming languages truncate the quotient toward zero instead of flooring, which flips the sign of the remainder for negative inputs. The tool shows both so you can match the behaviour of your language.
Features of this calculator
- Handles positive, negative and mixed-sign integer inputs
- Follows the mathematical convention (result has the sign of the divisor)
- Also shows the truncated result used by C, Java and JavaScript
- Displays the quotient and full a = q · b + r identity
- Step-by-step working using the floor definition
Frequently asked questions
+What is the modulo operator used for?
It returns the remainder after integer division and is used for cyclic problems: array wrap-around, calendar arithmetic, hashing, cryptography and checksums.
+Why is −7 mod 3 different in math vs programming?
They use different definitions of the quotient. The mathematical convention floors, giving quotient −3 and remainder 2. Truncated modulo (C, Java, JS) rounds toward zero, giving quotient −2 and remainder −1.
+Can the divisor be zero?
No. Division by zero is undefined, so a mod 0 has no meaning either.
+What if both operands are negative?
The mathematical result still has the sign of the divisor. For example, −7 mod −3 = −1, because −7 = 2 · (−3) + (−1) and −1 is in the range (−3, 0].