Modulo Calculator (Remainder and Mod)
Enter a dividend and a divisor to get three results at once: the remainder from the % operator, the floored modulo, and the truncated integer quotient. Negatives are fully supported, so you can watch the two mod conventions agree or split apart depending on the signs. Each card explains which rule it follows.
How to compute a modulo
- Type the dividend, the number being divided, into the first field.
- Type the divisor, the number you divide by, into the second field.
- Read the three result cards: Modulo, Remainder and Quotient.
- Use Copy modulo to grab the floored modulo value on its own.
Examples
Both numbers positive
dividend 17, divisor 5
modulo 2, remainder 2, quotient 3
Negative dividend
dividend -7, divisor 3
modulo 2, remainder -1, quotient -2
Negative divisor
dividend 7, divisor -3
modulo -2, remainder 1, quotient -2
Frequently asked questions
What is the difference between the remainder and the modulo?
The remainder follows the dividend's sign, the way the % operator behaves in most languages, so -7 % 3 is -1. The floored modulo follows the divisor's sign, so the same inputs give 2. The two agree whenever the dividend and divisor share a sign and only split when their signs differ.
How does this calculator handle negative numbers?
The remainder is computed as dividend % divisor, which truncates toward zero and keeps the dividend's sign. The modulo is ((dividend % divisor) + divisor) % divisor, which shifts the result into the divisor's sign. So 7 and -3 give a remainder of 1 but a modulo of -2.
Is the modulo always positive?
Only when the divisor is positive. A positive divisor forces a non-negative modulo, while a negative divisor produces a non-positive modulo. That is why the sign of the divisor, not the dividend, determines the sign of this result.
How is the quotient defined?
The quotient uses truncated division, Math.trunc(dividend / divisor), which rounds toward zero rather than down. So -7 divided by 3 gives a quotient of -2, not -3. Multiplying the quotient by the divisor and adding the remainder always returns the original dividend.
Why can the divisor not be zero?
Division and the modulo operation are undefined when the divisor is zero, so the calculator rejects it with an error rather than returning a meaningless value or infinity.
Do the dividend and divisor have to be whole numbers?
No. The calculator accepts decimals, and the underlying % operator extends to them, so 5.5 divided by 2 gives a remainder and modulo of 1.5. Floating point rounding can appear with numbers that cannot be represented exactly in binary.
Which convention do programming languages use?
It varies. C, Java, Go and JavaScript use the truncated remainder shown here, so their % can be negative. Python and Ruby use the floored modulo instead, matching the Modulo card. Knowing which one your language uses avoids subtle bugs with negatives.
How do I force a non-negative result in code?
Apply the same trick the Modulo card uses: ((a % n) + n) % n. Adding n before the final modulo lifts a negative remainder back into the 0 to n minus 1 range whenever n is positive.
Is my calculation private?
Yes. Everything runs locally in your browser, so the numbers you enter are never uploaded to a server.
Learn more
- Remainder vs modulo for negative numbers
Why the % operator and a floored modulo disagree on negatives, how truncated and floored division cause it, and which to reach for in code.
Related tools
GCD Calculator
Find the greatest common divisor of two or more integers with the Euclidean algorithm. Handles negatives and zero. Free, fast, and private.
Rounding Calculator
Round a number to decimal places or the nearest 5, 10, or 0.25. Choose half up, bankers, ceiling, floor, or truncation. Handles negatives. Free.
Exponent Calculator
Raise any base to any power online. Handles negative and fractional exponents, shows the result with scientific notation, and updates instantly.
Annulus Area Calculator
Calculate the area of an annulus, the ring between two concentric circles, from its outer and inner radius. Returns both circumferences and width too. Free.
Area Calculator
Find the area of a circle, square, rectangle, triangle, trapezoid, parallelogram, ellipse, sector or rhombus. Free and runs in your browser.
Arithmetic Sequence Calculator
Find the nth term, the sum of n terms and the full term list for any arithmetic or geometric sequence. Enter the first term, step or ratio, and n.