Modulo Calculator

Calculate the remainder when dividing a by n (a mod n).

Result
—
Enter values and click calculate

Quick Examples

Modulo Operation

The modulo operation finds the remainder after division of one number by another.

a mod n = r where a = qn + r and 0 ≤ r < n

Clock Arithmetic

Modulo is used in clock arithmetic. For example, to find what time it is 25 hours after 10:00:

(10 + 25) mod 12 = 35 mod 12 = 11 o'clock

Applications

  • Cryptography: RSA encryption, hash functions
  • Computer Science: Hash tables, random number generation
  • Music: Calculating chord progressions
  • Scheduling: Day-of-week calculations

Modulo Vocabulary: Dividend, Divisor, Quotient, Remainder

Every modulo computation involves four named parts:

TermSymbolMeaningIn 17 mod 5
DividendaThe number being divided17
Divisor (modulus)nThe number you divide by5
QuotientqWhole times n fits into a3
RemainderrWhat is left over2
a = q × n + r, where 0 ≤ r < n

The inequality 0 ≤ r < n is the whole contract: the remainder is never negative and always smaller than the divisor. This calculator follows that mathematical convention, so −7 mod 5 = 3, not −2.

How the Modulo Calculator Works

Enter the dividend (a) and the divisor (n), then click Calculate Modulo. The tool divides, discards the fractional part of the quotient, and returns the remainder along with the verification equation a = q × n + r. The divisor cannot be zero — division by zero has no quotient and therefore no remainder.

How to Calculate Modulo by Hand

Four steps, no calculator needed:

  1. Divide a by n and keep only the whole part (round down): 17 ÷ 5 = 3.4 → q = 3.
  2. Multiply the divisor by that whole part: 5 × 3 = 15.
  3. Subtract from the dividend: 17 − 15 = 2.
  4. Read the remainder: 17 mod 5 = 2.

More Worked Examples

Problemq (whole part)q × nRemainder
100 mod 714982
123 mod 10121203
25 mod 46241
15 mod 260015
15 mod 53150

Two patterns worth noticing: when the dividend is smaller than the divisor (15 mod 26), the remainder is the dividend itself; when the divisor divides evenly (15 mod 5), the remainder is 0.

Negative Numbers: Three Conventions

For positive inputs everyone agrees. Negatives split the world into three camps, differing only in how they round the quotient:

ExpressionFloored (Python, math class)Truncated (JavaScript, C, Java)Euclidean
17 mod 5222
−17 mod 53−23
17 mod −5−322
−17 mod −5−2−23
a mod n = a − n × ⌊a / n⌋ (floored convention)
  • Floored rounds the quotient toward −∞; the remainder takes the divisor's sign. Used by Python, Ruby, and most math courses.
  • Truncated rounds toward zero; the remainder takes the dividend's sign. Used by JavaScript, C, C++, Java, and Go.
  • Euclidean always returns a non-negative remainder (0 ≤ r < |n|), matching the division algorithm above.

Check −17 mod 5 the floored way: ⌊−17/5⌋ = ⌊−3.4⌋ = −4, so −17 − 5(−4) = −17 + 20 = 3. All three conventions satisfy a = qn + r — they just choose different q.

Congruence: a ≡ b (mod n)

Closely related to the mod operation is congruence: a and b are congruent modulo n when they leave the same remainder — equivalently, when n divides their difference.

a ≡ b (mod n) exactly when n divides (a − b)
  • 17 ≡ 2 (mod 5) — both leave remainder 2, and 17 − 2 = 15 is a multiple of 5.
  • 9 ≡ 21 (mod 6) — 21 − 9 = 12, a multiple of 6; both leave remainder 3.

Numbers congruent to each other form a congruence class: …, −8, −3, 2, 7, 12, 17, 22, … are all ≡ 2 (mod 5). The ≡ sign is not equality — it means "equal up to a multiple of n."

Modular Arithmetic Laws

You can take mods before finishing a calculation — the secret to handling enormous numbers:

(A + B) mod C = ((A mod C) + (B mod C)) mod C
(A × B) mod C = ((A mod C) × (B mod C)) mod C
A^B mod C = ((A mod C)^B) mod C

Worked: (11 × 7) mod 4

Direct: 77 mod 4 = 1 (4 × 19 = 76, remainder 1). Via the law: (11 mod 4) × (7 mod 4) = 3 × 3 = 9, and 9 mod 4 = 1. Same answer, smaller numbers.

Worked: 2^100 mod 3

2^100 has 31 digits — no need to write it out. Since 2² = 4 ≡ 1 (mod 3), split the exponent: 2^100 = (2²)^50, so 2^100 mod 3 = 1^50 mod 3 = 1. Cryptography runs on exactly this trick with numbers hundreds of digits long.

Edge Cases and Fine Print

  • a mod 0 is undefined. Division by zero has no quotient, so there is no remainder either.
  • a mod 1 = 0, always. Every integer is a multiple of 1.
  • Decimals work too: 7.5 mod 2 = 1.5 (2 × 3 = 6, remainder 1.5).
  • Precedence: mod binds as tightly as × and ÷, so 10 + 7 mod 3 = 10 + 1 = 11.
  • The % symbol: most programming languages write a mod b as a % b — but remember it may follow the truncated convention for negatives.

Real-World Applications

  • Check digits: ISBN-10 codes validate with mod 11, IBAN bank numbers with mod 97, and UPC barcodes with mod 10 — a mistyped digit breaks the congruence and the error is caught.
  • Calendars: what weekday is 100 days after Monday? 100 mod 7 = 2, so Wednesday — the remainder counts the leftover days after whole weeks.
  • Cryptography: RSA encryption is modular exponentiation with gigantic moduli; the laws above keep it computable.
  • Hash tables: a hash value mod table-size picks the storage slot, spreading keys evenly.
  • Parity and divisibility: n mod 2 = 0 flags even numbers; a year is a leap year roughly when year mod 4 = 0.
  • Cyclic schedules: rotating shifts, round-robin tournaments, and repeating patterns all "wrap around" with mod.

Common Mistakes to Avoid

  • Assuming −17 mod 5 = −2 everywhere. That is the JavaScript answer; Python and math classes say 3. Know your convention.
  • Reading ≡ as =. 17 ≡ 2 (mod 5) does not claim 17 equals 2 — only that they differ by a multiple of 5.
  • Confusing remainder with the decimal part. 17 ÷ 5 = 3.4, but 17 mod 5 = 2, not 0.4.
  • Computing a mod 0. Undefined — always guard against a zero divisor.
  • Forgetting the final mod in the laws. (A mod C + B mod C) can exceed C; the outer mod brings it back into range.

Where the Word Comes From

Modulo comes from the Latin modus, meaning "measure" — arithmetic measured against a fixed modulus. Carl Friedrich Gauss introduced the ≡ congruence notation in his 1801 Disquisitiones Arithmeticae, founding modern number theory on the idea that numbers sharing a remainder can be treated as equivalent.

Frequently Asked Questions

What is the difference between mod and remainder?
For positive numbers, mod and remainder give the same result. For negative numbers, modulo typically returns a positive result (wrapping around), while remainder returns a negative value.