Skip to main content

Online Calculators and Tools | Calculators Toolbox

Modulo Calculator

Home / Modulo Calculator
Modulo Calculator illustration showing a glowing analog clock face with numbers wrapping around in a circle, beside a division bracket with a small leftover cube

This modulo calculator finds a mod b, the remainder and quotient, including negative numbers and decimals.

Modulo Calculator

Calculation Explanation

Free tool by Modulo Calculator – CalculatorsToolbox

Modulo Calculator – Find a mod b and the Remainder

Our free modulo calculator finds a mod b, the remainder left over after division, along with the quotient. It handles negative numbers and decimals, and shows how the result differs between math and programming conventions.

What Is Modulo?

The modulo operation, written a mod b, gives the remainder when a is divided by b. If you share 17 cookies among 5 friends, each gets 3 and 2 are left over, so 17 mod 5 = 2. The number you divide (17) is the dividend, the number you divide by (5) is the divisor or modulus, and the answer (2) is the remainder.

Modulo is everywhere once you notice it. Clocks work in mod 12 (or mod 24), days of the week repeat in mod 7, and programmers use it constantly to cycle through lists, check whether numbers are even, and build hash tables and encryption.

How to Calculate a mod b

Divide, round the quotient down to a whole number, and subtract to find what's left.

a mod b = a − b × ⌊a ÷ b⌋

For 17 mod 5: 17 ÷ 5 = 3.4, which rounds down to 3. Then 5 × 3 = 15, and 17 − 15 = 2. The ⌊ ⌋ symbols mean "floor," or round down. This floor version always gives a result with the same sign as the divisor, which is the convention used in mathematics, Python and spreadsheet MOD functions.

Example Calculations:

17 mod 517 − 5 × 3 = 2
100 mod 7100 − 7 × 14 = 2
−17 mod 5−17 − 5 × (−4) = 3
7.5 mod 27.5 − 2 × 3 = 1.5

How to Use the Modulo Calculator

  1. Enter the dividend (a), the number being divided.
  2. Enter the divisor (b), the number you're dividing by. It can't be 0.
  3. The remainder appears instantly, along with the whole-number quotient.
  4. If either number is negative, you'll also see the truncated remainder that languages like C, Java and JavaScript return with the % operator.

Real-World Applications of Modulo

Telling Time

15 hours after 10 o'clock is (10 + 15) mod 12 = 1 o'clock. Converting 17:00 to 12-hour time is 17 mod 12 = 5 PM.

Days of the Week

If today is Monday, 100 days from now is 100 mod 7 = 2 days later, a Wednesday.

Programming

n % 2 === 0 checks for even numbers, and i % 3 === 0 runs code on every third item in a loop.

Check Digits

ISBN-10 and many ID numbers use mod 11 or mod 10 check digits to catch typing errors.

Cryptography

RSA and other encryption systems are built on modular arithmetic with very large numbers.

Rotations and Shifts

Assigning 23 tasks to 4 people in turn, the last task goes to person 23 mod 4 = 3.

Modulo With Negative Numbers

Floored Modulo (Math, Python, Excel)

The quotient is rounded down, so the remainder takes the sign of the divisor. With a positive divisor, the answer is always between 0 and b − 1.

Example: −17 mod 5 = 3, because −17 = 5 × (−4) + 3.

Truncated Remainder (C, C++, Java, JavaScript)

The quotient is rounded toward zero, so the remainder takes the sign of the dividend.

Example: −17 % 5 = −2, because −17 = 5 × (−3) + (−2).

Which One Should I Use?

For clock and calendar problems, and most math, use the floored version so results stay positive. When translating code between languages, check which convention each uses, because the same expression can give different answers.

Modulo With Decimals

The same formula works for decimals: 7.5 mod 2 = 1.5 and 10 mod 2.5 = 0. Spreadsheets and Python support this; some older languages only allow whole numbers.

