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 88 in the knowledge graph I know this Set as goal
6topics build on this
402prerequisites beneath it
See this on the map →
Carmichael Function and Carmichael NumbersMultiplicative Inverses in Modular Arithmetic+1 moreThe Euclidean Algorithm and Greatest Common Divisor
modular-arithmetic number-theory

Core Idea

a ≡ b (mod n) if and only if n divides a - b. Modular arithmetic obeys addition, subtraction, and multiplication rules like standard arithmetic. Congruences partition the integers into residue classes, and arithmetic can be performed within these classes.

Explainer

Think of a clock. After 12 hours, the clock resets — 13 o'clock is the same position as 1 o'clock. This is modular arithmetic in action: 13 ≡ 1 (mod 12) because 12 divides 13 − 1 = 12. The notation a ≡ b (mod n) simply means that a and b leave the same remainder when divided by n, or equivalently that n divides a − b. Every integer belongs to exactly one residue class modulo n, represented by its remainder: 0, 1, 2, ..., n − 1. Instead of working with all integers, you work with these n classes.

The power of modular arithmetic comes from its closure under operations. If a ≡ b (mod n) and c ≡ d (mod n), then a + c ≡ b + d (mod n) and a × c ≡ b × d (mod n). This means you can reduce numbers before performing operations and still get the right answer modulo n. For example, to compute 99 × 101 (mod 10), note that 99 ≡ 9 and 101 ≡ 1 (mod 10), so the product is ≡ 9 × 1 = 9 (mod 10). The actual product 9,999 also ends in 9 — confirming the calculation. This reduction trick makes modular arithmetic essential in cryptography and computer science, where numbers can be astronomically large.

Division works differently in modular arithmetic. You cannot always divide — you need a modular inverse. The inverse of a modulo n exists if and only if gcd(a, n) = 1; when it exists, a⁻¹ is the unique x with ax ≡ 1 (mod n). For example, 3 × 5 = 15 ≡ 1 (mod 7), so 3⁻¹ ≡ 5 (mod 7). When n is prime, every nonzero element has an inverse, making the residue classes modulo a prime into a complete arithmetic system (a field). This is why prime moduli appear everywhere in cryptographic protocols.

A powerful shortcut for large powers is modular exponentiation. To compute 2¹⁰⁰ (mod 13), you don't multiply 100 times. Instead, repeatedly square and reduce: 2² = 4, 2⁴ ≡ 3, 2⁸ ≡ 9, 2¹⁶ ≡ 3 (mod 13), and so on, then combine. This connects to Fermat's Little Theorem: if p is prime and p does not divide a, then aᵖ⁻¹ ≡ 1 (mod p). So 2¹² ≡ 1 (mod 13), meaning powers of 2 cycle with period dividing 12 modulo 13. Modular arithmetic transforms intractable arithmetic on huge numbers into manageable computation on small residues.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesSet Operations: Union, Intersection, and ComplementProof by CasesProving by Cases and ExhaustionVacuous Truth and Trivial CasesProof by Cases (Proof by Exhaustion)Mathematical InductionDivisibility and Greatest Common DivisorThe Fundamental Theorem of ArithmeticDivisibility Theory (Formal Treatment)Fundamental Theorem of Arithmetic (Rigorous Proof)Arithmetic Functions and MultiplicativityDirichlet Series and L-FunctionsPrimes in Arithmetic Progressions (Dirichlet's Theorem)Distribution of PrimesIntroduction to the Riemann Zeta FunctionDirichlet Series and L-FunctionsPrimes in Arithmetic Progressions (Dirichlet's Theorem)Wilson's TheoremFermat's Little TheoremCarmichael Function and Carmichael NumbersModular Arithmetic and Congruences

Longest path: 89 steps · 402 total prerequisite topics

Prerequisites (3)

Leads To (1)