Modulo n
Modulo
n
Modular Numbers
The value of an integer modulo n is equal to the remainder left when the number is divided by n. Modulo n is usually written mod n.

See also
Key Formula
amodn=rwhere a=qn+r and 0≤r<n
Where:
- a = The integer being divided (the dividend)
- n = The modulus — the positive integer you divide by
- q = The quotient (an integer)
- r = The remainder, which is always between 0 and n − 1 inclusive
Worked Example
Problem: Find 23 mod 7.
Step 1: Divide 23 by 7 to find the quotient.
23÷7=3 remainder 2
Step 2: Express this as a division equation to verify.
23=3×7+2
Step 3: The remainder is 2, which satisfies 0 ≤ 2 < 7.
23mod7=2
Answer: 23 mod 7 = 2
Another Example
Problem: Find (−10) mod 3.
Step 1: We need to write −10 in the form q × 3 + r where 0 ≤ r < 3. Notice that −10 ÷ 3 = −3.33…, so the quotient q must be rounded down (toward negative infinity) to −4.
q=−4
Step 2: Compute the remainder using r = a − qn.
r=−10−(−4)(3)=−10+12=2
Step 3: Check: 0 ≤ 2 < 3, so the remainder is valid.
(−10)mod3=2
Answer: (−10) mod 3 = 2. With negative numbers, you still adjust so the remainder is non-negative.
Frequently Asked Questions
What is the difference between 'mod' and 'remainder'?
For positive integers, modulo and remainder mean the same thing. The distinction appears with negative numbers: the mathematical definition of mod always gives a non-negative result (0 ≤ r < n), while some programming languages define remainder so it can be negative. For instance, (−10) mod 3 = 2 in standard mathematics, but some languages return −1.
What does it mean when two numbers are 'equal mod n'?
Two integers a and b are equal mod n (written a ≡ b mod n) when they have the same remainder upon division by n. Equivalently, this means n divides the difference a − b. For example, 17 ≡ 2 (mod 5) because both leave remainder 2 when divided by 5, and 17 − 2 = 15 is divisible by 5.
a mod n (modulo operation) vs. a ≡ b (mod n) (modular equivalence)
The expression 'a mod n' is an operation that produces a single number — the remainder. The notation 'a ≡ b (mod n)' is a relation that states two numbers leave the same remainder when divided by n. One gives you a value; the other makes a statement about two values. For example, 17 mod 5 = 2 is an operation, while 17 ≡ 7 (mod 5) is a statement that both 17 and 7 share the same remainder of 2.
Why It Matters
Modular arithmetic is the foundation of clock arithmetic — a 24-hour clock resets because hours are computed mod 24. It is essential in cryptography, where algorithms like RSA rely entirely on operations mod large primes. In everyday math, divisibility tests (such as checking if a number is even by computing it mod 2) are modular arithmetic in disguise.
Common Mistakes
Mistake: Confusing the quotient with the remainder. For example, saying 23 mod 7 = 3 (the quotient) instead of 2 (the remainder).
Correction: The mod operation returns the remainder, not the quotient. Always write the full division equation a = q × n + r and identify r, the leftover part.
Mistake: Giving a negative remainder for negative numbers, such as writing (−10) mod 3 = −1.
Correction: In standard mathematical convention, the remainder must satisfy 0 ≤ r < n. For −10 mod 3, adjust by adding 3 to get r = 2. Be aware that some programming languages behave differently.
Related Terms
- Remainder — The value produced by the mod operation
- Modular Equivalence — States two numbers share the same remainder mod n
- Integers — Modular arithmetic operates on integers
- Divisibility — a is divisible by n when a mod n = 0
- Quotient — The other result of integer division
- Prime Number — Primes serve as the modulus in many applications
