Modulo Calculator
Calculate a mod b — the remainder after division — with the floor quotient shown too.
The remainder and the quotient
Enter a dividend a and a divisor b. The calculator shows a mod b, the remainder left after dividing, and the floor quotient, how many whole times b fits into a, rounded down.
With the defaults, 17 mod 5 is 2 and the quotient is 3. The two always fit together as a = b × quotient + remainder: 5 × 3 + 2 = 17. That identity is a quick way to check any result, including the negative ones below.
Negative numbers: which rule this calculator uses
There are two common conventions for the remainder of a negative number, and they give different answers. This calculator uses the mathematical one, sometimes called floored modulo. It computes ((a % b) + b) % b and rounds the quotient down. With a positive divisor, the result is always between 0 and b − 1.
| Input | This calculator | Quotient | JavaScript a % b |
|---|---|---|---|
| −17 mod 5 | 3 | −4 | −2 |
| −7 mod 3 | 2 | −3 | −1 |
| −1 mod 12 | 11 | −1 | −1 |
JavaScript's % operator, and its equivalent in C and Java, truncates toward zero, so the remainder takes the sign of the dividend. Python's % gives the same results as this calculator. If you're checking code, make sure you compare against the convention your language uses.
The identity still holds either way: 5 × −4 + 3 = −17. If you type a negative divisor, the result takes the divisor's sign. 17 mod −5 is −3, with a quotient of −4.
Everyday uses
- Clock time: 15 hours after 14:00 is (14 + 15) mod 24 = 5, so 05:00 the next day.
- Days of the week: 100 days after a Monday, 100 mod 7 = 2, so two days on: a Wednesday.
- Counting backwards: one hour before 12 on a 12-hour dial is −1 mod 12 = 11. This is where the floored convention earns its keep, since truncated modulo would give −1.
- Odd or even: n mod 2 is 0 for even numbers and 1 for odd ones, negatives included.
- Last digit: 1234567 mod 10 is 7, and the quotient, 123,456, is the number with that digit removed.
When a is smaller than b, the remainder is just a and the quotient 0: 5 mod 17 is 5.
Decimals and floating-point surprises
Decimals work: 7.5 mod 2 is 1.5, with a quotient of 3. But numbers like 0.1 can't be stored exactly in binary, which leads to odd results. 0.3 mod 0.1 should be 0, yet the calculator shows 0.1, with a quotient of 2. The stored remainder is a hair under 0.1, and the two-decimal display rounds it up.
To avoid this, scale to whole numbers first. Instead of 0.3 mod 0.1, use 3 mod 1, which is 0. A divisor of 0 shows dashes, since dividing by zero has no remainder.
Frequently asked questions
What does 17 ≡ 2 (mod 5) mean?+
It reads 17 is congruent to 2 modulo 5, meaning both numbers leave the same remainder when divided by 5. Equivalently, their difference, 15, is a multiple of 5. This calculator gives the smallest non-negative number in that family, which is 2.
How do I check whether one number divides another?+
Look for a remainder of 0. 24 mod 6 is 0, so 6 divides 24 exactly, four times. Any other result means it doesn't divide evenly.
Does it work with very large numbers?+
Up to a point. The browser stores numbers in a format that holds every whole number exactly only up to 9,007,199,254,740,992. Beyond that, the dividend you typed may already be rounded before the calculation starts, so the remainder can't be trusted.
Embed this tool on your website
Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.
<iframe src="https://utilityapp.lat/embed/math/modulo-calculator" title="Modulo Calculator" width="100%" height="660" style="border:0;max-width:760px" loading="lazy"></iframe> <p style="font-size:13px"><a href="https://utilityapp.lat/math/modulo-calculator">Modulo Calculator</a> by UtilityApp</p>