Sums of Four Squares
Take any positive integer you like — say 7, or 2023, or a billion. Ask whether it can be written as a sum of four perfect squares (zero allowed). Try 7: it is . Try 2023: it is . This is no accident. Lagrange's four-square theorem asserts that every positive integer is a sum of four squares. There are no exceptions and no extra hypotheses. This is a striking contrast to sums of two squares. There, Sums of Two Squares shows that primes must appear to an even power. The result matters because it is the cleanest possible universality statement in the theory of quadratic forms: the form represents everything. It sits at the headwaters of the study of which integers a given quadratic form can represent. This subject blossoms into the full theory of Binary Quadratic Forms. It extends beyond into the theory of quadratic forms in variables and modular forms. Historically it was conjectured by Bachet (from Diophantus) and Fermat. It was finally proved by Lagrange in 1770 using a descent argument sharpened by an identity of Euler. The big picture: three squares are not enough ( is not a sum of three squares). But four is exactly the right number to close off all obstructions. The proof has two independent engines. First, an algebraic identity — Euler's four-square identity — reduces the whole problem to primes. If every prime is a sum of four squares, a multiplicativity argument extends this to every product of primes. Hence it extends to every integer greater than . (And , trivially.) Second, a beautiful pigeonhole-and-descent argument shows every odd prime is a sum of four squares. This argument is due to Lagrange and was streamlined by later writers. This article gives the full, self-contained proof. It covers the identity, the key lemma, and the descent step. The key lemma states some multiple of a prime () is a sum of four squares. The infinite-descent step shrinks down to . We verify every computation. We discuss why each hypothesis (four squares, not three) is essential. We close with the historical and modern context — a gateway to Waring's problem and the theory of quadratic forms.
- Statement: every non-negative integer can be written as with .
- Reduction step: Euler's four-square identity shows the set of sums of four squares is closed under multiplication.
- This reduces the theorem to proving it for primes only.
- Core step: for any odd prime , some makes a sum of four squares (pigeonhole on residues).
- Descent step: if divides a representable , one can always produce a smaller multiple of that is also a sum of four squares, forcing eventually.
- Key idea: four squares are exactly enough because a quaternion-style identity makes "sum of four squares" a multiplicatively closed property, and infinite descent kills every obstruction prime by prime.
Where this lives today
The four-square theorem is the prototype for Waring's problem: for each , does every sufficiently large integer decompose as a bounded sum of -th powers? Lagrange's theorem is the case with the exact bound established (unlike higher Waring exponents, where the minimal number of summands is much harder to pin down and, for some , still not exactly known in full generality). In the theory of quadratic forms, is the simplest positive-definite quaternary form representing all non-negative integers; the classification of which quadratic forms are "universal" (represent everything) is a rich modern subject, culminating in results such as the Conway–Schneeberger "15 theorem" characterizing universal quaternary forms by checking representability of integers up to . This connects directly onward to Binary Quadratic Forms, where the two-variable analogue of representability questions is governed by class numbers and reduction theory, and to the broader theory of modular forms, where theta series built from quadratic forms (such as ) encode representation counts as Fourier coefficients — Jacobi's formula for is exactly the statement that this theta series is a specific weight-2 modular form. In algebra, the identity underlying the proof is a shadow of the multiplicativity of the norm form on the quaternions , the first genuinely noncommutative division algebra over ; this is the same structural fact exploited in the two-square case via Gaussian integers (norms in ) as covered in Sums of Two Squares, and it generalizes further to Cayley's eight-square identity over the octonions. In computer science and cryptography, algorithms for finding an explicit four-square decomposition of a given integer run in polynomial time (via a randomized reduction to sums of two squares over primes dividing auxiliary quantities), and are used in some lattice-based and combinatorial constructions; the underlying pigeonhole-plus-descent technique is a recurring pattern in constructive existence proofs across combinatorics and coding theory. In statistical mechanics and physics, sums of squares appear naturally as energies of lattice vectors, and representation-counting functions like arise in computing degeneracies of quantum states on four-dimensional lattices.
Ask the tutor: Can you walk through why the descent step needs to be odd, using a fresh numerical example where starts even?
A non-negative integer is a sum of four squares if there exist integers (not necessarily distinct or positive, zero permitted) such that
Equivalently, lies in the image of the quaternary quadratic form on .
Intuition
Sums of two squares are picky: , , , , are all not sums of two squares, and Sums of Two Squares characterizes exactly which qualify, via the exponents of primes in their factorization. Sums of three squares are also picky — Legendre's three-square theorem says fails exactly when . The remarkable phenomenon with four squares is that the pickiness vanishes entirely: no number is excluded. Why does adding one more square variable remove every obstruction? Heuristically, the "local" obstructions to two- and three-square representability come from congruence conditions modulo and : squares are always , so sums of two or three squares miss certain residues completely. With four squares, every residue mod 8 becomes achievable, and — more deeply — the multiplicative identity below shows that the set of representable numbers is closed under multiplication in a way that is robust enough to absorb every prime, without leaving any congruence-class gap. The picture below shows how three squares fail to reach but four squares reach it immediately, and how the key identity "multiplies" representations together.
Central theorem
Every non-negative integer can be written as a sum of four squares of integers:
We isolate the machinery into named lemmas, each with hypotheses stated explicitly, and assemble them into the final proof.
For all real (in particular integer) numbers ,
where
This is a direct algebraic verification (technique: brute-force expansion, made transparent via quaternion multiplication). Consider the quaternions
in the quaternion algebra with , , , . For a quaternion define its conjugate and its norm , which is a nonnegative real scalar (the cross terms cancel because anticommute pairwise and each squares to ; this is a direct computation from the multiplication rules above). Quaternion multiplication is associative (it is a specific instance of an associative algebra defined by bilinear extension of the rules on basis elements ; associativity is checked once on the 4×4×4 table of basis products and then follows for all quaternions by bilinearity). Conjugation is an anti-automorphism: , verified directly from the defining rules by checking it on and extending bilinearly. Hence for any quaternions ,
using that is a real scalar and hence commutes with . This proves . Now compute explicitly using the multiplication table
and collect the coefficient of in
Expanding term by term (16 products) and grouping by basis element gives exactly
with as stated. (For instance the coefficient of collects from , from times , and similarly , from , giving ; the other coefficients are computed the same way using the table.) Then
which is precisely the claimed identity.
∎If and are each sums of four squares, then so is .
Immediate from Euler's Four-Square Identity: write and , then for the explicit integers (integer because each is an integer linear combination of integer ).
∎By this corollary and unique factorization, it suffices to prove the theorem when is , , , or an odd prime : every positive integer factors as a product of primes, each of which is a sum of four squares (once we handle and odd primes), so itself is a sum of four squares by repeated application of the corollary. We record the trivial cases and then attack odd primes.
, , .
Immediate by inspection.
∎Now fix an odd prime . The heart of the proof is:
Let be an odd prime. There exists an integer with such that is a sum of four squares:
More precisely: there exist integers with
so that for some positive integer .
This is a pigeonhole argument (technique: counting residues, due essentially to Lagrange/Euler and streamlined by later authors such as Ireland–Rosen). Consider the two sets
Each set has exactly elements. Indeed, for , if then ; since , cannot divide , so , forcing because . Hence the map is injective on , giving distinct residues. The identical injectivity argument applied to (composing an injective squaring map with the bijection ) shows as well. Both and are subsets of the set of residues , which has exactly elements. Since
the pigeonhole principle forces . So there exist with such that
Thus for some non-negative integer . We bound : since ,
for (in fact certainly holds for ). Hence
Also since and must be a positive multiple of (it cannot be since ). Thus , as claimed.
∎The previous lemma shows some multiple with is representable as (here with , but we will need the fully general descent below, so we restate the induction in terms of an arbitrary representable multiple). We now perform the descent.
Let be an odd prime, and suppose is the smallest positive integer such that is a sum of four squares. Then .
This is Lagrange's infinite descent (technique: minimal counterexample / descent, sharpened using Euler's identity — the modern streamlined form is due to later expositors, e.g. as in Ireland–Rosen). By Lemma: Some small multiple of is a sum of four squares, the set of positive integers such that is a sum of four squares is non-empty and contains an element less than ; by well-ordering it has a least element , and (in particular exists and the bound already proved, so a minimum with exists). Suppose, for contradiction, that . Write
for some integers .
Step 1: is odd. Suppose is even. Then . Among any four integers whose squares sum to an even number, we can always pair into two pairs of equal parity: reduce mod 2, each of is or , and even means the number of odd terms among is even (0, 2, or 4). In every such case, we may reorder so that and (if or are odd, any pairing works since all agree in a block of parity; if exactly are odd, pair the two odd ones together and the two even ones together). Then , , , are all even, so
This exhibits as a sum of four squares (of integers, since the four halved quantities are integers), and is a smaller positive integer with representable — contradicting minimality of . Hence must be odd.
Step 2: reduce modulo . Since is odd and, by hypothesis, , we have . Choose integers with
(possible since is odd: every residue class mod has a unique representative strictly between and ). Then
so for some non-negative integer . Moreover, since each of satisfies etc.,
so .
Step 3: rule out . If , then , meaning , , , . Then , so . Since and is prime, this is impossible (the only positive divisors of are and ). Hence , so .
Step 4: apply Euler's identity to . We have two representations
so by Euler's Four-Square Identity,
where, using the identity with and ,
Step 5: show each is divisible by , so that is an integer. Since , we compute modulo :
So , and we may set for . Dividing the identity by gives
Step 6: contradiction. This exhibits as a sum of four squares, with (we showed in Step 3 and in Step 2). This contradicts the minimality of as the smallest positive integer with a sum of four squares. Therefore the assumption is false, and .
∎(Proof of Lagrange's Four-Square Theorem.) We assemble the pieces (technique: multiplicative reduction to primes, then descent on primes — this is the full, non-circular proof). Base cases. By Lemma: Base cases, are each sums of four squares. Odd primes. Let be an odd prime. By Lemma: Some small multiple of is a sum of four squares, the set is non-empty. By Lemma: Descent step, its least element is , i.e., itself is a sum of four squares. General . Every integer factors as a product of primes,
where each (with repetition allowed). Each is a sum of four squares, by the base case or by the odd-prime case just proved. By repeated application of Corollary: Multiplicative closure (an induction on : the product of the first factors is a sum of four squares, and multiplying by the -st factor — itself a sum of four squares — preserves this by the corollary), is a sum of four squares. Together with from the base case, every non-negative integer is a sum of four squares.
∎Worked examples
Example 1: the prime . We illustrate the pigeonhole lemma and descent concretely, choosing an asymmetric case where the naive small representation is not immediately obvious. Step A (pigeonhole). We need with and . Compute squares mod 23 for :
(e.g. , , , , , ). We want , i.e. . Scanning pairs: with , , need , so works (). Check: . So . Step B (descent from to ). We have with . Reduce each coordinate mod to the representative in , i.e. residues in :
so . Then
Good — as guaranteed, and as the proof requires. Now apply Euler's identity to :
Check: . Indeed . Each should be divisible by : are all multiples of . Dividing by :
and
So . We have descended in one step directly to , giving an explicit four-square representation
Example 2: an arbitrary composite number, . Factor . We need four-square representations of and of , then combine via Euler's identity. Four squares for : (). Four squares for : (). Combine with itself using Euler's identity to get : take . Then
So — unsurprising since is trivially a perfect square, but it confirms the identity mechanics. Combine and : take (representation of ) and (representation of ). Then
Check: . And indeed . So
As a sanity check by direct arithmetic: , and , and . Correct. (This differs from, but is equally valid alongside, the representation mentioned in the overview — four-square representations need not be unique.)
Drop nothing about the integers involved, but weaken the hypothesis on the number of squares from four to three: consider the claim "every non-negative integer is a sum of three squares." This is false, and the standard counterexample is . Check every combination of three squares from (since , no square exceeding can appear): the possible sums using are
— explicitly: , , , , , , , , , . The number never appears among these sums. Since any three squares summing to would have to be built entirely from (as ), and none of the ten combinations above equals , we conclude is not a sum of three squares. This matches the general theorem of Legendre (proof beyond the scope of this article): is a sum of three squares if and only if is not of the form for non-negative integers . Here is exactly of the excluded form. This shows the hypothesis "four squares" in Lagrange's theorem is not an artifact of a weak proof technique — it is numerically necessary: dropping to three squares genuinely breaks universality, with as the smallest failure.
Scope, edge cases & common traps
| Situation | What happens | Why |
|---|---|---|
| trivial, included by convention | ||
| a perfect square | e.g. | zeros are allowed, so squares are trivially sums of four squares |
| Only three squares allowed | fails for (Legendre's ) | three squares miss an entire congruence family |
| Requiring strictly | fails for small (e.g. cannot be written with four positive squares) | zero must be allowed as a summand in general |
| Uniqueness of representation | false — e.g. | the theorem asserts existence, not uniqueness; the number of representations is governed by Jacobi's four-square formula, a separate refinement |
| Negative integers | theorem does not apply | squares are non-negative, so only can be represented |
The mathematician behind it
Origins · 1 minJoseph-Louis Lagrange and how this was discovered
Lagrange was born in Turin and rose to become, alongside Euler, the dominant analytical mathematician of the eighteenth century. He worked at the Berlin Academy under Frederick the Great and later at the Paris institutions reorganized after the Revolution, contributing foundational work to mechanics (the Mécanique analytique), the calculus of variations, and algebra (early group-theoretic ideas behind the unsolvability of the quintic). In number theory, building on conjectures traceable to Diophantus, Bachet, and Fermat, Lagrange gave in 1770 the first complete proof that every positive integer is a sum of four integer squares, using a descent method sharpened by Euler's four-square identity — itself discovered by Euler while attempting the same problem without quite closing the descent argument.
Does the four-square theorem give a unique representation for each ?
No. Existence, not uniqueness, is what Lagrange's theorem asserts. Many integers have several genuinely different representations as ordered or unordered sums of four squares — for instance , two distinct decompositions. The precise count of ordered representations (with signs and order counted) is given by Jacobi's formula, , which is a much finer statement than mere existence and requires the separate machinery of modular forms and theta functions to prove.
Why does the proof need Euler's identity at all — couldn't we just try to show every prime is representable directly and add representations coordinate-wise?
Sums of squares do not add coordinate-wise in general: if and , there is no reason should equal . What makes representable is a genuinely multiplicative structure — the quaternion norm being multiplicative — captured precisely by Euler's identity. Without it, one would have to prove representability for every integer directly, an intractable task; the identity is what allows reducing the infinite problem (all ) down to a finite-flavored one (all primes).
Is the four-square theorem related to sums of two squares?
Yes, both are instances of the same phenomenon at different "orders": the norm form on the Gaussian integers is multiplicative for two squares (as used in Sums of Two Squares), while the norm form on the Hamilton quaternions is multiplicative for four squares. Two squares have genuine obstructions (primes to an odd power block representability), while four squares have none — the extra "room" in four real dimensions removes every obstruction, essentially because the quaternions, unlike a hypothetical two-real-dimension-only analogue, supply enough multiplicative structure combined with the descent to reach every prime.
Why does the pigeonhole argument require rather than all residues ?
Restricting to is what makes the two sets and each have exactly distinct elements (squaring is 2-to-1 on the full range , collapsing and to the same square, so restricting to half the range removes the redundancy). This exact count is what forces , guaranteeing overlap by pigeonhole. Using the full range would double-count and could make the pigeonhole bound too weak to guarantee an intersection.
Does the theorem hold for negative integers or non-integers?
No — by definition, a sum of squares of real numbers is always non-negative, so no negative integer can be a sum of four squares (or any number of squares). For non-integers such as rational numbers, a related but different theory exists (e.g., every non-negative rational is a sum of four rational squares, provable from the integer case by clearing denominators and using the identity), but the theorem as stated is specifically about non-negative integers decomposed using integer square roots.
How does this connect to Waring's problem?
Waring's problem asks, for each exponent , for the minimal number such that every positive integer is a sum of at most -th powers. Lagrange's theorem is exactly the statement (three is not enough, as the counterexample shows, and four always suffices). For higher the analogous minimal number is far harder to determine and was only fully resolved for many exponents in the twentieth century using the Hardy–Littlewood circle method; the four-square theorem remains the cleanest, fully elementary base case of this entire research program.