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 78 in the knowledge graph ☐ I know this ☆ Set as goal
377prerequisites beneath it
See this on the map →
Fundamental Theorem of Arithmetic (Rigorous)Lagrange's Four-Square Theorem+1 more→
representations quadratic-forms diophantine

Core Idea

A positive integer n can be expressed as a sum of two squares if and only if in the prime factorization of n, every prime of the form 4k+3 appears to an even power. This classical result elegantly connects arithmetic structure to geometric representations and is proved using Gaussian integers.

Explainer

The question "which integers are sums of two squares?" sounds simple but has a surprisingly structured answer. Start by testing small cases: 1 = 1² + 0², 2 = 1² + 1², 4 = 2² + 0², 5 = 2² + 1², 9 = 3² + 0², 10 = 3² + 1². But 3, 6, 7, and 11 cannot be written this way no matter how you try. The pattern is not obvious from the examples alone, but it becomes crisp once you classify the primes.

Primes split into three types for this problem: 2 = 1² + 1² (works), primes p ≡ 1 (mod 4) like 5, 13, 17, 29 (always expressible as sums of two squares), and primes p ≡ 3 (mod 4) like 3, 7, 11, 19 (never expressible). The modular condition connects to your background in quadratic residues: −1 is a quadratic residue mod p exactly when p ≡ 1 (mod 4), and this is precisely the condition that makes p expressible as a² + b². The connection between "−1 has a square root mod p" and "p is a sum of two squares" is the heart of the theorem.

The cleanest proof uses Gaussian integers, the ring ℤ[i] = {a + bi : a, b ∈ ℤ}. In this ring, a² + b² = (a + bi)(a − bi) = |a + bi|². So asking whether p = a² + b² is the same as asking whether p factors nontrivially in ℤ[i]. Using the fundamental theorem of arithmetic for ℤ[i] (which is a Euclidean domain and hence a UFD), one can show: a prime p ≡ 1 (mod 4) factors as p = π · π̄ where π = a + bi is a Gaussian prime; a prime p ≡ 3 (mod 4) remains prime (inert) in ℤ[i] and cannot be written as a product of conjugates. This is why primes of the form 4k+3 are the obstruction.

For composite n, the full theorem follows from Brahmagupta's identity: (a² + b²)(c² + d²) = (ac − bd)² + (ad + bc)² = (ac + bd)² + (ad − bc)². This identity says the product of two sums of squares is again a sum of squares. So to check whether n is representable, you only need to check its prime factors: each prime p ≡ 1 (mod 4) contributes, 2 contributes, and a prime p ≡ 3 (mod 4) to an even power can be absorbed (since p² = p² + 0²), but a prime p ≡ 3 (mod 4) to an odd power blocks representation entirely. The theorem gives a complete, efficient criterion: factor n, check the exponents of the 4k+3 primes, and you immediately know whether n lands on the integer lattice as the squared distance from the origin.

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 Euclidean Algorithm → Modular Arithmetic and Congruences → Quadratic Residues and the Legendre Symbol → Sum of Two Squares Theorem

Longest path: 79 steps · 377 total prerequisite topics

Prerequisites (3)

Leads To (0)

No topics depend on this one yet.