How to use the modulo calculator
- Enter the number a, the dividend. It can be negative, a decimal, or a whole number of any length.
- Enter the modulus n, the divisor. It can’t be 0.
- Read the result. The large figure is a mod n in the floored convention used in mathematics, Python and spreadsheets. The cards show the truncated and Euclidean results, the quotient for each, and whether n divides a evenly.
The calculator opens on 17 mod 5. Since 17 = 5 × 3 + 2, the answer is 2.
What modulo means
Dividing a by n gives a quotient q and a remainder r that satisfy
“a mod n” is that remainder. With positive numbers it is the familiar remainder from long division: 17 ÷ 5 = 3 R2, so 17 mod 5 = 2. The remainder is smaller than the divisor, so for n = 5 the possible results are 0, 1, 2, 3 and 4.
If a mod n = 0, n divides a evenly: 20 mod 5 = 0, so 20 is a multiple of 5. That is the usual way to test for divisibility and, with n = 2, for even and odd numbers.
Negative numbers: three conventions
The equation a = n × q + r doesn’t fix q and r on its own when a or n is negative. The conventions differ in how they round the quotient:
| Convention | Quotient | −17 mod 5 | 17 mod −5 |
|---|---|---|---|
| Floored | Rounded down | 3 | −3 |
| Truncated | Rounded toward 0 | −2 | 2 |
| Euclidean | Chosen so r ≥ 0 | 3 | 2 |
- Floored gives the remainder the sign of the divisor. The Python language reference says its % yields a result with the same sign as its second operand, and that x == (x // y) × y + (x % y). Spreadsheet MOD functions work the same way.
- Truncated gives the remainder the sign of the dividend. MDN’s reference for JavaScript’s % says the result takes the sign of the dividend, so −13 % 5 is −3 in JavaScript. C, C++ and Java behave the same way. That is why JavaScript calls % the remainder operator rather than modulo.
- Euclidean keeps the remainder between 0 and |n| − 1 whatever the signs, which is what number theory usually means by the residue of a modulo n.
All three agree whenever a and n are both positive. Check −17 mod 5 in each: floored, −17 = 5 × (−4) + 3; truncated, −17 = 5 × (−3) + (−2).
Clock arithmetic and calendars
Modulo describes anything that wraps around. On a 12-hour clock, 27 hours after midnight is 27 mod 12 = 3 o’clock. Days of the week repeat every 7: 100 days from a Monday is 100 mod 7 = 2 days later in the week, a Wednesday. Load “100 days from now” to see it.
Going backward works with the floored or Euclidean result. Five hours before 2 o’clock is (2 − 5) mod 12 = −3 mod 12 = 9 o’clock. The truncated convention would give −3, which isn’t a clock position; this is a common bug when programmers port such code to JavaScript or C and use % directly.
Congruence
Two numbers are congruent modulo n when they leave the same remainder, written a ≡ b (mod n). 17 ≡ 2 (mod 5) and 22 ≡ 2 (mod 5), so 17 ≡ 22 (mod 5). Equivalently, n divides their difference: 22 − 17 = 5.
Congruences can be added and multiplied like equations, which makes remainders of huge numbers easy to find by hand. The last digit of a whole number is its value mod 10, and a number is divisible by 9 exactly when its digit sum is, because 10 ≡ 1 (mod 9).
Decimals and very large numbers
Modulo works with decimals too: 5.5 mod 2 = 1.5, since 5.5 = 2 × 2 + 1.5. Python’s reference gives the example 3.14 % 0.7 = 0.34. Decimal results are rounded to 12 decimal places to hide floating-point noise.
Whole numbers are handled exactly, however long they are. 123456789012345678901234567890 mod 97 comes out exactly, which matters in checksums: the international bank account number (IBAN) check, for example, rests on a large number mod 97.
Rules that make mod easy
Remainders can be taken before or after adding and multiplying, and the result is the same:
- Sums: (a + b) mod n = ((a mod n) + (b mod n)) mod n. For example, (38 + 47) mod 10 = (8 + 7) mod 10 = 5.
- Products: (a × b) mod n = ((a mod n) × (b mod n)) mod n. So 38 × 47 ends in the same digit as 8 × 7 = 56: a 6.
- Powers: reduce as you go. To find 7¹⁰⁰ mod 5, note 7 ≡ 2 (mod 5) and 2⁴ = 16 ≡ 1 (mod 5). Since 100 = 4 × 25, 7¹⁰⁰ ≡ (2⁴)²⁵ ≡ 1 (mod 5).
These rules are why remainders of enormous numbers can be found without ever writing the numbers out.
Even, odd and repeating patterns
a mod 2 is 0 for even numbers and 1 for odd ones, using the floored or Euclidean result. With the truncated convention, a negative odd number gives −1, so code that tests “x % 2 == 1” misses negative odd numbers in JavaScript or C; testing “x % 2 != 0” works in every convention.
More generally, i mod n cycles through 0, 1, …, n − 1 as i counts up. That makes it handy for anything that repeats: alternating row colors (row mod 2), putting items into n columns (item mod n gives the column), rotating through a list of names, or wrapping an index back to the start of a list.
Starting from Monday, November 2, 2026, “100 days from now” lands 100 mod 7 = 2 weekdays later: Wednesday, February 10, 2027.
A divisibility shortcut for 11
Because 10 ≡ −1 (mod 11), the powers of 10 alternate between 1 and −1 modulo 11. So a whole number is divisible by 11 exactly when the alternating sum of its digits, starting from the right, is. For 918,082: 2 − 8 + 0 − 8 + 1 − 9 = −22, a multiple of 11, so 918,082 mod 11 = 0. Indeed, 918,082 = 11 × 83,462. Enter it in the calculator to confirm that the “Divisible?” card says Yes.
Sources & assumptions
How this calculator gets its numbers. Full method: our methodology.
- a = n × q + r in every convention; they differ in how q is rounded.
- Floored: q rounded down, r has the sign of n (Python, spreadsheets). Truncated: q rounded toward 0, r has the sign of a (JavaScript, C, Java).
- Euclidean: r is from 0 up to |n|. Whole numbers are computed exactly at any size.
Sources
- Python Software Foundation, The Python Language Reference, 6.7 Binary arithmetic operations. Python’s % yields a result with the same sign as the second operand, and x == (x // y) * y + (x % y).
- MDN Web Docs (Mozilla), Remainder (%). JavaScript’s % takes the sign of the dividend, unlike the modulo used in mathematics.
Last reviewed . For the full long-division steps, use the long division calculator.
Frequently asked questions
What does mod mean in math?
a mod n is the remainder when a is divided by n. For example, 17 mod 5 = 2 because 17 = 5 × 3 + 2.
What is −17 mod 5?
3 in the floored and Euclidean conventions (Python, Excel, number theory), and −2 in the truncated convention used by JavaScript, C and Java.
Is modulo the same as remainder?
For positive numbers, yes. With negatives, “remainder” often means the truncated result and “modulo” the floored or Euclidean one.
How do I calculate mod by hand?
Divide, round the quotient down to a whole number, multiply it by n and subtract from a. For 47 mod 6: 47 ÷ 6 ≈ 7.83, 7 × 6 = 42, and 47 − 42 = 5.
What is anything mod 1?
For whole numbers, 0, since 1 divides every whole number. For decimals, it is the fractional part in the floored convention.
Can the modulus be 0?
No. Division by zero is undefined, so a mod 0 has no value.