Modular arithmetic — definition, addition, multiplication, congruence
Overview
Modular arithmetic is arithmetic that "wraps around" after reaching a certain value called the modulus. It's the mathematical foundation of clock arithmetic, cyclic patterns, cryptography, and computer science hash functions.

Core Concepts
Instead of numbers extending infinitely, we partition them into equivalence classes based on their remainder when divided by a fixed number (the modulus). This lets us:
- Simplify calculations with large numbers (cryptography uses this!)
- Find patterns in divisibility
- Work with cyclic structures (days of week, months, rotations)
Key insight: Two numbers are "the same" in modular arithmetic if they leave the same remainder when divided by the modulus.
Equivalent definition: if and only if and leave the same remainder when divided by .
What does this mean? The difference between and is a multiple of . They're in the same "bucket" when we divide integers into groups based on remainder.
From First Principles:
1. Addition: If and , then:
Why?
- We know and for some integers
- Add these:
- Rearrange:
- Since is an integer,
2. Multiplication: If and , then:
Why?
- We have and
- Multiply:
- Expand:
- Factor:
- Therefore: , so
3. Power Rule: If , then:
Why? Apply the multiplication rule repeatedly times.
Solution:
- Method 1 (Difference): . Since the difference is a multiple of 5, yes.
- Method 2 (Remainder): (remainder 3), (remainder 3). Same remainder, yes.
Why this matters: Both numbers are in the "remainder 3" equivalence class when working mod 5.
Solution:
-
Step 1: Reduce each number first
- , so
- , so
- Why this step? Smaller numbers are easier to work with, and we can reduce before operating.
-
Step 2: Add the reduced numbers
- Why this step? By the addition rule,
-
Step 3: Result
- , so is already in standard form
- Why this step? We want the answer in the range .
Answer:
Verification: . Remainder is 5. ✓
Solution:
-
Step 1: Reduce each factor
- , so
- , so
- Why this step? Working with smaller numbers prevents overflow and simplifies calculation.
-
Step 2: Multiply reduced numbers
- Why this step? By multiplication rule,
-
Step 3: Reduce the result
- , so
- Why this step? Final answer should be in standard form .
Answer:
Verification: . Remainder is 4. ✓
Solution:
-
Step 1: Reduce the base
- , so
- Why this step? If the base reduces to something simple, the power becomes trivial.
-
Step 2: Apply power rule
- Why this step? By the power rule, congruence is preserved under exponentiation.
-
Step 3: Evaluate
- Why this step? Any power of 1 is 1.
Answer:
Key insight: Reducing the base first can make impossible-looking calculations trivial!
Why it feels right: This actually works! But for large numbers (like ), calculating the full sum first can cause overflow or unnecessary complexity.
The fix: Reduce each operand first, then operate. This is always valid by the addition/multiplication rules, and it's more efficient.
Steel-man: The "calculate then reduce" approach is mathematically correct, just computationally inefficient. The modular arithmetic rules exist precisely to let us reduce during calculation.
Why it feels right: In regular arithmetic, we can divide both sides by the same number.
The fix: Division in modular arithmetic is not always defined. You can only divide by if (i.e., and are coprime). Here, , so we can't divide by 6.
Correct approach:
- Notice divides both 6 and 9
- Simplify: becomes
- Now we can solve: multiply both sides by the modular inverse of 2 5
Steel-man: The intuition from regular algebra is powerful, but modular arithmetic has different rules. Always check if division is valid by checking the gcd.
Why it feels right: In programming, some languages return negative remainders.
The fix: In mathematics, we always want the result in . Convert negative numbers:
General rule: If you get a negative result , add multiples of until you reach : where is chosen so the result is non-negative.
Recall Explain to a 12-year-old
Imagine you have a circular track with 12 positions, numbered 0through 11 (like a clock face). You start at position 0. If you take 5 steps forward, you're at position 5. If you take 8 more steps, you'd be at 13... but wait, there's no position 13! You go around: after position 11 comes position 0 again. So 13 is the same as position 1(because 13 - 12 = 1).
This is modular arithmetic! The "12" is called the modulus—it's when you wrap around. Two positions are the "same" if they're the same spot on the circle.
When we write , we're saying "13 and 1 are the same position on a12-hour clock."
The cool part: you can add and multiply on this circular track, and everything still works! If you're at position 5 and a friend is at position 8, together you've gone steps, which is position 1. If you go around the track 5 times, taking 8 steps each time, you go steps total, which lands you at position 4 (because ).
Reminder: means " and show the same time on an -hour clock."
Properties of Congruence
Congruence modulo is an equivalence relation, meaning:
- Reflexive: (every number is congruent to itself)
- Symmetric: If , then
- Transitive: If and , then
Why this matters: These properties mean congruence partitions the integers into distinct equivalence classes (called residue classes). Every integer belongs to exactly one class.
For modulus , there are exactly residue classes: .
The Residue Classes
For modulus 5, the residue classes are:
Every integer is in exactly one of these classes. We write for the set of residue classes mod 5.
Connections
- Division Algorithm — the foundation of remainders
- GCD and LCM — determines when modular division is possible
- Fermats Little Theorem — uses modular exponentiation
- Eulers Theorem — generalizes Fermat's theorem using modular arithmetic
- Chinese Remainder Theorem — solves systems of congruences
- Modular Inverses — division in modular arithmetic
- RSA Cryptography — built entirely on modular arithmetic with large primes
- Linear Congruences — solving
- Quadratic Residues — which numbers are perfect squares mod
Practice Problems
- Verify that using both definitions
- Compute by reducing first
- Find efficiently
- Calculate (hint: reduce the base first!)
- Prove that if , then
- Find all such that
#flashcards/maths
What is the definition of congruence modulo n? :: Two integers and are congruent modulo (written ) if their difference is a multiple of , i.e., for some integer .
What is the equivalent definition of congruence using remainders?
State the addition rule in modular arithmetic :: If and , then .
State the multiplication rule in modular arithmetic
Why can we reduce numbers before operating in modular arithmetic? :: Because the addition and multiplication rules guarantee that , and similarly for multiplication. This makes calculations more efficient.
What is the danger with division in modular arithmetic?
How do you handle negative numbers in modular arithmetic? :: Add multiples of the modulus until the result is in the range . For example, because .
What are the three properties that make congruence an equivalence relation?
How many residue classes exist for modulus n?
What is the clock face analogy for modular arithmetic? :: Modular arithmetic works like a clock: after reaching the modulus value, you wrap around to 0. For mod 12, after 11 comes 0 again. Two numbers are congruent if they point to the same position on the clock.
Quick calculation: what is ?
Quick calculation: what is ?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Modular arithmetic ek aisa concept hai jahan numbersek certain value (modulus) ke bad wrap around ho jate hain, bilkul clock ki tarah. Jaise clock mein 12 ke baad fir se 1 aa jata hai, waise hi modular arithmetic mein bhi ek limit ke baad numbers cycle repeat karte hain.
Iska sabse important idea hai congruence: do numbers congruent hain (matlab same equivalence class mein hain) agar unka difference modulus ka multiple ho. For example, 17 aur 8 dono modulo 5 mein congruent hain kyunki 17 - 8 = 9, jo 5 ka multiple nahi hai... wait, 9/5 = 1 remainder 4, toh actually 17 aur 8 congruent nahi hain! Sahi example: 17 aur 12 congruent hain mod 5 kyunki 17 - 12 = 5. Yeh bhi dekh sakte hain remainders se: 17 ÷ 5 gives remainder 2, aur 12 ÷ 5 bhi remainder 2 deta hai.
Addition aur multiplication modular arithmetic mein behave karte hain waise hi jaise normal arithmetic mein, bas har step pe hum modulus se reduce kar sakte hain. Agar tum bade numbers ke sath kaam kar rahe ho, toh pehle unhe reduce karo, phir operate karo – yeh much easier aur efficient hai. Lekin dhyan rakhna, division modular arithmetic mein complicated hai – sirf tab divide kar sakte ho jab divisor aur modulus coprime hon (GCD = 1). Yeh concept cryptography mein bohot use hota hai, jahan hum bade numbers ke saath securely kaam karte hain bina actually unhe fully compute kiye.