Tips for Working With Modulo

  • a mod b is always smaller than b (for positive b). If you get something bigger, recheck the division.
  • If a is smaller than b and both are positive, a mod b is just a: 3 mod 10 = 3.
  • a mod b = 0 means b divides a exactly, which is a quick divisibility test.
  • Modulo distributes over addition: (a + b) mod n = ((a mod n) + (b mod n)) mod n.
  • In Excel and Google Sheets, use =MOD(a, b); in Python, a % b.
  • For even/odd checks only, the even or odd checker is even quicker.

Modulo Reference Table

ExpressionQuotientRemainder (floored)Truncated %
17 mod 5322
20 mod 4500
100 mod 71422
3 mod 10033
−17 mod 5−43−2
17 mod −5−4−32
25 mod 12211
7.5 mod 231.51.5

Step-by-Step Worked Example

New Year's Day falls on a Thursday. What day of the week is day 256 of the year?

  1. Day 256 is 255 days after day 1.
  2. Days of the week repeat every 7, so find 255 mod 7.
  3. 255 ÷ 7 = 36.43, which rounds down to 36. Then 7 × 36 = 252, and 255 − 252 = 3.
  4. Count 3 days forward from Thursday: Friday, Saturday, Sunday. Day 256 is a Sunday. (In a leap year the answer is the same, because the leap day comes after day 59 and doesn't change the count from day 1.)

Enter 255 and 7 into the modulo calculator to see the same quotient and remainder.

Modular Arithmetic: Clock Math

Modular arithmetic treats numbers as if they wrap around a circle, just like the hands of a clock. In mod 12, 13 is the same as 1, and 24 is the same as 0. Mathematicians write this as 13 ≡ 1 (mod 12), read as "13 is congruent to 1 modulo 12." You can add, subtract and multiply in modular arithmetic just like ordinary arithmetic, then take the remainder at the end. This idea, formalized by Carl Friedrich Gauss in 1801, now underpins computer science, digital signatures and secure online payments.

Modulo in Spreadsheets

Spreadsheets make modulo easy for everyday tasks. In Excel or Google Sheets, =MOD(A2, 7) gives the remainder of A2 divided by 7. Combine it with ROW() to shade every other row (=MOD(ROW(), 2) = 0) or to assign items to groups in rotation. Both programs use the floored convention, so =MOD(-17, 5) returns 3, matching the main result of this modulo calculator rather than the % operator in JavaScript. If you build formulas that must match code written in another language, test a negative example first so the two systems agree before you rely on the results across a whole sheet.

Why Use Our Modulo Calculator?

Remainders with negative numbers and decimals are easy to get wrong, and different tools disagree. Our modulo calculator gives the mathematical result, the quotient and, where it differs, the programming-language result, all with a clear explanation. It's great for programmers, students, puzzle solvers and anyone working with clocks, calendars or cycles.

Frequently Asked Questions

Quick answers to common questions related to Modulo Calculator are as under:-

What does mod mean in math?

Mod, short for modulo, gives the remainder after dividing one number by another. 17 mod 5 = 2 because 17 divided by 5 is 3 with 2 left over.

How do you calculate a mod b?

Divide a by b, round the quotient down to a whole number, multiply it by b and subtract the result from a. What remains is a mod b.

What is −17 mod 5?

In mathematics and Python, −17 mod 5 = 3. In C, Java and JavaScript, −17 % 5 returns −2 because those languages truncate toward zero.

What does it mean when a mod b equals 0?

It means b divides a exactly, with no remainder. For example, 20 mod 4 = 0, so 4 is a factor of 20.

Can modulo be used with decimals?

Yes. The same formula works, so 7.5 mod 2 = 1.5. Python, Excel and Google Sheets all support decimal modulo.

What is the difference between modulo and division?

Division gives the quotient, how many times b fits into a. Modulo gives the remainder, what is left over after that.

Latest from Our Blog

Explore helpful tips, updates, and guides on calculators, AI tools, and conversions.