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 and with , the expression yields the unique integer such that where is an integer and .
Key Formula
Where:
- = The number being divided (the dividend)
- = The number you divide by (the divisor), must be positive
- = The quotient — how many whole times n fits into a
- = The remainder, which is the result of the modulo operation
How It Works
To compute , divide by and keep only the remainder. First, find how many times fits into without going over. Multiply that count by , then subtract the result from . What's left is the remainder. For instance, : since and , the answer is 2.
Worked Example
Problem: Find 47 mod 6.
Divide: Divide 47 by 6 to find the whole-number quotient.
Multiply back: Multiply the quotient by the divisor.
Subtract: Subtract to find the remainder.
Answer:
Why It Matters
The modulo operation is essential in computer science for tasks like determining whether a number is even or odd (), 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 .
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 , the answer is 2 (the remainder), not 3 (the quotient).
