Skip to content
Statculator
Math & Percentages

Modulo Calculator (Mod Calculator)

Free mod calculator: find a mod n, the remainder and quotient, with steps. Handles negative and decimal numbers as Python, Excel, C, Java and JavaScript do.

Free, no sign-up Runs in your browserBy Hira Noor, BS MathematicsUpdated

Try

The number being divided. Negative and decimal values are allowed.

Results

17 mod 5
2
Floored remainder (mathematics, Python, Excel)
Quotient, q = ⌊a / n⌋
3
Truncated remainder (C, Java, JavaScript %)
2
Euclidean remainder (always ≥ 0)
2
Truncated quotient, trunc(a / n)
3
Euclidean quotient
3
Exact quotient, a / n
3.4
Is 17 divisible by 5?
No

Interpretation: 17 = 5 × 3 + 2: dividing 17 by 5 gives 3 whole times with 2 left over (floored convention). All three conventions agree here because neither number is negative, or the division is exact.

Results under each convention

ConventionUsed byQuotient qRemainder rCheck: n × q + r
FlooredPython %, Excel and Google Sheets MOD, R %%, Ruby %, Java Math.floorMod325 × 3 + 2 = 17
TruncatedC and C++ %, Java %, JavaScript %, C# %, Go %, SQL MOD, Python math.fmod325 × 3 + 2 = 17
EuclideanNumber theory, Rust rem_euclid325 × 3 + 2 = 17

Floored remainders take the sign of the divisor, truncated remainders the sign of the dividend, and Euclidean remainders are never negative.

Step-by-step solution

  1. 1

    Divide a by n

    a / n = 17 / 5 = 3.4
  2. 2

    Floored convention: round the quotient down

    Take the largest integer not greater than a / n, then subtract n × q from a.

    q = ⌊3.4⌋ = 3
    r = a − n × q = 17 − 5 × 3 = 2
  3. 3

    Truncated convention: drop the fractional part

    Round the quotient toward zero instead of down. This only differs from the floored result when a / n is negative and not a whole number.

    q = trunc(3.4) = 3
    r = 17 − 5 × 3 = 2
  4. 4

    Euclidean convention: keep the remainder non-negative

    Choose q so that 0 ≤ r < |n| = 5.

    q = 3, r = 17 − 5 × 3 = 2
  5. 5

    Check the division identity a = n × q + r

    5 × 3 + 2 = 17
    5 × 3 + 2 = 17
    5 × 3 + 2 = 17

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

  1. Enter the Dividend, a, the number being divided.
  2. Enter the Divisor (modulus), n. It can be negative or a decimal, but not 0.
  3. Read a mod n (floored) and the quotient at the top; the table lists the truncated and Euclidean results too.
  4. 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:

  1. Divide a by n: 38 / 7 = 5.43.
  2. Round the quotient down to a whole number: q = 5.
  3. Multiply back: 7 × 5 = 35.
  4. 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.

Floored (sign of the divisor)
q = ⌊a / n⌋, r = a − n·⌊a / n⌋
Truncated (sign of the dividend)
q = trunc(a / n), r = a − n·trunc(a / n)
Euclidean (never negative)
0 ≤ r < |n|, q = (a − r) / n
Formula symbols
SymbolMeaning
adividend, the number being divided
ndivisor or modulus (n ≠ 0)
qinteger quotient
rremainder, 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.

  1. 01−17 / 5 = −3.4.
  2. 02Floored: q = ⌊−3.4⌋ = −4, so r = −17 − 5 × (−4) = −17 + 20 = 3.
  3. 03Truncated: q = trunc(−3.4) = −3, so r = −17 − 5 × (−3) = −17 + 15 = −2.
  4. 04Euclidean: the remainder must satisfy 0 ≤ r < 5, giving r = 3 with q = −4.
  5. 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.

ExpressionDivisionQuotient qa mod n
1 mod 21 = 2 × 0 + 101
2 mod 32 = 3 × 0 + 202
3 mod 43 = 4 × 0 + 303
2 mod 42 = 4 × 0 + 202
0 mod 30 = 3 × 0 + 000
4 mod 34 = 3 × 1 + 111
8 mod 38 = 3 × 2 + 222
10 mod 310 = 3 × 3 + 131
25 mod 325 = 3 × 8 + 181
6 mod 26 = 2 × 3 + 030
7 mod 47 = 4 × 1 + 313
12 mod 1012 = 10 × 1 + 212
3 mod 103 = 10 × 0 + 303
17 mod 717 = 7 × 2 + 323
31 mod 731 = 7 × 4 + 343
123 mod 11123 = 11 × 11 + 2112
1234 mod 101234 = 10 × 123 + 41234

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.

ExpressionFloored (Python, Excel)Truncated (C, Java, JS %)Euclidean
17 mod 5222
−17 mod 53−23
17 mod −5−322
−17 mod −5−2−23
−23 mod 61−51

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?

a mod n is the remainder after dividing a by n. For example, 17 mod 5 = 2 because 17 = 5 × 3 + 2. In modular arithmetic, two numbers with the same remainder are called congruent: 17 ≡ 2 (mod 5).

How do you find mod?

Divide a by n, round the quotient down to a whole number q, then compute r = a − n × q. For 47 mod 6: 47 / 6 = 7.83, q = 7 and r = 47 − 42 = 5. If you round toward zero instead of down, you get the truncated remainder used by C and Java, which differs only for negative numbers.

How do you calculate modulo on a calculator?

Divide a by n and note the whole-number part of the answer, then calculate a − n × (whole-number part). For 1234 mod 10: 1234 ÷ 10 = 123.4, and 1234 − 10 × 123 = 4. In Excel or Google Sheets, =MOD(1234, 10) returns 4 directly.

What is 1 mod 2?

1 mod 2 = 1. Because 2 does not fit into 1, the quotient is 0 and the whole 1 is left over. Any odd number mod 2 is 1 and any even number mod 2 is 0. In the same way, 2 mod 3 = 2, 2 mod 4 = 2 and 3 mod 4 = 3.

What is the modulo of a negative number?

It depends on the convention. Under the floored rule used in mathematics, Python and Excel, −17 mod 5 = 3. Under the truncated rule used by % in C, Java and JavaScript, it is −2. The Euclidean rule always gives a non-negative remainder, here 3.

What is 5 mod 0?

It is undefined, because finding it would mean dividing by zero. Python raises an error, Excel shows #DIV/0! and JavaScript returns NaN. A few texts define a mod 0 = a as a convention, but this calculator reports an error instead. By contrast, 0 mod 5 = 0.

Is modulo the same as remainder?

For positive numbers, yes. Some languages separate the two: the remainder operation follows the truncated rule and takes the sign of the dividend, while the modulo operation follows the floored rule and takes the sign of the divisor. They differ only when exactly one of the numbers is negative and the division is not exact.

Can you take the modulo of a decimal number?

Yes. The definition r = a − n × ⌊a / n⌋ works for any real numbers, so 7.5 mod 2 = 1.5 and 5.5 mod 0.2 = 0.1. This calculator scales decimal inputs to whole numbers first, so it avoids the rounding errors that make 5.5 % 0.2 return 0.0999999… in many programming languages.

Cite this page

Statculator. (2026, November 14). Modulo Calculator. Retrieved November 14, 2026, from https://statculator.com/math/modulo-calculator/