Modulo Calculator
The remainder of a mod n, with negatives handled correctly
Last updated September 2026
Method: The division algorithm r = a − n × q, evaluated three ways: floored quotient (Python, Excel MOD), truncated quotient (C, Java, JavaScript) and the Euclidean form whose remainder is never negative. Whole numbers are computed with exact arbitrary-precision arithmetic.
Included: Remainder and quotient in all three conventions, a check of the identity a = n × q + r, a divisibility flag, and a table of your number mod 2 through mod 12.
Not included: Modular exponentiation, modular inverses and congruence solving. The modulus must not be zero, since division by zero is undefined.
Remainder of -17 mod 5
Check: a = n × q + r
-17 = 5 × (-4) + (3)-17 = 5 × (-3) + (-2)Whole-number inputs are handled exactly with arbitrary-precision arithmetic, so very large values keep every digit.
-17 mod 2 through 12
| Modulus | Quotient | Remainder | Divisible |
|---|---|---|---|
| mod 2 | -9 | 1 | no |
| mod 3 | -6 | 1 | no |
| mod 4 | -5 | 3 | no |
| mod 5 | -4 | 3 | no |
| mod 6 | -3 | 1 | no |
| mod 7 | -3 | 4 | no |
| mod 8 | -3 | 7 | no |
| mod 9 | -2 | 1 | no |
| mod 10 | -2 | 3 | no |
| mod 11 | -2 | 5 | no |
| mod 12 | -2 | 7 | no |
Remainders here use the floored convention, so every value is between 0 and the modulus minus 1.
Exact arithmetic, no rounding for whole numbers. The modulo operation returns what is left after dividing a by n. Programming languages disagree only about the sign of the remainder when a or n is negative, which is why this calculator shows the floored, truncated and Euclidean results side by side.
Modulo calculator: everything you need to know
A modulo calculator returns what is left over after one number is divided by another. Written a mod n, it keeps only the leftover, not the quotient. Example: 17 mod 5 = 2, because 5 fits into 17 three whole times (15) and 2 remains. Negative inputs have two accepted answers, and this page shows both.
Three sister tools cover neighboring questions. The Long Division Calculator writes out the full division that produces the quotient and remainder step by step, the GCF Calculator runs the Euclidean algorithm, which is nothing but repeated modulo, and the LCM Calculator answers the mirror-image question of the smallest common multiple. Use this page when you want the leftover itself, especially when a minus sign is involved.
How the modulo operation works
Every division of a whole number a (the dividend) by a non-zero whole number n (the modulus or divisor) can be written with one quotient and one remainder:
a = n × q + r so r = a − n × q Here q is the quotient and r is the remainder, the value the modulo operation returns. The formula alone is not quite enough, because it does not say how to round the quotient when the division does not come out even. That single choice is what separates the conventions:
- Floored: round the quotient down, toward negative infinity. The remainder then takes the sign of the modulus. This is what Python, Ruby and the MOD function in Excel and Google Sheets do.
- Truncated: round the quotient toward zero, simply dropping the fractional part. The remainder then takes the sign of the dividend. This is what C, C++, Java, C# and JavaScript do with the percent operator.
- Euclidean: choose the quotient so the remainder is never negative, whatever the sign of the modulus. This is the version mathematicians usually mean when they talk about residues.
When both numbers are positive, all three agree, which is why most people never notice the difference until a minus sign appears.
Worked example: −17 mod 5, step by step
Take the dividend a = −17 and the modulus n = 5. Work the floored version first:
- Divide: −17 ÷ 5 = −3.4.
- Round the quotient down to the next whole number: −4.
- Multiply back: 5 × (−4) = −20.
- Subtract: r = −17 − (−20) = 3.
- Check the identity: 5 × (−4) + 3 = −20 + 3 = −17. Correct.
Now the truncated version, which is what most programming languages give you:
- Divide: −17 ÷ 5 = −3.4.
- Round the quotient toward zero, dropping the decimals: −3.
- Multiply back: 5 × (−3) = −15.
- Subtract: r = −17 − (−15) = −2.
- Check the identity: 5 × (−3) + (−2) = −15 − 2 = −17. Also correct.
So −17 mod 5 is 3 in Python and in a spreadsheet, and −2 in JavaScript, Java or C. Neither answer is a bug. They differ by exactly one copy of the modulus, since 3 − 5 = −2, and both satisfy a = n × q + r.
Second worked example: 1,234 mod 12
With two positive numbers the arithmetic is simpler. Divide 1,234 by 12 to get 102.833..., drop the fraction for a quotient of 102, multiply back to 12 × 102 = 1,224, and subtract: 1,234 − 1,224 = 10. So 1,234 mod 12 = 10, and because the remainder is not zero, 1,234 is not a multiple of 12. Read on a 12-hour clock face, starting at 12 and counting forward 1,234 hours lands you 10 hours around the dial.
Negative numbers: floored, truncated and Euclidean side by side
The table below runs the dividend 17 and its negative against the modulus 5 and its negative, so you can see exactly where the three conventions split. Every row satisfies a = n × q + r in its own column pair.
| a mod n | Floored q | Floored r | Truncated q | Truncated r | Euclidean r |
|---|---|---|---|---|---|
| 17 mod 5 | 3 | 2 | 3 | 2 | 2 |
| −17 mod 5 | −4 | 3 | −3 | −2 | 3 |
| 17 mod −5 | −4 | −3 | −3 | 2 | 2 |
| −17 mod −5 | 3 | −2 | 3 | −2 | 3 |
Two patterns fall out of the table. The floored remainder always carries the sign of the modulus, and the truncated remainder always carries the sign of the dividend. When the two inputs share a sign, the rows agree.
1,234 mod 2 through mod 12
Running one number against every small modulus is a fast way to see its divisibility fingerprint. Here is 1,234 with the quotient and the floored remainder for each modulus from 2 to 12. The calculator above builds the same table for whatever number you type.
| Modulus n | Quotient q | 1,234 mod n | Divides evenly? |
|---|---|---|---|
| 2 | 617 | 0 | yes |
| 3 | 411 | 1 | no |
| 4 | 308 | 2 | no |
| 5 | 246 | 4 | no |
| 6 | 205 | 4 | no |
| 7 | 176 | 2 | no |
| 8 | 154 | 2 | no |
| 9 | 137 | 1 | no |
| 10 | 123 | 4 | no |
| 11 | 112 | 2 | no |
| 12 | 102 | 10 | no |
Only mod 2 gives zero, so 1,234 is even but shares no other factor from 2 to 12. Notice that mod 10 = 4 is simply the last digit, and mod 100 would be the last two digits, 34. Powers of ten make the modulo a digit-slicing tool.
Which convention does your tool use?
If two tools hand you different answers for the same negative input, this table usually explains why. It lists the sign rule each environment applies to the remainder.
| Tool or language | Operator | Convention | −17 mod 5 |
|---|---|---|---|
| Python | % | Floored, sign of the modulus | 3 |
| Excel / Google Sheets | MOD | Floored, sign of the modulus | 3 |
| Ruby | % | Floored, sign of the modulus | 3 |
| JavaScript | % | Truncated, sign of the dividend | −2 |
| C, C++, C# | % | Truncated, sign of the dividend | −2 |
| Java | % | Truncated, sign of the dividend | −2 |
| Java | Math.floorMod | Floored, sign of the modulus | 3 |
If you need a non-negative result in a truncated language, the standard fix is to add the modulus and take the modulo again, writing the expression as a percent n plus n, then percent n once more. That maps −2 back to 3 without changing any positive result.
How to use this modulo calculator
Two numbers are all you need, and the result updates as you type. Work through the fields in order:
- Dividend (a): the number being divided. Whole numbers of any length are handled exactly; decimals and negatives are accepted too.
- Modulus (n): the number you divide by, sometimes called the divisor. It cannot be zero. Use the quick buttons for the common moduli 2, 7, 10, 12, 24, 60 and 100.
- Sign convention: pick floored, truncated or Euclidean to choose which value appears as the headline. The other results stay visible in the tiles underneath, so you never have to run the calculation twice.
- Read the check line: the identity a = n × q + r is printed out with your actual numbers, which is the fastest way to confirm a hand calculation.
- Scan the table: the mod 2 through mod 12 table shows every small remainder at once, with a flag on any modulus that divides your number evenly.
Who this calculator is for
- Students checking homework on remainders, divisibility and modular arithmetic.
- Programmers debugging an index that wrapped the wrong way, or porting code between a floored language and a truncated one.
- Spreadsheet users who need to know why the MOD function disagrees with a result from their code.
- Puzzle and competition solvers working congruences, cycle lengths and last-digit questions.
- Anyone scheduling on a cycle, such as rotating shifts, recurring dates or a repeating rota, where the answer is a leftover position rather than a count.
Key terms explained
- Dividend (a): the number being divided, the value on the left of a mod n.
- Modulus (n): the number you divide by. It sets the size of the wrap, so a positive modulus n produces remainders from 0 to n minus 1.
- Quotient (q): how many whole copies of the modulus fit inside the dividend, after rounding in the chosen direction.
- Remainder (r): what is left over, and the value the modulo operation returns.
- Residue: another word for the remainder in modular arithmetic, usually the Euclidean one that is never negative.
- Congruence: the statement that two numbers leave the same remainder, as in 26 is congruent to 2 modulo 12.
- Divisor: a number that divides another with remainder 0. If a mod n = 0, then n is a divisor of a.
Where the modulo shows up in everyday life
Modulo is the arithmetic of anything that wraps around, which makes it far more common than its name suggests:
- Clocks: 26 mod 12 = 2, so 26 hours after noon the hour hand points at 2. Minutes and seconds run on mod 60, and 24-hour time on mod 24.
- Time conversion: 3,725 seconds is 3,725 mod 60 = 5 seconds left over, 62 whole minutes, and 62 mod 60 = 2 minutes left over after 1 hour, giving 1:02:05.
- Weekdays: 100 mod 7 = 2, so 100 days from a Monday is a Wednesday.
- Even and odd: a mod 2 = 0 means even, 1 means odd. That single test drives alternating table rows, striped charts and coin-flip logic.
- Leap years: the Gregorian rule is pure modulo. 2026 mod 4 = 2, so 2026 is not a leap year. 2100 mod 4 = 0 but 2100 mod 400 = 100, so 2100 is skipped, while 2000 mod 400 = 0 made 2000 a leap year.
- Splitting things up: 48 slices shared by 5 people leaves 48 mod 5 = 3 slices over.
- Programming: wrapping an index back to the start of an array, spreading keys across hash buckets, striping work across servers, and computing check digits on account, ISBN and card numbers.
Divisibility shortcuts you can do in your head
For small moduli you rarely need long division at all, because the remainder can be read off the digits:
- mod 2: look at the last digit. Even digit, remainder 0.
- mod 5 and mod 10: the last digit decides. 97 mod 10 = 7, and 97 mod 5 = 2.
- mod 4: only the last two digits matter, because 100 is a multiple of 4. For 1,234 that is 34, and 34 mod 4 = 2, which matches the table above.
- mod 3 and mod 9: add the digits. For 1,234 the digit sum is 10, and 10 mod 9 = 1, so 1,234 mod 9 = 1. The same digit sum gives 10 mod 3 = 1 for mod 3.
- Powers of 10: 123,456,789 mod 1,000 = 789, the last three digits.
What changes the result
If you are experimenting with the inputs, three things move the answer:
- The size of the modulus: it fixes the range of possible answers. A positive modulus n can only ever return 0 through n minus 1, so mod 7 answers live in 0 to 6 no matter how large the dividend is.
- The signs: the conventions only diverge when the dividend and the modulus have different signs. Two positives, or two negatives, and every method agrees.
- Adding or subtracting whole moduli: the remainder does not change. 23 mod 5, 28 mod 5 and 1,000,023 mod 5 all equal 3, because adding a multiple of the modulus adds nothing to the leftover. That is the whole idea of congruence.
Tips for getting the answer you actually want
- Decide the convention before you code. If a negative result would break your logic, use the Euclidean value and force it in code with the add-then-modulo trick.
- Verify with the identity. Multiply the quotient by the modulus and add the remainder. If you do not get the dividend back, the quotient was rounded the wrong way.
- Use the wrap deliberately. To cycle a counter through positions 0 to 5, increment it and take mod 6 every time rather than testing for the end value.
- Keep the modulus positive. A negative modulus is legal but the results are counter-intuitive, and almost every practical use has n greater than zero.
- Watch decimals. Binary floating point cannot store 0.1 exactly, so a decimal modulo can land a hair away from the value you expect. Scale to whole numbers when the exact answer matters.
Limitations and assumptions
- The modulus cannot be zero. There is no quotient that satisfies a = 0 × q + r for a non-zero a, so the operation is undefined.
- Whole-number inputs are exact at any length, but decimal inputs use standard floating-point arithmetic, precise to roughly 15 significant digits, and are rounded to ten decimal places for display.
- This page covers the single operation a mod n. It does not do modular exponentiation, modular inverses, or solving a congruence for an unknown.
- Results are pure arithmetic, so no rounding rules, tax tables or measurement standards apply. The only judgment call is the sign convention, and all three are shown.
How it compares to related calculators
This page answers "what is left over after dividing?" If your question is slightly different, another tool fits better:
- To see the whole division written out, digit by digit, use the Long Division Calculator.
- To find the largest number that divides two values with remainder 0, use the GCF Calculator, which applies repeated modulo through the Euclidean algorithm.
- To find the smallest number that two values both divide into, use the LCM Calculator.
- To break a number into its prime building blocks, use the Prime Factorization Calculator.
- To convert between number bases, where repeated modulo is exactly how digits are extracted, use the Binary Calculator.
- To turn a leftover into a fraction of the divisor, use the Fraction Calculator, or the Percentage Calculator to express it as a share.
Sources
Everything on this page is deterministic arithmetic and exact definition, so no external data source is needed. The definitions used are:
- The division algorithm, a = n × q + r with the remainder smaller in size than the modulus - standard number theory (Euclid's Elements, Book VII).
- U.S. Common Core State Standards for Mathematics (4.NBT.B.6 and 6.NS.B.2) - finding whole-number quotients and remainders.
- ECMA-262, the ECMAScript language specification - the percent operator returns a remainder carrying the sign of the dividend, which is the truncated convention used in this calculator.
- ISO/IEC 9899, the C language standard (C99 and later) - integer division truncates toward zero, so the percent operator follows the sign of the dividend.
- The Gregorian leap-year rule, divisible by 4 except centuries that are not divisible by 400, quoted in the everyday-uses section.
⚠️ Common mistakes & edge cases
Assuming a negative dividend gives a positive remainder
In C, Java and JavaScript, −17 % 5 is −2, not 3. Code that uses the result as an array index or a color slot will run off the start of the list. Wrap it as a percent n plus n, then percent n again to force a value from 0 to n minus 1.
Comparing a spreadsheet to code without checking the convention
Excel and Google Sheets use the floored MOD, so MOD(−17, 5) returns 3, while the same expression in a script returns −2. The numbers are not in conflict; they differ by exactly one modulus, since 3 − 5 = −2.
Using zero as the modulus
a mod 0 is undefined, not zero and not a. Guard the divisor before you compute, especially when the modulus comes from user input, a list length or a count that can legitimately be empty.
Reading the remainder as a decimal
1,234 ÷ 12 = 102.833..., but the modulo is 10, not 0.833. The decimal part is the remainder divided by the modulus, so 10 ÷ 12 = 0.833. Multiply the fraction back by the modulus to recover the true leftover.
Trusting a decimal modulo to be exact
Floating-point numbers cannot store values like 0.1 exactly, so a decimal modulo can return something a fraction away from the expected result. When exactness matters, scale both numbers to whole units first, for example working in cents instead of dollars.
Confusing the modulus with the quotient
In a mod n, the answer is the leftover, not how many times n fits. For 1,234 mod 12 the quotient is 102 and the modulo result is 10. Both are shown side by side above so the two never get mixed up.
❓ Frequently asked questions
What does modulo mean?
Modulo is the operation that returns what is left over after one whole number is divided by another. Written a mod n, it answers the question 'if I divide a by n and only keep whole units, how much is left?' For example, 17 mod 5 is 2, because 5 goes into 17 three times (15) and 2 remains.
How do you calculate a mod n by hand?
Divide a by n and throw away the fractional part to get the quotient q, then multiply back and subtract: r = a - n x q. For 1,234 mod 12, the quotient is 102 because 12 x 102 = 1,224, and the remainder is 1,234 - 1,224 = 10. So 1,234 mod 12 = 10.
What is -17 mod 5?
It depends on the convention. Under the floored convention used by Python and by the MOD function in Excel and Google Sheets, -17 mod 5 = 3, with quotient -4, because 5 x (-4) + 3 = -17. Under the truncated convention used by C, Java and JavaScript, -17 % 5 = -2, with quotient -3, because 5 x (-3) + (-2) = -17. Both are arithmetically correct; they just round the quotient in different directions.
Why do calculators disagree about the modulo of a negative number?
Because the division algorithm only pins down the remainder once you decide how to round the quotient. Rounding the quotient down (toward negative infinity) gives a remainder with the sign of the modulus, which is the floored convention. Rounding the quotient toward zero gives a remainder with the sign of the dividend, which is the truncated convention. This calculator shows both, plus the Euclidean result, which is never negative.
Is modulo the same as the remainder?
In everyday whole-number arithmetic with positive values, yes: 23 mod 5 and the remainder of 23 divided by 5 are both 3. The two ideas only come apart when a negative number is involved, where 'remainder' usually means the truncated result your programming language gives and 'modulo' often means the floored, non-negative result. That is why the calculator labels each one.
What is the difference between mod, modulo and modulus?
In practice all three are used for the same calculation. 'Modulo' names the operation, 'mod' is its shorthand as in a mod n, and 'modulus' is the number you divide by, the n in a mod n. Some sources also use 'modulus' as a synonym for the whole operation, which is why a mod calculator, a modulo calculator and a modulus calculator all do the same job.
Can the modulus be zero?
No. a mod 0 is undefined, because it would require dividing by zero. Enter any non-zero modulus instead. Most programming languages either throw an error or return a special not-a-number value when you try it, so this calculator blocks the input and tells you why.
Can you take the modulo of a decimal?
Yes. The same definition r = a - n x q works for decimals once you fix how the quotient is rounded. For 10.5 mod 3 the quotient is 3, so the remainder is 10.5 - 9 = 1.5. This calculator handles decimals and rounds the display to ten decimal places so binary floating-point noise does not show up.
What is the modulo used for in real life?
Anywhere something wraps around or repeats. Clocks use mod 12 and mod 24, minutes and seconds use mod 60, weekday arithmetic uses mod 7, even-or-odd tests use mod 2, and the Gregorian leap-year rule uses mod 4, mod 100 and mod 400. Programmers use it to cycle through arrays, spread keys across hash buckets, and compute check digits on account and ISBN numbers.
How do I check whether one number divides another?
Take the modulo. If a mod n = 0, then n divides a evenly and a is a multiple of n. For example, 1,234 mod 2 = 0, so 1,234 is even, while 1,234 mod 3 = 1, so it is not a multiple of 3. The result table on this page checks every modulus from 2 to 12 at once.
Why is the remainder always smaller than the modulus?
If the leftover were as large as the modulus, you could fit one more whole copy of the modulus into the dividend, so the quotient was too small. With a positive modulus n, the floored remainder therefore always lands between 0 and n minus 1. That fixed range is exactly what makes modulo useful for wrapping values around.
What is modular arithmetic?
Modular arithmetic is arithmetic on the remainders themselves, where two numbers count as the same if they leave the same remainder. Written 26 is congruent to 2 modulo 12, it says both land on 2 on a 12-hour clock. Addition, subtraction and multiplication all survive the wrap, which is why modular arithmetic underpins calendars, check digits and cryptography.
Does this modulo calculator handle very large numbers?
Yes. Whole-number inputs are evaluated with arbitrary-precision integer arithmetic, so a value with dozens of digits keeps every digit and the remainder is exact. For example, 1,000,000,007 mod 97 = 41. Decimal inputs fall back to standard floating-point arithmetic, which is precise to about 15 significant digits.
Is this modulo calculator free?
Yes. It is completely free, with no sign-up and no limit on how many calculations you can run. Change the dividend, the modulus or the sign convention as often as you like; the remainder, the quotient and the table of a mod 2 through 12 update instantly in your browser.
💡 Good to know
The remainder never gets bigger than the modulus
With a positive modulus n, every possible answer falls between 0 and n minus 1. That guarantee is what lets you use modulo to wrap a counter, pick a bucket or land on a clock face without ever checking the bounds yourself.
Adding the modulus changes nothing
23 mod 5, 28 mod 5 and 1,000,023 mod 5 all equal 3. Numbers that leave the same remainder are called congruent, and that single property is what makes modular arithmetic work for calendars, check digits and cryptography.
Modulo is the engine inside the Euclidean algorithm
To find the greatest common factor of two numbers, replace the larger with the remainder of dividing it by the smaller, and repeat until the remainder hits 0. The last non-zero value is the GCF, which is why one modulo key can solve a much bigger problem.