Online Calculators and Tools | Calculators Toolbox
This modulo calculator finds a mod b, the remainder and quotient, including negative numbers and decimals.
Our free modulo calculator finds a mod b, the remainder left over after division, along with the quotient. It handles negative numbers and decimals, and shows how the result differs between math and programming conventions.
The modulo operation, written a mod b, gives the remainder when a is divided by b. If you share 17 cookies among 5 friends, each gets 3 and 2 are left over, so 17 mod 5 = 2. The number you divide (17) is the dividend, the number you divide by (5) is the divisor or modulus, and the answer (2) is the remainder.
Modulo is everywhere once you notice it. Clocks work in mod 12 (or mod 24), days of the week repeat in mod 7, and programmers use it constantly to cycle through lists, check whether numbers are even, and build hash tables and encryption.
Divide, round the quotient down to a whole number, and subtract to find what's left.
For 17 mod 5: 17 ÷ 5 = 3.4, which rounds down to 3. Then 5 × 3 = 15, and 17 − 15 = 2. The ⌊ ⌋ symbols mean "floor," or round down. This floor version always gives a result with the same sign as the divisor, which is the convention used in mathematics, Python and spreadsheet MOD functions.
15 hours after 10 o'clock is (10 + 15) mod 12 = 1 o'clock. Converting 17:00 to 12-hour time is 17 mod 12 = 5 PM.
If today is Monday, 100 days from now is 100 mod 7 = 2 days later, a Wednesday.
n % 2 === 0 checks for even numbers, and i % 3 === 0 runs code on every third item in a loop.
ISBN-10 and many ID numbers use mod 11 or mod 10 check digits to catch typing errors.
RSA and other encryption systems are built on modular arithmetic with very large numbers.
Assigning 23 tasks to 4 people in turn, the last task goes to person 23 mod 4 = 3.
The quotient is rounded down, so the remainder takes the sign of the divisor. With a positive divisor, the answer is always between 0 and b − 1.
Example: −17 mod 5 = 3, because −17 = 5 × (−4) + 3.
The quotient is rounded toward zero, so the remainder takes the sign of the dividend.
Example: −17 % 5 = −2, because −17 = 5 × (−3) + (−2).
For clock and calendar problems, and most math, use the floored version so results stay positive. When translating code between languages, check which convention each uses, because the same expression can give different answers.
The same formula works for decimals: 7.5 mod 2 = 1.5 and 10 mod 2.5 = 0. Spreadsheets and Python support this; some older languages only allow whole numbers.
| Expression | Quotient | Remainder (floored) | Truncated % |
|---|---|---|---|
| 17 mod 5 | 3 | 2 | 2 |
| 20 mod 4 | 5 | 0 | 0 |
| 100 mod 7 | 14 | 2 | 2 |
| 3 mod 10 | 0 | 3 | 3 |
| −17 mod 5 | −4 | 3 | −2 |
| 17 mod −5 | −4 | −3 | 2 |
| 25 mod 12 | 2 | 1 | 1 |
| 7.5 mod 2 | 3 | 1.5 | 1.5 |
New Year's Day falls on a Thursday. What day of the week is day 256 of the year?
Enter 255 and 7 into the modulo calculator to see the same quotient and remainder.
Modular arithmetic treats numbers as if they wrap around a circle, just like the hands of a clock. In mod 12, 13 is the same as 1, and 24 is the same as 0. Mathematicians write this as 13 ≡ 1 (mod 12), read as "13 is congruent to 1 modulo 12." You can add, subtract and multiply in modular arithmetic just like ordinary arithmetic, then take the remainder at the end. This idea, formalized by Carl Friedrich Gauss in 1801, now underpins computer science, digital signatures and secure online payments.
Spreadsheets make modulo easy for everyday tasks. In Excel or Google Sheets, =MOD(A2, 7) gives the remainder of A2 divided by 7. Combine it with ROW() to shade every other row (=MOD(ROW(), 2) = 0) or to assign items to groups in rotation. Both programs use the floored convention, so =MOD(-17, 5) returns 3, matching the main result of this modulo calculator rather than the % operator in JavaScript. If you build formulas that must match code written in another language, test a negative example first so the two systems agree before you rely on the results across a whole sheet.
Remainders with negative numbers and decimals are easy to get wrong, and different tools disagree. Our modulo calculator gives the mathematical result, the quotient and, where it differs, the programming-language result, all with a clear explanation. It's great for programmers, students, puzzle solvers and anyone working with clocks, calendars or cycles.
Mod, short for modulo, gives the remainder after dividing one number by another. 17 mod 5 = 2 because 17 divided by 5 is 3 with 2 left over.
Divide a by b, round the quotient down to a whole number, multiply it by b and subtract the result from a. What remains is a mod b.
In mathematics and Python, −17 mod 5 = 3. In C, Java and JavaScript, −17 % 5 returns −2 because those languages truncate toward zero.
It means b divides a exactly, with no remainder. For example, 20 mod 4 = 0, so 4 is a factor of 20.
Yes. The same formula works, so 7.5 mod 2 = 1.5. Python, Excel and Google Sheets all support decimal modulo.
Division gives the quotient, how many times b fits into a. Modulo gives the remainder, what is left over after that.