Sums of Squares
students, imagine trying to build a number using only square numbers like $1^2$, $2^2$, $3^2$, and so on. 🔢 That is the heart of the sums of squares topic in Number Theory. In this lesson, you will learn how to decide when a number can be written as a sum of two squares or more, why some numbers work and others do not, and how these ideas connect to Diophantine equations, which are equations where we look for integer solutions.
What does “sum of squares” mean?
A square is a number of the form $n^2$, where $n$ is an integer. Examples are $0^2=0$, $1^2=1$, $2^2=4$, $3^2=9$, and $4^2=16$. A sum of squares is just an addition of one or more square numbers, such as $5=1^2+2^2$ or $25=3^2+4^2$.
In Number Theory, the most famous question is this: for a given integer $N$, can we find integers $a$ and $b$ such that $N=a^2+b^2$? This is a Diophantine equation, because we want integer answers only. Sometimes we also ask whether $N$ can be written as $a^2+b^2+c^2$ or even more squares. These questions are important because they reveal hidden patterns in the integers.
A quick example helps. The number $29$ can be written as $29=2^2+5^2$. But $3$ cannot be written as a sum of two squares, because the only squares less than or equal to $3$ are $0$ and $1$, and $3$ is not $0+3$, $1+2$, or $1+1$ in square form. This simple test already shows how arithmetic rules affect whether a representation is possible.
Two squares: the main idea
The problem of writing a number as $a^2+b^2$ has a powerful and famous result behind it. To understand the idea, start by listing small sums of two squares:
- $0=0^2+0^2$
- $1=1^2+0^2$
- $2=1^2+1^2$
- $4=2^2+0^2$
- $5=1^2+2^2$
- $8=2^2+2^2$
- $9=3^2+0^2$
- $10=1^2+3^2$
- $13=2^2+3^2$
You can already notice that many numbers work, but not all. For example, $7$ does not appear, and neither does $15$. This is where deeper number theory enters.
A key fact is that a prime number $p$ can be written as $p=a^2+b^2$ exactly when $p=2$ or when p
eq 2$ and $p mod 4=1. In words, odd primes that are $1$ more than a multiple of $4$ can be written as a sum of two squares, while primes that are $3 mod 4$ cannot. For example, $5=1^2+2^2$ and $13=2^2+3^2$, but $3$, $7$, and $11 cannot be written this way.
Why does this matter for composite numbers? Because the shape of a number’s prime factorization controls whether it can be a sum of two squares. If a number has primes of the form $4k+3$ appearing with odd exponents in its prime factorization, then it cannot be written as a sum of two squares. If every prime congruent to $3 mod 4 appears with an even exponent, then the number can be written as a sum of two squares.
For example, consider $45$. Its prime factorization is $45=3^2 \times 5$. The prime $3$ is of the form $4k+3$, but its exponent is $2$, which is even. So $45$ can be written as a sum of two squares. In fact, $45=3^2+6^2$. On the other hand, $21=3 \times 7$ cannot be written as a sum of two squares, since both $3$ and $7$ are primes congruent to $3 mod 4, and both appear to the first power. 🧠
Why primes congruent to $3 \bmod 4$ matter
Let’s explore the reason behind this rule in a simple way. Suppose a number $N$ can be written as $N=a^2+b^2$. If $N$ is odd, then one of $a$ and $b$ must be even and the other odd, because odd squares are $1 mod 4$ and even squares are $0 mod 4$. That means $a^2+b^2$ is often $1 mod 4$ or $2 mod 4, depending on the values.
A stronger argument uses modular arithmetic. Any square is congruent to either $0$ or $1$ modulo $4$. So the sum of two squares can only be congruent to $0$, $1$, or $2$ modulo $4$. It can never be $3 mod 4. This tells us that numbers like $3$, $7$, $11$, and $15$ are impossible as sums of two squares, because they are all $3 mod 4.
This is only a first clue, though. Not every number that is not $3 mod 4 is automatically a sum of two squares. For example, $14 mod 4=2$, and indeed $14=1^2+ \text{not a square}$? Actually, $14$ is not a sum of two integer squares. The reason is that its prime factorization is $14=$2 \times 7$$, and $7$ is a prime of the form $4k+3$ appearing once. So modular arithmetic gives a necessary condition, but prime factorization gives the full answer.
This connection is one of the best examples of how Diophantine equations use both algebra and number theory. You are not just solving an equation; you are studying the structure of integers. ✨
Sums of three squares
Now let’s look at sums of three squares: numbers of the form $a^2+b^2+c^2$. This problem is different from two squares and has its own famous rule.
A number can be written as a sum of three squares unless it has the form $N=4^k(8m+7)$ for integers $k \ge 0$ and $m \ge 0$. Numbers of this form are exactly the ones that cannot be expressed as a sum of three squares.
Examples:
- $7=4^0(8\cdot 0+7)$, so $7$ cannot be written as a sum of three squares.
- $15=4^0(8\cdot 1+7)$, so $15$ cannot be written as a sum of three squares.
- $28=4^1(8\cdot 0+7)$, so $28$ also cannot be written as a sum of three squares.
- $29$ is not of that form, and indeed $29=2^2+3^2+4^2$.
This result shows how the same number can behave differently depending on how many squares you allow. For example, $7$ is impossible as a sum of two squares and also impossible as a sum of three squares, but it can be written as a sum of four squares: $7=2^2+1^2+1^2+1^2$.
The three-square theorem is important because it gives a complete classification. If you are given a number, you can test whether it fits the forbidden pattern $4^k(8m+7)$. If it does, no three-square representation exists. If it does not, at least one representation does exist.
Examples and problem-solving strategies
When solving sums-of-squares problems, a few techniques are especially useful.
1. Check small squares first
If the number is not too large, list the squares less than it and test combinations.
Example: Can $18$ be written as a sum of two squares?
- Squares up to $18$ are $0,1,4,9,16.
- Try pairs: $18-16=2$ no, $18-9=9$ yes.
- So $18=3^2+3^2$.
2. Use modular arithmetic
Look at the number modulo $4$ or modulo $8$.
Example: Can $11$ be written as a sum of two squares?
- Since $11 \equiv 3 \pmod{4}$, it cannot be a sum of two squares.
- Also, $11=4^0(8\cdot 1+3)$, which is not the forbidden form for three squares, so it can be a sum of three squares.
- In fact, $11=1^2+1^2+3^2$.
3. Use prime factorization
This is the strongest tool for two squares.
Example: Can $65$ be written as a sum of two squares?
- Factor: $65=5 \times 13$.
- Both $5$ and $13$ are primes congruent to $1 mod 4.
- So $65$ should be a sum of two squares.
- Indeed, $65=1^2+8^2$.
4. Look for patterns with identities
Useful identities can create new sums of squares from old ones. For example:
$$
$(a^2+b^2)(c^2+d^2)=(ac-bd)^2+(ad+bc)^2.$
$$
This identity shows that the product of two sums of two squares is again a sum of two squares. That is why numbers like $65=5\times 13$ work: both factors are sums of two squares, and their product is too.
This kind of formula is powerful because it lets you build many examples from a few basic ones. It also explains why sums of squares are connected to multiplication, not just addition. 🧩
How this fits into Diophantine equations II
Sums of squares are a perfect example of the bigger theme in Diophantine Equations II. In this topic, the goal is not only to solve equations but to understand which integer solutions exist and why.
For sums of squares, the equation is usually something like $x^2+y^2=n$ or $x^2+y^2+z^2=n$, where $n$ is a given integer. The challenge is to determine whether integer solutions $x$, $y$, and $z$ exist. This connects to Pythagorean triples, where the equation $x^2+y^2=z^2$ describes right triangles with integer side lengths. In both cases, squares are combined in a structured way, and number theory provides the tools to study them.
The topic also shows the importance of proof. Instead of guessing, you use facts about primes, modular arithmetic, and factorization to make exact statements. That is why sums of squares is such an important part of classical number theory: it combines pattern spotting with rigorous reasoning.
Conclusion
Sums of squares is about finding integers that can be written as $a^2+b^2$, $a^2+b^2+c^2$, or more generally as sums of square numbers. The topic reveals deep patterns in the integers, especially through modular arithmetic and prime factorization. The two-square problem has a full classification using primes congruent to $3 \bmod 4$, and the three-square problem has a famous forbidden form $4^k(8m+7)$. These results are classic examples of Diophantine thinking because they ask which integers can appear in an equation and explain the structure behind the answers.
Study Notes
- A square is a number of the form $n^2$.
- A sum of squares is an expression like $a^2+b^2$ or $a^2+b^2+c^2$.
- The equation $x^2+y^2=n$ is a Diophantine equation because we seek integer solutions.
- A prime $p$ can be written as $p=a^2+b^2$ exactly when $p=2$ or $p \equiv 1 \pmod{4}$.
- If a prime $p \equiv 3 \pmod{4}$ appears to an odd power in the prime factorization of $n$, then $n$ cannot be written as a sum of two squares.
- A number can be written as a sum of three squares unless it has the form $4^k(8m+7)$.
- Modular arithmetic is useful because squares are only $0$ or $1$ modulo $4$.
- The identity $(a^2+b^2)(c^2+d^2)=(ac-bd)^2+(ad+bc)^2$ helps build new sums of two squares.
- Sums of squares connect directly to the larger study of Diophantine equations and integer patterns in Number Theory.
