Mathwords logoMathwords

Modulo Operation — Definition, Formula & Examples

The modulo operation finds the remainder when one whole number is divided by another. For example, 17 mod 5 equals 2 because 17 ÷ 5 = 3 with a remainder of 2.

Given integers aa and nn with n>0n > 0, the expression amodna \bmod n yields the unique integer rr such that a=qn+ra = qn + r where qq is an integer and 0r<n0 \le r < n.

Key Formula

amodn=rwherea=qn+rand0r<na \bmod n = r \quad \text{where} \quad a = qn + r \quad \text{and} \quad 0 \le r < n
Where:
  • aa = The number being divided (the dividend)
  • nn = The number you divide by (the divisor), must be positive
  • qq = The quotient — how many whole times n fits into a
  • rr = The remainder, which is the result of the modulo operation

How It Works

To compute amodna \bmod n, divide aa by nn and keep only the remainder. First, find how many times nn fits into aa without going over. Multiply that count by nn, then subtract the result from aa. What's left is the remainder. For instance, 23mod723 \bmod 7: since 7×3=217 \times 3 = 21 and 2321=223 - 21 = 2, the answer is 2.

Worked Example

Problem: Find 47 mod 6.
Divide: Divide 47 by 6 to find the whole-number quotient.
47÷6=7 remainder ?47 \div 6 = 7 \text{ remainder } ?
Multiply back: Multiply the quotient by the divisor.
7×6=427 \times 6 = 42
Subtract: Subtract to find the remainder.
4742=547 - 42 = 5
Answer: 47mod6=547 \bmod 6 = 5

Why It Matters

The modulo operation is essential in computer science for tasks like determining whether a number is even or odd (nmod2n \bmod 2), cycling through lists, and powering encryption algorithms. In everyday math, it helps with clock arithmetic — 15 hours after 10 o'clock lands on 1 o'clock because (10+15)mod12=1(10 + 15) \bmod 12 = 1.

Common Mistakes

Mistake: Confusing the modulo result with the quotient.
Correction: The modulo operation returns the remainder, not how many times the divisor fits in. For 17mod517 \bmod 5, the answer is 2 (the remainder), not 3 (the quotient).