Mathwords logoMathwords

Modular Arithmetic

Modular Arithmetic

Regular addition, subtraction, and multiplication, but with the answer given modulo n.

 

Three examples: 17−3≡2 (mod 3), 17−3≡4 (mod 10), 17−3≡14 (mod 20)

 

 

See also

Modular equivalence

Key Formula

amodn=rwhere a=qn+r and 0r<na \mod n = r \quad \text{where } a = qn + r \text{ and } 0 \le r < n
Where:
  • aa = The integer you are reducing
  • nn = The modulus (the number you divide by)
  • qq = The quotient (an integer)
  • rr = The remainder, which is the result

Worked Example

Problem: Compute (17 + 20) mod 12.
Step 1: Add the two numbers normally.
17+20=3717 + 20 = 37
Step 2: Divide by the modulus 12 and find the remainder.
37=3×12+137 = 3 \times 12 + 1
Step 3: The remainder is the answer in modular arithmetic.
37mod12=137 \mod 12 = 1
Answer: (17 + 20) mod 12 = 1. This is exactly how a 12-hour clock works: 5 PM plus 20 hours lands on 1 PM.

Why It Matters

Modular arithmetic is the foundation of modern cryptography, including the RSA algorithm that secures online transactions. It also appears in everyday life: clocks use mod 12, days of the week use mod 7, and checksums on credit cards and ISBNs rely on modular calculations to detect errors.

Common Mistakes

Mistake: Confusing the modulus with the remainder. For example, saying '37 mod 12 = 12'.
Correction: The result of a mod n is always the remainder r, which satisfies 0 ≤ r < n. It can never equal n itself. Here, 37 mod 12 = 1, not 12.

Related Terms