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 TheoremPythagorean 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 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)Bézout's IdentityLinear Diophantine EquationsPell's EquationLagrange's Four-Square TheoremSum of Two Squares Theorem

Longest path: 82 steps · 383 total prerequisite topics

Prerequisites (2)

Leads To (1)