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

Sum of Two Squares Theorem

Graduate Depth 81 in the knowledge graph ☐ I know this ☆ Set as goal
2topics build on this
383prerequisites beneath it
See this on the map →
Fundamental Theorem of Arithmetic (Rigorous Proof)Lagrange's Four-Square Theorem→→Pythagorean Triples (Parametrization)
sum-of-squares diophantine representation

Core Idea

An integer n is representable as n = a2 + b2 iff in its prime factorization, every prime p ≡ 3 (mod 4) appears to an even power. This theorem connects number theory and geometry; Gaussian integers provide an elegant proof.

Explainer

You already know from the fundamental theorem of arithmetic that every positive integer has a unique factorization into primes. The sum of two squares theorem gives a precise answer to the question: which integers live on the integer lattice of a circle? That is, for which n does the equation n = a² + b² have an integer solution? The answer depends entirely on the prime factorization of n, and specifically on how primes behave modulo 4.

Start with primes. The prime 2 = 1² + 1² works. For odd primes, there are only two residues mod 4: either p ≡ 1 (mod 4) or p ≡ 3 (mod 4). It turns out that every prime p ≡ 1 (mod 4) is representable as a sum of two squares — for example, 5 = 1² + 2², 13 = 2² + 3², 17 = 1² + 4² — while no prime p ≡ 3 (mod 4) is representable. You can verify the latter: modulo 4, squares are always 0 or 1, so a² + b² is congruent to 0, 1, or 2 (mod 4) — never 3. This means primes like 3, 7, 11, 19 can never be written as a sum of two squares.

The elegant proof uses the Gaussian integers ℤ[i] = {a + bi : a, b ∈ ℤ}. The key insight is that a² + b² = (a + bi)(a − bi) = |a + bi|². So asking whether n is a sum of two squares is the same as asking whether n is the norm of a Gaussian integer. Primes p ≡ 3 (mod 4) remain inert (prime) in ℤ[i] — they don't factor further. Primes p ≡ 1 (mod 4) split: p = π · π̄ for a Gaussian prime π = a + bi with |π|² = p. This is why such primes are sums of two squares. The prime 2 ramifies: 2 = −i(1+i)².

To handle composite n, you need a multiplicative identity: if m and n are both sums of two squares, so is mn. This follows from the Gaussian integer norm being multiplicative: N(αβ) = N(α)N(β). It means you can assemble the representation of n from those of its prime factors. The constraint "every prime p ≡ 3 (mod 4) appears to an even power" comes from the fact that such primes must pair up — each contributes a factor of p to the norm, and two inert primes p · p = p² = (p + 0i)(p − 0i) is representable. The theorem is one of the cleanest examples of how algebraic structure in an extended ring (ℤ[i]) illuminates purely arithmetic questions about ℤ.

Practice Questions 5 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 Fundamental Theorem of Arithmetic → Divisibility Theory (Formal Treatment) → Bézout's Identity → Linear Diophantine Equations → Pell's Equation → Lagrange's Four-Square Theorem → Sum of Two Squares Theorem

Longest path: 82 steps · 383 total prerequisite topics

Prerequisites (2)

Leads To (1)