What this calculator does
Find the remainder left over when you divide one number by another. That's what the modulo (or "mod") operation gives you. For example, 17 mod 5 = 2, because 5 goes into 17 three times (15) with 2 left over. It's the math behind clocks and calendars, and checking whether a number is even. It also helps with splitting items into groups, cycling through lists, and check digits (checksums) like those on barcodes and bank numbers.
For positive numbers, everyone agrees on the answer. For negative numbers, there are three common rules, and different programming languages and textbooks use different ones. Enter the number being divided (a) and the number you divide by (n), and pick a rule. The calculator gives the remainder and the quotient (how many whole times n fits). It checks that a = q × n + r, and shows all three rules side by side so you can see when they differ.
Where it's used
Why this math matters outside the classroom:
- Clock time. Seventy hours after 9:00 is (9 + 70) mod 24 = 7, so a 24-hour clock reads 7:00.
- Days of the week. A date 100 days after a Monday falls 100 mod 7 = 2 days later in the week, on a Wednesday.
- Even or odd. Programmers test n mod 2, where a remainder of 0 means n is even and 1 means it is odd.
- Leftover eggs. Packing 250 eggs into cartons of 12 leaves 250 mod 12 = 10 eggs over.
- Check digits. An ISBN-10 is valid when a weighted sum of its digits leaves a remainder of 0 when divided by 11.
Grade level and standards: Grades 4–6; Common Core State Standards for Mathematics 4.NBT.B.6, 5.NBT.B.6. © Copyright 2010. National Governors Association Center for Best Practices and Council of Chief State School Officers. All rights reserved.
How to use it
- Enter the dividend a, the number being divided.
- Enter the divisor n, also called the modulus. It can be any number except 0.
- Choose the rule (convention) for negative numbers. Floored is the default, and it matches most spreadsheets and Python.
- Read the remainder at the top, the quotient beneath it, and the table comparing all three rules.
What the inputs mean
- Dividend (a)
- Any number, including negatives and decimals such as 7.5. Decimals are handled exactly as typed, so 0.3 mod 0.1 really is 0.
- Divisor, or modulus (n)
- Any number except zero. Its sign (plus or minus) matters for the floored rule, but the Euclidean remainder ignores it.
- Convention for negative numbers
- Truncated rounds a ÷ n toward zero, so the remainder has the same sign as a. That's how the % operator works in C, C++, Java, C# and JavaScript. Floored rounds a ÷ n down, so the remainder has the same sign as n. That matches % in Python and the MOD function in common spreadsheets. Euclidean always gives a remainder from 0 up to |n| (n without its sign). It's the usual choice in number theory.
Formula and method
a = q × n + r truncated: q = trunc(a ÷ n), r = a − n × q floored: q = ⌊a ÷ n⌋, r = a − n × q Euclidean: q = sign(n) × ⌊a ÷ |n|⌋, so 0 ≤ r < |n|
In the formulas, a is the number being divided, n is the divisor, q is the quotient (a whole number) and r is the remainder. trunc means "chop off the decimal part". The ⌊ ⌋ brackets mean "round down". |n| is n without its sign, and sign(n) is plus or minus, matching n.
Every rule writes a as a whole number q of n's, plus a remainder r that's smaller in size than n. They differ only in which whole number q they pick. That choice matters when a ÷ n is negative or falls between two whole numbers. Once q is chosen, the remainder is r = a − n × q.
Take −17 and 5. The exact quotient is −3.4. Truncating gives q = −3 and r = −17 − (−15) = −2. Flooring gives q = −4 and r = −17 − (−20) = 3. The Euclidean rule agrees with flooring here because n is positive. But for 17 mod −5, floored gives −3 while Euclidean gives 2.
All the math is done on exact decimals, not the binary approximations computers often use. So results like 5.5 mod 2.5 = 0.5 come out exactly, with no stray digits such as 0.49999999999999.
Worked example
Find 17 mod 5.
- Divide: 17 ÷ 5 = 3.4.
- Take the whole-number part: q = 3. Because both numbers are positive, all three rules agree.
- Subtract: r = 17 − 3 × 5 = 2.
Result: 17 mod 5 = 2, with quotient 3, and 17 = 3 × 5 + 2. Changing a to −17 gives a remainder of 3 (floored and Euclidean) or −2 (truncated).
Understanding the result
A remainder of 0 means n divides a exactly, so a is a multiple of n. For example, a mod 2 = 0 means a is even.
With the floored and Euclidean rules and a positive n, the remainder is always between 0 and n − 1. That's just what clock math needs. Say the hour hand points at 12. After 109 hours, it points at 109 mod 12 = 1.
If your code gives a different answer from a textbook for negative numbers, check the table of rules. Your programming language is probably using truncation.
Assumptions and limitations
- The divisor isn't zero. Inputs are treated as the exact decimals you type.
- The quotient must stay within about ±9 × 10^15. Extreme ratios such as 10^300 mod 10^−300 are rejected.
- Modular inverses, powers mod n and systems of congruences are separate problems, and they aren't covered here.
Frequently asked questions
Is the remainder the same as the modulo?
For positive numbers, yes. For negatives, "remainder" often means the truncated result, where the sign follows a. "Modulo" often means the floored or Euclidean result, which is never negative when n is positive. Some languages even offer both, under names like rem and mod.
What does a mod n give when a is smaller than n?
For 0 ≤ a < n, the quotient is 0 and the remainder is a itself. For example, 3 mod 7 = 3.
Can the modulus be a decimal?
Yes. The rule a = q × n + r works for any n except zero, as long as q is a whole number. So 7.5 mod 2 = 1.5, because 7.5 = 3 × 2 + 1.5. This is handy for wrapping angles, for example turning 370.5° into 10.5° with modulo 360.
Why does −1 mod 12 equal 11?
With the floored and Euclidean rules, the quotient rounds down to −1, so r = −1 − (−1 × 12) = 11. On a clock, one hour before 12 o'clock is 11 o'clock. That's why this rule suits things that go round in cycles.
How this calculator is checked
Method: Division algorithm a = qn + r with truncated, floored (Knuth) and Euclidean (Boute) choices of q, computed on exact decimals. The calculation is covered by automated tests with known reference values and edge cases. Last updated 2026-10-18. Found a problem? Tell us.
Embed this calculator
Put this Modulo Calculator on your own website or blog for free. Paste this code where you want it to appear: