Modulo Calculator
- Modulo finds the remainder after division, with the result always in 0…5 for a positive divisor: 47 = 7 × 6 + 5, so 47 mod 6 = 5 and 47 ≡ 5 (mod 6).
- Watch the sign convention: mathematics and Python use floor division, so a negative dividend wraps around (47 mod 6 = 5). JavaScript and C use truncated division, where the remainder takes the dividend's sign (5 here). The two agree whenever the dividend is positive.
Our modulo calculator finds the remainder when one number is divided by another. The expression a mod n represents this remainder, and for positive n the mathematical result always lies in the range 0 to n−1. For example, 47 mod 6 = 5, because 47 = 7 × 6 + 5. Similarly, 100 mod 7 = 2, because 100 = 14 × 7 + 2. The calculator also handles negative numbers correctly: −47 mod 6 = 1 under the mathematical convention, because −47 = −8 × 6 + 1. Note that some programming languages like JavaScript and C return −5 instead, using truncated division. Two numbers are congruent modulo n when they share the same remainder, such as 47 ≡ 5 (mod 6).
The mathematical floor convention used here is the accepted standard because it guarantees a non-negative remainder in the range 0 to n−1, which is essential for real-world applications. Clocks use modulo 12 arithmetic, weekdays follow modulo 7, and check digits in ISBN and credit cards rely on modulo 10 or 11 schemes. This page shows the formula, step-by-step workings, worked examples, and sources so you can verify every result and understand how the remainder is computed.
Worked examples
47 mod 6
47 = 7 × 6 + 5, so the remainder is 5 — clock arithmetic: 47 hours from now lands 5 hours past the same clock position two days on. (47 · 6)
| 47 mod 6 | 5 |
| Quotient (floor division) | 7 |
| Truncated remainder (JavaScript/C style %) | 5 |
| Check | 47 = 7 × 6 + 5 |
−47 mod 6
Mathematically 1, because −47 = −8 × 6 + 1 and remainders stay in 0…5. JavaScript's % operator says −5 instead — a real source of bugs with negative inputs. (-47 · 6)
| -47 mod 6 | 1 |
| Quotient (floor division) | -8 |
| Truncated remainder (JavaScript/C style %) | -5 |
| Check | -47 = -8 × 6 + 1 |
100 mod 7
100 = 14 × 7 + 2, remainder 2 — the same trick weekday calculations use to jump 100 days ahead. (100 · 7)
| 100 mod 7 | 2 |
| Quotient (floor division) | 14 |
| Truncated remainder (JavaScript/C style %) | 2 |
| Check | 100 = 14 × 7 + 2 |
Remainders, formalized
Remainders, formalized
The modulo operation gives a precise definition to a familiar idea. When you divide one integer by another, the quotient tells you how many times the divisor fits, and the remainder tells you what is left over. The relationship is written as a = qn + r, where a is the dividend, n is the divisor, q is the quotient, and r is the remainder. The key constraint is 0 ≤ r < n: for positive n, the mathematical result always lies in the range from 0 up to n−1. In other words, a mod n is the remainder when a is divided by n.
Take 47 mod 6 = 5 as the anchor example. The equation 47 = 7 × 6 + 5 shows the full breakdown: the quotient is 7, the divisor is 6, and the remainder is 5. Because 5 is less than 6, it satisfies the rule that the remainder must be smaller than the divisor. The same logic applies to 100 mod 7 = 2, because 100 = 14 × 7 + 2. A modulo calculator performs this division and returns the remainder directly, so you do not have to work through the arithmetic by hand.
Negative dividends reveal a subtle but important split between conventions. Under the mathematical (floor) convention, −47 mod 6 = 1, because −47 = −8 × 6 + 1. The remainder stays within the required 0 to 5 range. However, JavaScript and C return −5 for −47 mod 6, using truncated division instead. The difference matters: the mathematical convention keeps remainders non-negative, while truncated division simply drops the fractional part of the quotient and lets the remainder take the sign of the dividend. When comparing results across tools or programming languages, check which convention each one uses.
Two numbers are congruent modulo n when they share the same remainder. For example, 47 ≡ 5 (mod 6), because both 47 and 5 leave a remainder of 5 when divided by 6. This idea extends far beyond pure arithmetic. Clocks are modulo 12 arithmetic, weekdays are modulo 7, and check digits (ISBN, credit cards) are modulo 10 or 11 schemes. These real-world systems rely on the same formal rule that keeps remainders in a fixed, repeating range.
Worked examples
The table below shows how a modulo calculator handles three representative cases. Each row breaks the calculation into the quotient and remainder, which is the value the calculator returns. For positive numbers the result is straightforward, but the negative case highlights an important convention difference that matters when you compare results across programming languages.
Two numbers are congruent modulo n when they share the same remainder, which is why 47 ≡ 5 (mod 6). The result a mod n is the remainder when a is divided by n, and for positive n the mathematical result always lies in 0 through n − 1. That range matters: it means the remainder is never negative under the mathematical convention, even when the dividend is negative. This is the standard used in number theory and in most calculator tools designed for general use.
The negative case in the table is where tools diverge. Under the mathematical or floor convention, −47 mod 6 equals 1, because −47 = −8 × 6 + 1. However, JavaScript and C return −5 for the same input, because they use truncated division instead of floor division. Both answers are internally consistent with their respective rules, but they place the remainder in different ranges. If you are debugging code or comparing outputs, knowing which convention your tool uses prevents confusion.
These examples connect to everyday systems more than they might appear to. Clocks are modulo 12 arithmetic, weekdays are modulo 7, and check digits such as those in ISBN and credit card numbers use modulo 10 or 11 schemes. The same logic that produces 100 mod 7 = 2, because 100 = 14 × 7 + 2, also underlies how a clock wraps from 12 back to 1 or how a checksum catches a single mistyped digit in a book number.
| Expression | Calculation | Result | Notes |
|---|---|---|---|
| 47 mod 6 | 47 = 7 × 6 + 5 | 5 | Standard positive case |
| −47 mod 6 | −47 = −8 × 6 + 1 | 1 (floor) / −5 (truncated) | Floor convention gives 1; JavaScript and C give −5 |
| 100 mod 7 | 100 = 14 × 7 + 2 | 2 | Standard positive case |
The negative-number trap
A modulo calculator seems simple enough: a mod n is the remainder when a is divided by n, and for positive n the mathematical result always lies in 0 … n−1. The examples that people test first are reassuringly clean. Verified: 47 mod 6 = 5, because 47 = 7 × 6 + 5. Verified: 100 mod 7 = 2, because 100 = 14 × 7 + 2. Two numbers are congruent modulo n when they share the same remainder, so 47 ≡ 5 (mod 6). Everything looks consistent — until a negative number appears.
The trouble is that not every language agrees on what the remainder means when the dividend is negative. Mathematics uses floor division, which rounds the quotient toward negative infinity and keeps the remainder non-negative. Verified: −47 mod 6 = 1 under the mathematical (floor) convention, because −47 = −8 × 6 + 1. Python follows this rule, as do Ruby, Haskell, and most computer algebra systems. The result always falls in the expected range of 0 … n−1 for positive n, which keeps cyclic structures tidy: clocks are modulo 12 arithmetic, weekdays are modulo 7, and check digits (ISBN, credit cards) are modulo 10 or 11 schemes, and in every one of these the remainder must stay non-negative for the system to work.
JavaScript, C, Java, and many related languages instead use truncated division, which rounds the quotient toward zero and lets the remainder keep the dividend's sign. Under that rule the same calculation returns −5 instead of 1. Verified: −47 mod 6 = 1 under the mathematical (floor) convention, because −47 = −8 × 6 + 1 — but JavaScript and C return −5, using truncated division. The two conventions agree whenever both inputs are positive, which is why the gap hides during testing and then surfaces in production the moment real-world data introduces a negative value.
The bug pattern in real code is predictable: a developer writes an index expression like ((x % n) + n) % n to normalize a result, tests it with positive values, and ships it. Later, when x goes negative in JavaScript or C, the first modulo returns a negative remainder, the shift by n does not land in the intended slot, and the second modulo either fixes it or propagates the error depending on how the expression was ordered. Using a modulo calculator that respects the floor convention makes the mismatch visible before it reaches production — but only if you remember to test with negative inputs.
Congruence: numbers that behave the same
When you use a modulo calculator, the result is the remainder when a is divided by n. For positive n, the mathematical result always lies in 0 … n−1. But two numbers can share that same remainder without being identical — and when they do, they are called congruent modulo n. The notation is a ≡ b (mod n), read as "a is congruent to b modulo n." Congruence means the numbers behave the same way in further modular arithmetic, even though they may look completely different at a glance.
A concrete example makes this clear. The calculator confirms that 47 mod 6 = 5, because 47 = 7 × 6 + 5. The number 5 itself also has remainder 5 when divided by 6, since 5 = 0 × 6 + 5. Because both 47 and 5 leave the same remainder, we write 47 ≡ 5 (mod 6). From the perspective of modulo 6 arithmetic, the two numbers are interchangeable. If you add 3 to either one and reduce mod 6, you get the same answer: 47 + 3 = 50, and 50 mod 6 = 2; likewise, 5 + 3 = 8, and 8 mod 6 = 2. The starting point differs, but the modular result does not.
This interchangeability is what makes congruence so useful. You can replace a large number with a smaller, congruent one to keep calculations manageable. For instance, 100 mod 7 = 2, because 100 = 14 × 7 + 2. So 100 ≡ 2 (mod 7), and any arithmetic you do with 100 modulo 7 will produce the same result as if you had used 2 — a far simpler number to work with. The principle scales: no matter how large the original value, you can reduce it to its remainder and proceed from there.
Congruence also explains why modular arithmetic shows up everywhere in daily life. Clocks are modulo 12 arithmetic: adding 5 hours to 9 o'clock gives 2, because 14 mod 12 = 2. Weekdays are modulo 7: seven days from any given day lands on the same weekday again. And check digits in ISBN codes and credit card numbers rely on modulo 10 or modulo 11 schemes, where a computed remainder verifies that the digits were entered correctly.
Modulo in daily life
You probably use modulo arithmetic more often than you realize. A standard wall clock is the most familiar example: once the hour hand passes 12, it starts over at 1. This is modulo 12 arithmetic in action. The same principle applies to a 24-hour clock, where the cycle resets after 24. Because a mod n is the remainder when a is divided by n, and for positive n the mathematical result always lies in 0 through n−1, a clock face effectively shows hours as remainders within a fixed cycle.
Weekdays work the same way, using modulo 7. If today is Monday and you want to know what day of the week it will be 100 days from now, you can compute 100 mod 7. Verified: 100 mod 7 = 2, because 100 = 14 × 7 + 2. That remainder of 2 means 100 days later is two weekdays ahead of Monday, which is Wednesday. This is why a modulo calculator can quickly answer scheduling questions without counting full weeks.
Another everyday application is parity checking. A number is even when it is congruent to 0 modulo 2, and odd when it is congruent to 1 modulo 2. Two numbers are congruent modulo n when they share the same remainder, so 47 ≡ 5 (mod 6) because both leave a remainder of 5 when divided by 6. Parity checks form the backbone of error detection in digital systems.
Beyond clocks and calendars, modulo arithmetic underpins several behind-the-scenes systems. Check digits on ISBNs and credit cards rely on modulo 10 or modulo 11 schemes to catch typos and transcription errors. Hash buckets in computer science also use modulo operations to distribute data evenly across a fixed number of storage slots. Whenever data needs to cycle through a fixed range, modulo arithmetic provides the mechanism.
One caution is worth noting if you ever work with negative numbers in code. Verified: −47 mod 6 = 1 under the mathematical (floor) convention, because −47 = −8 × 6 + 1. However, JavaScript and C return −5 for the same expression, using truncated division instead. This difference matters when a modulo calculator must match results across different programming environments.
Modulo vs remainder in programming languages
A modulo calculator gives the mathematical modulo result, but programming languages do not all agree on what that means for negative inputs. The distinction comes down to how each language handles division when the dividend is negative. In mathematics, a mod n is the remainder when a is divided by n, and for positive n the result always lies in 0 … n−1. For example, 47 mod 6 = 5, because 47 = 7 × 6 + 5, and 100 mod 7 = 2, because 100 = 14 × 7 + 2. The sign of the result matches the divisor, not the dividend.
Python implements % as a floor-mod operator, which agrees with the mathematical convention. Under this convention, −47 mod 6 = 1, because −47 = −8 × 6 + 1. The result is always non-negative when the divisor is positive. JavaScript and C take a different approach: their % operator is a remainder, not a true modulo. These languages use truncated division, which rounds toward zero, so JavaScript and C return −5 for −47 mod 6. The sign of the result follows the dividend, which can place it outside the expected 0 … n−1 range.
Rust provides both options explicitly. The rem operator gives the truncated remainder, matching the behavior of JavaScript and C, while rem_euclid gives the Euclidean modulo result, matching the mathematical convention. This avoids the ambiguity that other languages force you to work around manually.
If your language only offers a truncated remainder and you need the mathematical modulo, the standard fix is the expression ((a % n) + n) % n. The inner operation adds n to shift a negative remainder into positive territory, and the outer operation wraps it back into the 0 … n−1 range. This works because two numbers are congruent modulo n when they share the same remainder, as with 47 ≡ 5 (mod 6). The same principle underlies real-world systems: clocks are modulo 12 arithmetic, weekdays are modulo 7, and check digits (ISBN, credit cards) are modulo 10 or 11 schemes. When you use a modulo calculator, it applies the mathematical convention, so keep that in mind if you are comparing results against code in JavaScript or C.
FAQs
What is 47 mod 6?
The answer is 5, because 47 = 7 × 6 + 5. When you divide 47 by 6, the quotient is 7 and the remainder is 5. That remainder is the modulo result.
Why is −47 mod 6 equal to 1 and not −5?
Mathematically the remainder must sit in 0…5: −47 = −8 × 6 + 1. Programming languages with truncated division (JavaScript, C) return −5 instead, but the true mathematical modulo result is 1.
What does mod mean in math?
The remainder after division, and more broadly the congruence relation: a ≡ b (mod n) means n divides a − b. So mod covers both the leftover value from division and the formal statement that two numbers share the same remainder.
How do I compute mod with a negative number in code?
Use ((a % n) + n) % n in JavaScript-style languages to get the mathematical floor-mod result. This adjusts the truncated remainder that languages like JavaScript and C return, bringing it into the correct positive range.
What is 100 mod 7?
The answer is 2 — 100 = 14 × 7 + 2. It is also why 100 days from a Monday is a Wednesday. Dividing 100 by 7 leaves a remainder of 2, shifting the weekday forward by two positions.
Is mod the same as the % operator?
Only for positive operands in most languages. For negatives, % is usually a truncated remainder, while mathematical mod is a floor remainder. So they agree on positive numbers but can differ on negative inputs depending on the language.