Modulo Calculator
Calculate the remainder of division (modulo operation) for any two numbers.
Modulo Calculator tool
Example
Input: 17 mod 5 (dividend 17, divisor 5)
Result: 2 (quotient 3; 17 = 5 x 3 + 2)
17 / 5 = 3.4, floored to 3; 17 - 5 x 3 = 2, so the remainder is 2.
Floored Modulo vs the % Operator
| Expression | Quotient (floored) | Modulo (Python, this tool) | % in C, Java, JS |
|---|---|---|---|
| 17 mod 5 | 3 | 2 | 2 |
| -17 mod 5 | -4 | 3 | -2 |
| 17 mod -5 | -4 | -3 | 2 |
| -17 mod -5 | 3 | -2 | -2 |
| -1 mod 12 | -1 | 11 | -1 |
| 5.5 mod 2 | 2 | 1.5 | 1.5 |
The two results differ only when the signs differ and the division is not exact.
- Enter the dividend (the number being divided) in the first field.
- Enter the divisor (the number to divide by) in the second field.
- View the remainder (modulo result) and quotient instantly.
- See the complete division equation showing dividend = divisor x quotient + remainder.
- With negative numbers, compare the floored modulo with the truncated remainder that C, Java, and JavaScript return.
- Click the copy button to copy the result.
Remainders, Negative Numbers and Modulo
The modulo operation gives the remainder after division. 17 mod 5 = 2, because 5 goes into 17 three times with 2 left over. This calculator shows the remainder, the whole-number quotient, and a check line such as 17 = 5 x 3 + 2.
With positive numbers, everyone agrees on the answer. With negative numbers there are two conventions, and they give different results. This calculator uses floored modulo, the one used in math and in Python. Its answer always has the same sign as the divisor, so -17 mod 5 = 3. The % operator in C, Java and JavaScript works differently. It gives a truncated remainder that takes the sign of the dividend, so it returns -2. When the two differ, the calculator shows both, which helps when porting code between languages.
Modulo is behind many everyday patterns. A number is even when n mod 2 is 0. Clock time wraps around: 5 hours after 10 o'clock is (10 + 5) mod 12 = 3 o'clock. Days of the week work the same way. 100 days after a Monday is 100 mod 7 = 2 days later in the week, a Wednesday. Programmers use it to wrap list positions and spread items across hash tables. Bank account checks such as the IBAN Validator use mod 97.
Decimals work too, so 5.5 mod 2 is 1.5. The tool cleans up tiny floating point errors so results such as 0.3 mod 0.1 come out as 0. A divisor of 0 is not allowed. For the largest number that divides two values, see the GCD and LCM Calculator.
Formula / How It Works
Frequently Asked Questions
Related Tools
GCD and LCM Calculator
Find the greatest common divisor and least common multiple of two or more numbers.
Math and NumbersPrime Number Checker and Generator
Check if a number is prime and generate lists of prime numbers in any range.
Math and Numbers