Modulo Calculator
Find a mod b, the remainder of a division, with the quotient, the equation a = bq + r and step-by-step working, including negative numbers.
- Dividend (a)
- 17
- Divisor (b)
- 5
- Quotient (q)
- 3The whole number of times the divisor fits
- Remainder (r)
- 2What is left over; 0 ≤ r < |b|
- Division
- 17 ÷ 5 = 3 remainder 2
- Equation a = bq + r
- 17 = 5(3) + 2
- Modulo expression
- 17 mod 5 = 2
- Congruence
- 17 ≡ 2 (mod 5)17 and 2 leave the same remainder when divided by 5
Step-by-step calculation
Step 1: Divide 17 by 5
17 ÷ 5 = 3.4
Step 2: Take the integer quotient
For a positive divisor, round the result down (toward −∞) to the next whole number.
q = 3
Step 3: Multiply the divisor by the quotient
5 × 3 = 15
Step 4: Subtract from the dividend
17 − 15 = 2
Step 5: Result
Check: 0 ≤ 2 < 5, and 5 × 3 + 2 = 17.
17 mod 5 = 2
17 = 5(3) + 2
Modulo formula
a mod b = r
a = bq + r, 0 ≤ r < |b|
- a
- dividend, the number being divided
- b
- divisor, any non-zero integer
- q
- quotient, the whole number of times b fits into a
- r
- remainder, what is left over (the result of a mod b)
Quick reference
| Expression | Quotient | Remainder |
|---|---|---|
| 10 mod 3 | 3 | 1 |
| 15 mod 4 | 3 | 3 |
| 20 mod 5 | 4 | 0 |
| 23 mod 6 | 3 | 5 |
| 27 mod 24 | 1 | 3 |
| 11 mod 2 | 5 | 1 |
| −17 mod 5 | −4 | 3 |
All arithmetic is exact integer arithmetic, so even very large numbers give the right remainder. Related tools: the GCF Calculator (which uses repeated remainders in Euclid’s algorithm), the LCM Calculator, the Prime Number Calculator, the Prime Factorization Calculator and the Fraction Calculator for turning a remainder into a mixed number.
The modulo operation, written a mod b, gives the remainder left over when one whole number is divided by another. 17 mod 5 = 2, because 5 fits into 17 three whole times (15) and 2 is left over. This modulo calculator (also called a mod or remainder calculator) finds that remainder together with the quotient and the division equation 17 = 5(3) + 2.
Enter the dividend and divisor as whole numbers, positive or negative. Each answer shows the division, the integer quotient, the multiplication and subtraction steps, and a check that the result satisfies a = bq + r. Negative numbers follow the standard mathematical convention, with a remainder that is never negative, and the page explains how that differs from the % operator in programming languages. You can also work out a whole list of expressions at once.
Worked Calculation Examples
| Scenario | Result | Calculation Step |
|---|---|---|
| 17 mod 5 | 2 | 17 ÷ 5 = 3.4, so the quotient is 3. 5 × 3 = 15 and 17 − 15 = 2, so 17 ÷ 5 = 3 remainder 2 and 17 = 5(3) + 2. |
| 25 mod 7 | 4 | 7 fits into 25 three times (21), leaving 4: 25 = 7(3) + 4. |
| 20 mod 5 (exact division) | 0 | 5 divides 20 evenly: 20 = 5(4) + 0, so the remainder is 0. |
| 3 mod 10 (divisor larger than dividend) | 3 | 10 fits into 3 zero times, so the quotient is 0 and all of 3 is left over: 3 = 10(0) + 3. |
| −17 mod 5 (negative dividend) | 3 | −17 ÷ 5 = −3.4. Rounding down gives q = −4, and 5 × (−4) = −20, so r = −17 − (−20) = 3: −17 = 5(−4) + 3. A truncating % operator would give −2 instead. |
| 17 mod −5 (negative divisor) | 2 | With the remainder kept between 0 and |b| − 1 = 4: 17 = (−5)(−3) + 2, so the answer is 2. (Python and Excel give −3, because their remainder takes the sign of the divisor.) |
| Clock: 27 hours after midnight | 3:00 | 27 mod 24 = 3, because 27 = 24(1) + 3: one full day plus 3 hours. |
What Is Modulo?
Modulo is the remainder after division by whole numbers. To find a mod b, see how many whole times b fits into a (the quotient), then take what is left over (the remainder). "17 mod 5" is read "17 modulo 5", and its value is 2.
The quotient is the whole number of times the divisor fits: for 23 ÷ 4 it is 5, since 4 × 5 = 20. The remainder is the amount left after that: 23 − 20 = 3. So 23 = 4(5) + 3 and 23 mod 4 = 3. When the division comes out even, as in 20 ÷ 5 = 4, the remainder is 0, so 20 mod 5 = 0. When the divisor is bigger than the dividend, it fits 0 times and the whole dividend is left over: 3 mod 10 = 3, because 3 = 10(0) + 3.
Modulo vs Division
Ordinary division gives one number, possibly with a decimal: 17 ÷ 5 = 3.4. Integer division splits the same problem into two whole numbers: a quotient of 3 and a remainder of 2. Modulo returns just the remainder, 2.
Don't confuse the decimal part with the remainder. The .4 in 3.4 is the remainder divided by the divisor (2 ÷ 5 = 0.4), not the remainder itself. To get the remainder from a decimal result, multiply the decimal part by the divisor: 0.4 × 5 = 2.
Modulo vs Remainder With Negative Numbers
For positive numbers, "modulo" and "remainder" mean the same thing. With negative numbers, different conventions give different answers. In mathematics, the remainder is usually required to be non-negative: −17 mod 5 = 3, because −17 = 5(−4) + 3, and 3 is between 0 and 4.
Many programming languages define % differently. JavaScript, C and Java truncate the quotient toward zero, so −17 % 5 gives −2 (−17 = 5(−3) − 2). Python and spreadsheet MOD functions take the sign of the divisor instead, so 17 mod −5 is −3 there. Every one of these answers satisfies a = bq + r; they only disagree about which q to choose. This calculator always uses the mathematical (Euclidean) convention, 0 ≤ r < |b|, and shows the other results when an input is negative.
Modular Arithmetic
Modular arithmetic is arithmetic in which numbers wrap around after reaching a fixed value, the modulus. We write a ≡ b (mod n), read "a is congruent to b modulo n", when a and b leave the same remainder after division by n; equivalently, n divides a − b.
For example, 17 ≡ 2 (mod 5), because 17 mod 5 = 2 and 2 mod 5 = 2. Likewise 17 ≡ 7 (mod 5), since both leave remainder 2, and 17 − 7 = 10 is a multiple of 5. Sums and products can be reduced as you go: (17 + 8) mod 5 = (2 + 3) mod 5 = 0. This idea underlies number theory, check digits and modern cryptography.
Real-World Uses of Modulo
Clock arithmetic: a 24-hour clock works modulo 24, so 27 hours after midnight is 27 mod 24 = 3, or 3:00; 10 hours after 20:00 is (20 + 10) mod 24 = 6:00. Calendars work modulo 7: 100 days after a Monday is 100 mod 7 = 2 days further on, a Wednesday.
Repeating patterns and scheduling: to rotate among 4 teams, item n goes to team n mod 4; striped table rows alternate with row mod 2. Programming and computer science use modulo to wrap array indexes, build hash tables (key mod table size) and generate pseudo-random numbers. Cryptography, including RSA, relies on arithmetic with very large numbers modulo a secret modulus, and check digits on ISBNs and bank account numbers use mod 11 or mod 97.
Odd and Even Numbers
Modulo 2 is the simplest test there is. A whole number n is even when n mod 2 = 0 and odd when n mod 2 = 1. For example, 10 mod 2 = 0, so 10 is even, and 11 mod 2 = 1, so 11 is odd.
With the mathematical convention this also works for negative numbers: −7 mod 2 = 1, so −7 is odd. (With a truncating % operator, −7 % 2 gives −1, which is why code often tests n % 2 !== 0 for odd numbers rather than n % 2 === 1.) The same idea extends to divisibility in general: n is divisible by k exactly when n mod k = 0.
How to Use the Modulo Calculator
- Enter the dividend (the number being divided) and the divisor (the number you divide by). Both must be whole numbers; negative numbers are allowed, but the divisor cannot be 0.
- Read the remainder, which is the answer to a mod b, together with the quotient and the division equation a = bq + r.
- Follow the steps: divide, take the whole-number quotient, multiply it by the divisor, and subtract that from the dividend.
- With negative numbers, the calculator uses the mathematical convention, so the remainder is never negative, and it shows what the floored (Python, Excel) and truncated (JavaScript, C) conventions would give.
- Switch to “Several at once” to work out a list of expressions such as 10 mod 3 and 17 mod 5 together, one per line.
Frequently Asked Questions
What is modulo?
Modulo is the remainder left after dividing one whole number by another. 17 mod 5 = 2, because 5 fits into 17 three times (15) with 2 left over.
What does mod mean?
“Mod” is short for modulo. “a mod b” means the remainder when a is divided by b, and “a ≡ c (mod b)” means a and c leave the same remainder when divided by b.
How do you calculate a modulo?
Divide a by b and take the whole-number quotient q (rounding down for a positive divisor). Multiply b × q and subtract it from a: the result is the remainder. For 17 mod 5: q = 3, 5 × 3 = 15, 17 − 15 = 2.
What is the difference between modulo and division?
Division gives the full quotient, 17 ÷ 5 = 3.4. Modulo gives only the whole-number remainder, 17 mod 5 = 2. The decimal .4 is the remainder divided by the divisor (2 ÷ 5), not the remainder itself.
What is the remainder of 17 divided by 5?
2. 5 goes into 17 three whole times, making 15, and 17 − 15 = 2, so 17 = 5(3) + 2.
What happens when the divisor is larger than the dividend?
For a non-negative dividend, the quotient is 0 and the remainder is the dividend itself: 3 mod 10 = 3, because 3 = 10(0) + 3.
What is 20 mod 5?
0. 5 divides 20 exactly four times, so nothing is left over: 20 = 5(4) + 0.
Can modulo be negative?
In the mathematical convention used here, no: the remainder is always between 0 and |b| − 1. Some programming languages return negative results, for example −17 % 5 = −2 in JavaScript, C and Java.
What is -17 mod 5?
3, because −17 = 5(−4) + 3 and 3 is between 0 and 4. A truncating % operator gives −2 instead, from −17 = 5(−3) − 2.
What happens when you divide by zero in modulo?
It is undefined. The remainder would have to satisfy 0 ≤ r < 0, which no number does, and 0 × q is always 0, so a mod 0 has no answer. The calculator asks for a non-zero divisor instead.
How is modulo used in programming?
Through the % operator or a mod function: to test even and odd numbers (n % 2), wrap values around a range (index % length), cycle through repeating patterns, build hash tables and convert units such as seconds into minutes and seconds. Watch out for negative operands, where languages differ.
How is modulo used in modular arithmetic?
Modular arithmetic works with remainders only: a ≡ b (mod n) when a and b have the same remainder mod n. Clock times, days of the week, check digits and cryptography such as RSA are all built on it.
How can modulo determine whether a number is odd or even?
Take n mod 2. If the result is 0, n is even; if it is 1, n is odd. For example, 10 mod 2 = 0 (even) and 11 mod 2 = 1 (odd).
Related Calculators
GCF Calculator
Find the greatest common factor of two or more whole numbers, with verification, Euclidean algorithm steps, common factors, and prime factorization.
LCM Calculator
Find the least common multiple of two or more whole numbers, with verification, GCD steps, and the prime factorization method.
Prime Number Calculator
Check whether a whole number is prime or composite, list its factors and prime factorization, and find the nearest primes.
Prime Factorization Calculator
Find the prime factors of a number with step-by-step division, exponent form, a factor tree, factor pairs and a check of the answer.
Fraction Calculator
Add, subtract, multiply, and divide fractions.
Scientific Calculator
Advanced math calculator supporting trigonometry, logs, exponentials, and roots.
Last updated: September 27, 2026.