About the Modulo Calculator
Modulo gives the remainder after division and powers clock arithmetic, check digits, cryptography and programming tricks such as alternating row colors. This modulo calculator handles numbers of any size, so 17 mod 5 is 2, and it shows both conventions for negative numbers, since −7 mod 3 is 2 in mathematics but −1 in languages such as JavaScript and C.
For positive numbers all conventions agree. With negatives they differ in which way the quotient is rounded. Truncated division rounds the quotient toward zero, so the remainder takes the sign of a: −17 % 5 = −2 in JavaScript. Floored division rounds the quotient down, so the remainder takes the sign of n: −17 mod 5 = 3 in Python. The Euclidean remainder is never negative. In every case a = quotient × n + remainder.
Example: 17 mod 5 = 2 with quotient 3. For −17 and 5, the floored result is 3 with quotient −4, since −17 = −4 × 5 + 3, while the truncated remainder is −2 with quotient −3. For 17 and −5, floored gives −3 and truncated gives 2. A huge value such as 123456789012345678901234567890 mod 97 = 52 is computed exactly with big integers.
Modular arithmetic is clock arithmetic: 10 hours after 9 o'clock is (9 + 10) mod 12 = 7 o'clock. It underpins checksums, hashing and cryptography. See also the GCF calculator, the prime number checker and the long division calculator.
How to use the Modulo Calculator
- Enter the dividend aType any whole number, positive or negative, of any length.
- Enter the divisor nType the modulus; it cannot be zero.
- Read a mod nSee the mathematical (floored) result and the quotient.
- Compare conventionsSee the truncated and Euclidean remainders used by different languages.
Modulo Calculator features
- a mod n for integers of any size
- Quotient and remainder together
- Floored, truncated and Euclidean conventions
- Correct handling of negative numbers
- Exact BigInt arithmetic
- Division check a = q × n + r
- Free and private
Common uses
- Programming and debugging % operators
- Clock and calendar arithmetic
- Checksums and check digits
- Number theory and cryptography lessons
- Splitting items into groups with leftovers
Modulo in practice: clocks, calendars, check digits and code
The modulo operation gives the remainder after division: 17 mod 5 is 2. That simple idea powers clock arithmetic, day-of-the-week calculations, the check digits that catch typing errors in book numbers and bank accounts, and countless everyday programming tasks. This guide walks through those uses with worked examples and explains why different programming languages disagree about negative numbers.
Clock arithmetic
Clocks are the most familiar example of modular arithmetic. On a 24-hour clock, 15 hours after 14:00 is (14 + 15) mod 24 = 5, so 05:00 the next day. On a 12-hour clock, 9 hours after 8 o'clock is (8 + 9) mod 12 = 5 o'clock. Thinking in remainders avoids counting hours one by one.
Days of the week
Weeks repeat every 7 days, so modulo 7 tells you which weekday a future date falls on. If today is Saturday, then 100 days from now is 100 mod 7 = 2 days further on in the week, which is Monday. The same idea lies behind formulas that calculate the weekday of any date in history.
Check digits
Many identification numbers end with a check digit calculated from the others using modular arithmetic, so that typing mistakes are caught. ISBN-13 book numbers multiply the first 12 digits alternately by 1 and 3, add the results and choose the final digit so that the total is a multiple of 10. Bank card numbers use the Luhn algorithm, also based on mod 10, and international bank account numbers, IBANs, use mod 97.
A worked example: an ISBN check digit
Take the first twelve digits of an ISBN: 978030640615. Multiplying alternately by 1 and 3 gives 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15 = 93. The remainder of 93 divided by 10 is 3, so the check digit is 10 − 3 = 7, and the full ISBN is 9780306406157.
If someone types one digit wrong, the total almost always changes so that it no longer ends in zero, and the system flags the error before an order is placed for the wrong book.
Even and odd, and cycling in code
Programmers use modulo constantly. n mod 2 is 0 for even numbers and 1 for odd ones. Cycling through a list of items, such as rotating banner images or assigning tasks to team members in turn, uses index mod length, which wraps back to the start automatically. Hash tables, random number generators and encryption all rely on modular arithmetic too.
Negative numbers in different languages
Languages disagree about negative numbers. In JavaScript, C and Java, −7 % 3 gives −1, because the remainder takes the sign of the dividend. In Python, −7 % 3 gives 2, because the result takes the sign of the divisor. Both are mathematically defensible, but code that moves between languages can break if the difference is overlooked. For clock-style wrapping, Python's behaviour is usually what you want.
Modular arithmetic in cryptography
Public-key encryption, such as RSA, performs arithmetic modulo very large numbers. Raising a message to a power and taking the remainder modulo a large number scrambles it in a way that is easy to reverse only with the private key. The same remainder operation used for clocks is, at much larger scale, protecting secure websites.
Common mistakes
- Assuming every language handles negative remainders the same way.
- Confusing the quotient with the remainder.
- Forgetting that mod 0 is undefined.
- Using mod 12 when a 24-hour clock is meant.
Related tools
For division with full steps, use Long Division Calculator. For common factors, try GCF Calculator, and for dates, Day of the Week Calculator.
Leap years with modulo
Leap year rules are written naturally with modulo. A year is a leap year if year mod 4 is 0, unless year mod 100 is 0, in which case it is a leap year only if year mod 400 is also 0. So 2024 was a leap year, 1900 was not and 2000 was. Calendar software uses exactly these checks.
Converting units of time
Modulo and whole-number division together convert large numbers of minutes or seconds into hours and minutes. For 1,000 minutes, 1,000 divided by 60 is 16 with a remainder of 40, so 1,000 minutes is 16 hours 40 minutes. Repeating the step with 24 converts hours into days and hours, which is how timers and video players display long durations.
Packing and distributing
When items are packed into equal groups, modulo gives the leftovers. Packing 47 items into boxes of 6 fills 7 boxes, and 47 mod 6 = 5 items remain. Knowing the remainder in advance tells you whether an extra box is needed, or whether ordering a few more items would fill the last box exactly.
Round-robin schedules
Tournament organisers and teachers use modulo to rotate teams, players or duties fairly. With 5 groups and a task that rotates daily, the group responsible on day n is n mod 5, cycling through 0 to 4. The same idea assigns weekly cleaning duties, shift rotations or turns in a game, and it continues smoothly however many days pass.
Limits
Results are exact for whole numbers of any practical size, with the sign convention shown alongside the result.
Frequently asked questions
What does mod mean?
Mod, short for modulo, gives the remainder after division. 17 mod 5 = 2, since 5 goes into 17 three times with 2 left over. It is written a mod n or, in most programming languages, a % n.
How do I calculate a mod n by hand?
Divide a by n, take the whole-number part of the quotient, multiply it back by n and subtract from a. For 47 mod 6: 47 ÷ 6 = 7.83, 7 × 6 = 42, and 47 − 42 = 5.
What is a negative number mod n?
In mathematics and Python, −17 mod 5 = 3, because −17 = −4 × 5 + 3. In C, Java and JavaScript, −17 % 5 = −2, because those languages truncate the quotient toward zero. Both satisfy a = q × n + r.
What is the difference between mod and remainder?
For positive numbers they are the same. With negatives, remainder usually means the truncated result, which keeps the sign of a, while modulo often means the floored result, which keeps the sign of the divisor.
What is 0 mod n?
0 for any nonzero n, because n divides 0 exactly. Also, a mod n = 0 exactly when n divides a, which is a quick way to test divisibility.
Can you take mod 0?
No. a mod 0 would require dividing by zero, which is undefined, so the calculator reports an error. Some languages raise an exception and others return NaN.
Where is modulo used in real life?
Clock times, days of the week, ISBN and credit card check digits, hashing in computer science, cyclic patterns in programming and public-key cryptography such as RSA, which relies on modular exponentiation.
How do I find a remainder with an ordinary calculator?
Divide a by n, keep only the decimal part of the answer and multiply it by n. For 47 ÷ 6 = 7.8333…, the decimal part 0.8333… × 6 = 5, so the remainder is 5. Round the result, since the decimal is slightly inexact.