What is a Modulo Calculator?
A modulo calculator (or mod calculator) finds a mod n, the remainder left when a is divided by n, together with the whole-number quotient q, so that a = n × q + r. For example, 17 mod 5 = 2 because 17 = 5 × 3 + 2, and 1 mod 2 = 1 because 2 goes into 1 zero times with 1 left over. For positive numbers every method agrees. For negative numbers the floored, truncated and Euclidean conventions used by different languages disagree, so this calculator shows all three.
What the Modulo Calculator does
Enter a dividend and a divisor (positive, negative or decimal) and the calculator returns the remainder and quotient, the identity a = n × q + r with your numbers, and a table comparing the conventions used by Python, Excel, C, Java, JavaScript and number theory. It is also known as a mod calc, modulo calc, remainder calculator, modulus operator calculator or modular arithmetic calculator: they all compute the same remainder.
Modulo is the arithmetic of cycles: hours on a clock, days of the week, positions in a circular buffer, check digits on barcodes. It is also the place where programs most often disagree, because -17 % 5 is −2 in JavaScript but -17 % 5 is 3 in Python. Seeing both answers side by side tells you which one your code will produce.
How to use the Modulo Calculator
- Enter the Dividend, a, the number being divided.
- Enter the Divisor (modulus), n. It can be negative or a decimal, but not 0.
- Read a mod n (floored) and the quotient at the top; the table lists the truncated and Euclidean results too.
- Use the step-by-step solution to see how each quotient is rounded and to check that n × q + r gives back a.
How to find mod by hand
To find a mod n, divide, keep the whole-number part of the quotient, multiply it back and subtract. What is left over is the remainder. For 38 mod 7:
- Divide a by n: 38 / 7 = 5.43.
- Round the quotient down to a whole number: q = 5.
- Multiply back: 7 × 5 = 35.
- Subtract: r = 38 − 35 = 3. So 38 mod 7 = 3.
How to calculate modulo on a calculator
A standard calculator has no mod key, but the remainder takes only a division, a multiplication and a subtraction. Work out a ÷ n, note the whole-number part, then type a − n × (that whole number). For 38 mod 7: 38 ÷ 7 = 5.428…, and 38 − 7 × 5 = 3. Alternatively, multiply only the decimal part by n: 0.428571… × 7 = 3.
1234 mod 10: 1234 ÷ 10 = 123.4, so the whole part is 123 and 1234 − 10 × 123 = 4. Any whole number mod 10 is its last digit. 1 mod 3: 1 ÷ 3 = 0.333…, so the whole part is 0 and the remainder is the whole 1.
In Excel or Google Sheets, =MOD(38, 7) returns 3. In Python, C, Java and JavaScript, type 38 % 7. Take care with negative numbers, where those tools disagree (see below).
Modulo formula
All three conventions satisfy a = n × q + r; they differ only in how the quotient q is rounded.
| Symbol | Meaning |
|---|---|
| a | dividend, the number being divided |
| n | divisor or modulus (n ≠ 0) |
| q | integer quotient |
| r | remainder, with |r| < |n| |
| ⌊x⌋, trunc(x) | round down; round toward zero |
When n > 0 the floored and Euclidean remainders are identical, which is why mathematicians rarely distinguish them.
Sources: the Python language reference (% and // round down), MDN on the JavaScript remainder operator (% takes the sign of the dividend), and Microsoft’s MOD function page (MOD takes the sign of the divisor).
Worked example: a negative number, −17 mod 5
−17 mod 5 under all three conventions
Problem. Find −17 mod 5 under the floored, truncated and Euclidean conventions.
- 01−17 / 5 = −3.4.
- 02Floored: q = ⌊−3.4⌋ = −4, so r = −17 − 5 × (−4) = −17 + 20 = 3.
- 03Truncated: q = trunc(−3.4) = −3, so r = −17 − 5 × (−3) = −17 + 15 = −2.
- 04Euclidean: the remainder must satisfy 0 ≤ r < 5, giving r = 3 with q = −4.
- 05Check: 5 × (−4) + 3 = −17 and 5 × (−3) + (−2) = −17.
Answer. −17 mod 5 is 3 in mathematics, Python and Excel, but the % operator in C, Java and JavaScript returns −2. The two answers differ by exactly the divisor, 5.
Common mod results
These are the remainders people look up most often. All of them use positive numbers, so every convention gives the same answer. Type any other pair into the calculator above.
| Expression | Division | Quotient q | a mod n |
|---|---|---|---|
| 1 mod 2 | 1 = 2 × 0 + 1 | 0 | 1 |
| 2 mod 3 | 2 = 3 × 0 + 2 | 0 | 2 |
| 3 mod 4 | 3 = 4 × 0 + 3 | 0 | 3 |
| 2 mod 4 | 2 = 4 × 0 + 2 | 0 | 2 |
| 0 mod 3 | 0 = 3 × 0 + 0 | 0 | 0 |
| 4 mod 3 | 4 = 3 × 1 + 1 | 1 | 1 |
| 8 mod 3 | 8 = 3 × 2 + 2 | 2 | 2 |
| 10 mod 3 | 10 = 3 × 3 + 1 | 3 | 1 |
| 25 mod 3 | 25 = 3 × 8 + 1 | 8 | 1 |
| 6 mod 2 | 6 = 2 × 3 + 0 | 3 | 0 |
| 7 mod 4 | 7 = 4 × 1 + 3 | 1 | 3 |
| 12 mod 10 | 12 = 10 × 1 + 2 | 1 | 2 |
| 3 mod 10 | 3 = 10 × 0 + 3 | 0 | 3 |
| 17 mod 7 | 17 = 7 × 2 + 3 | 2 | 3 |
| 31 mod 7 | 31 = 7 × 4 + 3 | 4 | 3 |
| 123 mod 11 | 123 = 11 × 11 + 2 | 11 | 2 |
| 1234 mod 10 | 1234 = 10 × 123 + 4 | 123 | 4 |
When the dividend is smaller than the divisor
If 0 ≤ a < n, the divisor does not fit into the dividend even once, so the quotient is 0 and the whole dividend is left over: a mod n = a. That is why 1 mod 2 = 1, 2 mod 3 = 2, 2 mod 4 = 2, 3 mod 4 = 3, 5 mod 7 = 5 and 3 mod 10 = 3.
This only holds for non-negative dividends. With a negative dividend the floored answer wraps around: −1 mod 4 = 3, not −1, although the truncated % in C, Java and JavaScript still returns −1.
What a modulo of 0 means, and why a mod 0 is undefined
A remainder of 0 means n divides a exactly: 6 mod 2 = 0, 10 mod 5 = 0, and 0 mod n = 0 for any non-zero n. Any number mod 1 is also 0, because every whole number is a multiple of 1. Testing a mod n = 0 is the standard way to check divisibility, and a mod 2 = 0 is the test for an even number.
A divisor of 0 is a different matter. a mod 0 would require dividing by zero, so it has no standard value: Python raises ZeroDivisionError, Excel returns #DIV/0!, JavaScript returns NaN, and in C it is undefined behaviour. Some texts extend the definition so that a mod 0 = a, but this calculator treats a zero divisor as an error.
Modulo of negative numbers: why languages disagree
Integer division has to round a / n to a whole number, and rounding toward zero and rounding down are both reasonable choices. C, Java and JavaScript round toward zero, so the remainder keeps the sign of the dividend. Python and spreadsheets round down, so the remainder keeps the sign of the divisor, which is usually what you want for cyclic arithmetic such as wrapping an array index. This ambiguity is why "modulo" and "remainder" are sometimes treated as different operations.
If your language only offers the truncated %, you can get the floored result with ((a % n) + n) % n when n > 0. Java also has Math.floorMod and Rust has rem_euclid for the same purpose.
| Expression | Floored (Python, Excel) | Truncated (C, Java, JS %) | Euclidean |
|---|---|---|---|
| 17 mod 5 | 2 | 2 | 2 |
| −17 mod 5 | 3 | −2 | 3 |
| 17 mod −5 | −3 | 2 | 2 |
| −17 mod −5 | −2 | −2 | 3 |
| −23 mod 6 | 1 | −5 | 1 |
Modular arithmetic and congruence
Two numbers are congruent modulo n when they leave the same remainder: 17 ≡ 2 (mod 5), and 38 ≡ 3 (mod 7). Congruence works well with addition and multiplication, so you can reduce at every step and keep the numbers small: (a + b) mod n = ((a mod n) + (b mod n)) mod n, and the same holds for a × b.
That rule is what makes large powers tractable. For 2¹⁰ mod 7, note that 2³ = 8 ≡ 1 (mod 7), so 2¹⁰ = (2³)³ × 2 ≡ 1 × 2 = 2. Repeated squaring with reduction mod n is how RSA encryption and other public-key methods compute numbers hundreds of digits long.
In programming the operator is usually written with the percent symbol: a % n in C, Java, JavaScript and Python, MOD(a, n) in Excel, a %% n in R and a mod n in Pascal and Haskell.
Common use cases
- Clock and calendar arithmetic: 109 hours after midnight is 109 mod 24 = 13:00 on the fifth day, and 100 days after a Monday is a Wednesday because 100 mod 7 = 2.
- Divisibility and parity: a number is even exactly when n mod 2 = 0.
- Programming: wrapping indices in circular buffers, alternating row colors, and spreading items across a fixed number of buckets.
- Check digits: ISBN, IBAN and credit-card (Luhn) checks all reduce a weighted sum modulo 10, 11 or 97.
- Cryptography and number theory: modular exponentiation, congruences and the RSA algorithm.
Assumptions and limitations
- Inputs must be at most 9,007,199,254,740,991 in absolute value, the largest whole number a JavaScript double stores exactly.
- Decimal inputs with up to 12 decimal places are handled exactly by scaling to whole numbers; inputs with more decimal places use ordinary floating-point arithmetic.
- The divisor cannot be 0. Some systems define a mod 0 = a, but most treat it as an error, as this calculator does.
- This tool returns single remainders, not modular inverses or large modular powers. For counting arrangements in modular problems, see the Combination Calculator and Factorial Calculator.
Frequently asked questions
What does a mod n mean?
How do you find mod?
How do you calculate modulo on a calculator?
What is 1 mod 2?
What is the modulo of a negative number?
What is 5 mod 0?
Is modulo the same as remainder?
Can you take the modulo of a decimal number?
Cite this page
Statculator. (2026, November 14). Modulo Calculator. Retrieved November 14, 2026, from https://statculator.com/math/modulo-calculator/