Home/Calculators/Math/Modulo Calculator

Modulo Calculator

Find the remainder when one number is divided by another — instant and free.

modulo-calculator
Result
—
In summary: The modulo operation returns the remainder after division. Formula: a mod b = a − b × floor(a ÷ b). For a = 17 and b = 5, 17 mod 5 = 2 because 5 goes into 17 three times with 2 left over.

How modulo works

The modulo (or mod) operation gives the remainder left after dividing a by b: a mod b = a − b × floor(a ÷ b). For 17 mod 5, 5 fits into 17 three times (15), leaving a remainder of 2.

Read it from the inside out: floor(a ÷ b) is how many whole times the divisor fits, multiplying back by b gives the largest multiple that does not overshoot, and subtracting leaves the gap. So mod 5 can only return 0, 1, 2, 3 or 4. The remainder is the part long division leaves behind, and the long division calculator shows where it comes from.

Modulo with negative numbers

This calculator uses the floored definition, so the result always has the same sign as the divisor b. For example, −1 mod 5 = 4. That matches how many programming languages and math conventions treat modulo for negative inputs.

The floored convention is the useful one for wrapping around a cycle: stepping back one hour from 12 o'clock should give 11, not −1. Repeated remainders are how Euclid’s algorithm works, which is the method behind the greatest common factor calculator.

Common uses of modulo

Modulo powers clock arithmetic, even/odd checks (n mod 2), cycling through lists, and hashing. To convert a leftover remainder into a fraction or decimal, pair it with the fraction to decimal calculator.

A few patterns show up constantly:

  • Divisibility: a mod b equals 0 exactly when b divides a evenly.
  • Wrapping: index mod length keeps a counter inside a list of that length.
  • Grouping: n mod 3 splits items into three repeating buckets.
  • Digits: n mod 10 returns the last digit of a whole number.

Frequently asked questions

What is 17 mod 5?
17 mod 5 = 2, because 5 divides into 17 three times with a remainder of 2.
What happens if the divisor is zero?
Modulo by zero is undefined, so the calculator asks for a non-zero divisor.
How does modulo handle negative numbers?
This tool uses floored modulo, so the remainder takes the sign of the divisor, e.g. −1 mod 5 = 4.
How do I check if a number is even?
Compute n mod 2. A result of 0 means the number is even; 1 means it is odd.
Why does my programming language give a different answer for negatives?
Languages such as C, Java and JavaScript use truncated modulo, where the result takes the sign of the dividend, so −1 % 5 returns −1 rather than 4. Add the divisor to a negative result to convert to the floored answer used here.
How this tool works

The formula behind this tool is written out in full in the sections above, so you can check the maths yourself. Every calculator on Calculorium is verified against worked examples with automated tests before it is published, and pages are reviewed as formulas or standards change. Nothing you type is sent anywhere — the calculation runs entirely in your browser. Read how we build and check these tools.

Last updated: July 27, 2026 · Calculations run in your browser. Estimates for information only.