Modulo Calculator
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free modulo calculator. Find a mod n and the quotient, with the three conventions programming languages use for negative numbers, for numbers of any size.
- Floored (Python, Excel MOD)
- 0
- Truncated (JavaScript, C, Java %)
- 0
- Euclidean (always ≥ 0)
- 0
- Quotient (truncated)
- 0
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the modulo calculator
- Enter the number (a), the value being divided.
- Enter the divisor (n), also called the modulus.
- Read the results. The modulo calculator shows a mod n under the three conventions in use, plus the quotient.
Whole numbers of any size are handled exactly, so a 30-digit number mod 97 is computed digit for digit. Decimals work too.
What modulo means
The modulo operation gives the remainder after division. 17 mod 5 = 2, because 17 = 3 × 5 + 2. In general:
a = n × q + r
where q is the quotient and r is the remainder.
For positive numbers, everyone agrees on the answer. With negative numbers, there are three different conventions, and programming languages disagree. That's the most common source of modulo bugs, and why the modulo calculator shows all three.
The three conventions
Take −7 mod 3.
Truncated (rounds the quotient towards zero). −7 ÷ 3 = −2.33, truncated to −2. Remainder = −7 − (3 × −2) = −1. The result has the sign of the number (a). This is what the % operator does in JavaScript, C, C++, Java, C#, Go, Rust and Swift.
Floored (rounds the quotient down). −7 ÷ 3 rounded down is −3. Remainder = −7 − (3 × −3) = 2. The result has the sign of the divisor (n). This is what Python's %, Ruby's %, Excel's MOD and Google Sheets' MOD do, and what most mathematicians mean by "mod".
Euclidean (always non-negative). The remainder is always between 0 and |n| − 1. For −7 mod 3, it's 2. For 7 mod −3, it's 1 (where floored would give −2). This is the convention in number theory and in some languages, such as Dart's % operator.
For positive a and positive n, all three agree.
Why the difference matters
Suppose you want to wrap around a list or a clock:
- In Python, (index − 1) % length always gives a valid index, even when index is 0.
- In JavaScript, (0 − 1) % 5 = −1, which isn't a valid index. The usual fix is ((x % n) + n) % n, which gives the floored (and here Euclidean) result.
Likewise, checking whether a number is odd with x % 2 === 1 fails for negative odd numbers in JavaScript (−3 % 2 is −1). Use x % 2 !== 0 instead.
Everyday uses of modulo
- Clocks: 15:00 is 3 pm because 15 mod 12 = 3. 10 hours after 9 o'clock is (9 + 10) mod 12 = 7. For 24-hour times, the military time converter helps.
- Days of the week: 100 days after a Monday is (100 mod 7) = 2 days after Monday, a Wednesday. The day of the week calculator does this for any date.
- Even and odd: n mod 2 is 0 for even numbers.
- Repeating patterns: alternating table row colours with i mod 2, cycling through colours with i mod 5.
- Check digits: ISBNs, IBANs and card numbers use modulo arithmetic to catch typing mistakes. The IBAN validator uses mod 97, and the credit card validator uses a mod 10 check.
- Hashing and sharding: spreading items across n buckets or servers with hash mod n.
- Converting units: 135 minutes is 135 ÷ 60 = 2 hours, with 135 mod 60 = 15 minutes left.
Modular arithmetic
Modulo is the basis of modular arithmetic, "clock arithmetic", where numbers wrap around after reaching the modulus. Two numbers are congruent mod n if they have the same remainder: 17 ≡ 2 (mod 5).
Useful properties:
- (a + b) mod n = ((a mod n) + (b mod n)) mod n
- (a × b) mod n = ((a mod n) × (b mod n)) mod n
These let you work with huge numbers by reducing them as you go. They power modern cryptography, such as RSA, which relies on raising large numbers to powers mod a huge n.
Modulo with decimals
Modulo also works for decimals: 5.5 mod 2 = 1.5, because 5.5 = 2 × 2 + 1.5. It's useful for angles (wrap any angle into 0° to 360° with angle mod 360) and for time. Because of floating-point rounding, decimal results are rounded to 15 significant figures. For whole numbers, the modulo calculator uses exact integer arithmetic.
Quotient and remainder
The quotient shown is the truncated quotient (the whole-number part of the division, rounded towards zero), which pairs with the truncated remainder. The floored quotient pairs with the floored remainder. In both cases, quotient × divisor + remainder gives back the original number.
Tips
- Know your language's convention before relying on % with negative numbers.
- To force a non-negative result in C-style languages, use ((a % n) + n) % n.
- Dividing by zero isn't defined, so the modulo calculator asks for a non-zero divisor.
- For number bases (binary, hexadecimal), see the number base converter.
Privacy and accuracy
Your numbers stay in your browser. The modulo calculator uses exact big-integer arithmetic for whole numbers and standard floating-point for decimals, applying each convention's definition precisely, with no AI involved. Programmers, students, cryptography learners and puzzle fans use it free on any device.
Modulo in spreadsheets
- Excel and Google Sheets: =MOD(-7, 3) returns 2 (floored), matching Python.
- Excel: =MOD(7, -3) returns −2, taking the sign of the divisor.
If your spreadsheet results don't match your code, the convention is almost always the reason, and the modulo calculator shows both.
Checking divisibility
A number is divisible by n exactly when a mod n = 0. That makes modulo the standard way to test for multiples in code: "every 3rd row", "FizzBuzz" (divisible by 3, 5 or both), or "is this year divisible by 4" in leap-year rules. For leap years, a year is a leap year if it's divisible by 4, except years divisible by 100, unless also divisible by 400. So 2000 was a leap year and 1900 wasn't.
Large numbers
Big numbers, such as account numbers or cryptographic values, can't be stored exactly as ordinary floating-point numbers once they pass 16 digits. The modulo calculator uses exact big-integer arithmetic for whole numbers, so a 30-digit number mod 97 is exact. That's the same calculation used to validate IBANs.
Quick reference
- Dividend (a): the number being divided.
- Divisor (n), modulus: what you divide by.
- Quotient: how many whole times n fits into a.
- Remainder: what's left over.
- Truncated: sign follows a (JavaScript, C, Java).
- Floored: sign follows n (Python, Excel).
- Euclidean: never negative.
The modulo calculator shows all three, so you can match whichever language or tool you're using.
Modulo in scheduling and rotas
Modulo is ideal for anything that repeats in cycles. To work out which of three shifts a person is on in week 17 of a rotating rota, calculate 17 mod 3 = 2, so they're on the second shift pattern of the cycle (counting from 0, or the third if you count from 1). To find which day of a 14-day bin collection cycle a date falls on, take the number of days since a known collection day, mod 14. To rotate a list of five team members through a weekly task, week n goes to person n mod 5. The modulo calculator makes each of these quick and exact.
Checking your answer
For any convention, quotient × divisor + remainder should give back the original number. For −7 and 3 with the floored convention: −3 × 3 + 2 = −7.
A worked example
A developer is porting code from Python to JavaScript, and a carousel breaks when the user clicks "previous" on the first slide. In Python, (0 − 1) % 5 gave 4; in JavaScript it gives −1.
She enters −1 and 5 into the modulo calculator. The floored result (Python) is 4, the truncated result (JavaScript %) is −1, and the Euclidean result is 4. That confirms the bug, and she replaces index % length with ((index % length) + length) % length.
To check the day-of-week logic in the same app, she enters 1000 mod 7: the answer is 6, so 1,000 days after a Monday is a Sunday.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. That is the whole job of DeepRit: a PPC-only agency that sets up and runs Google Ads accounts so every click is accounted for. You keep full ownership of your account, get a written report every week, and can stop at any time. See our pricing or ask for a free audit.
Frequently asked questions
What is modulo?
The remainder after division. 17 mod 5 = 2. The modulo calculator also handles negative numbers under each convention.
What is −7 mod 3?
2 in Python, Excel and mathematics (floored); −1 in JavaScript, C and Java (truncated).
Why does JavaScript give negative remainders?
Its % operator truncates towards zero, so the result has the sign of the number being divided.
How do I get a positive modulo in JavaScript?
Use ((a % n) + n) % n.
What is the difference between mod and remainder?
Many people use them interchangeably, but strictly, "remainder" often means the truncated result and "mod" the floored or Euclidean one.
Is the modulo calculator free?
Yes, completely free, with no sign-up.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.