A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Modular Arithmetic and Congruences

College Depth 76 in the knowledge graph ☐ I know this ☆ Set as goal
743topics build on this
363prerequisites beneath it
See this on the map →
Divisibility and Greatest Common DivisorEquivalence Relations+1 more→→Accidentals and Enharmonic EquivalentsClassical Ciphers and Cryptanalysis+23 more
modular-arithmetic congruence residue-classes clock-arithmetic modular-inverse

Core Idea

Two integers a and b are congruent modulo n (written a ≡ b (mod n)) if n divides their difference a − b. Congruence is an equivalence relation that partitions the integers into n residue classes forming the ring ℤₙ. Addition, subtraction, and multiplication all respect congruence. A multiplicative inverse of a mod n exists if and only if gcd(a,n) = 1, and can be computed via the extended Euclidean algorithm. Fast exponentiation (repeated squaring) computes aᵏ mod n efficiently, underpinning RSA encryption.

How It's Best Learned

Use clock arithmetic (mod 12) as an entry point — familiar from daily life. Practice reducing large expressions mod n, then computing modular inverses and powers. Carefully work through cases where inverses do not exist to understand the role of the gcd condition.

Common Misconceptions

Explainer

You already understand divisibility: n divides a when a is a multiple of n. Modular arithmetic builds a full arithmetic system on top of divisibility. Instead of asking whether n divides (a − b) each time, we write a ≡ b (mod n) and work within residue classes — the n buckets into which all integers are sorted by their remainder when divided by n. The clock is the canonical mental model: on a 12-hour clock, 10 + 5 = 15, but we report 3, because 15 ≡ 3 (mod 12). The clock wraps around automatically.

The key algebraic fact is that addition, subtraction, and multiplication all commute with taking remainders: (a + b) mod n = ((a mod n) + (b mod n)) mod n. This means you can reduce large numbers early in a computation rather than waiting until the end. Instead of computing 1000 × 999 and then taking mod 7, you can reduce first: 1000 ≡ 6, 999 ≡ 5, and 6 × 5 = 30 ≡ 2 (mod 7). This makes computations tractable even when the numbers involved are astronomically large — a property essential for cryptography.

Multiplicative inverses are where modular arithmetic becomes more interesting — and trickier — than simple clock arithmetic. A multiplicative inverse of a mod n is a number x such that ax ≡ 1 (mod n). This is the modular version of division. By Bezout's identity, such an x exists if and only if gcd(a, n) = 1. When n is prime, every nonzero element has an inverse; when n is composite, some elements don't. This is why cryptographic systems typically use prime moduli — they guarantee a complete field where division always works. The extended Euclidean algorithm (which you may know from the euclidean-algorithm prerequisite) computes these inverses efficiently.

The most seductive error in modular arithmetic is cancellation: "if ac ≡ bc (mod n), then a ≡ b (mod n)." This is not always true. You can cancel c only when gcd(c, n) = 1. Otherwise, the modulus must be adjusted: ac ≡ bc (mod n) implies a ≡ b (mod n/gcd(c,n)). The example 4 ≡ 10 (mod 6) shows the danger — dividing by 2 gives 2 ≡ 5 (mod 3), not (mod 6). Always check the gcd before canceling.

Fast exponentiation (repeated squaring) lets you compute aᵏ mod n in O(log k) multiplications. The idea: a⁸ = ((a²)²)² — eight multiplications collapse to three squarings, each followed by a mod-n reduction to keep numbers small. This algorithm is the workhorse of RSA encryption: every HTTPS response your browser receives depends on computing something like 2¹⁰²⁴ mod p efficiently. From modular congruences and the gcd condition, you now have the foundation to understand why RSA works and what it means for a system to be cryptographically secure.

Practice Questions 3 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Proof by Cases → Proving by Cases and Exhaustion → Vacuous Truth and Trivial Cases → Proof by Cases (Proof by Exhaustion) → Mathematical Induction → Divisibility and Greatest Common Divisor → The Euclidean Algorithm → Modular Arithmetic and Congruences

Longest path: 77 steps · 363 total prerequisite topics

Prerequisites (3)

Leads To (25)