Mathwords logoMathwords

Modulo — Definition, Formula & Examples

Modulo is an operation that gives you the remainder when one number is divided by another. For example, 17 modulo 5 equals 2, because 17 ÷ 5 = 3 with a remainder of 2.

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

Key Formula

amodn=rwhere a=qn+r and 0r<na \bmod n = r \quad \text{where } a = qn + r \text{ and } 0 \le r < n
Where:
  • aa = The number being divided (the dividend)
  • nn = The number you divide by (the modulus), 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. If the division comes out evenly, the result is 0. For instance, 12mod4=012 \bmod 4 = 0 because 4 goes into 12 exactly 3 times with nothing left over. You will often see the word "mod" written between two numbers, or the symbol %\% used in programming languages to mean the same thing.

Worked Example

Problem: Find 23 mod 7.
Divide: Divide 23 by 7 to find the quotient.
23÷7=3 remainder 223 \div 7 = 3 \text{ remainder } 2
Verify: Check by multiplying the quotient by 7 and adding the remainder.
3×7+2=21+2=233 \times 7 + 2 = 21 + 2 = 23 \checkmark
State the result: The remainder is 2, so the answer is 2.
23mod7=223 \bmod 7 = 2
Answer: 23mod7=223 \bmod 7 = 2

Why It Matters

Modulo is used constantly in computer science for tasks like determining whether a number is even or odd (nmod2n \bmod 2), cycling through lists, and cryptography. In everyday life, clock arithmetic is modulo 12 — fifteen hours after 1 o'clock lands on 4 o'clock because 15mod12=315 \bmod 12 = 3, and 1+3=41 + 3 = 4.

Common Mistakes

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