The identity
$(a^2+b^2)(c^2+d^2)=(ac-bd)^2+(ad+bc)^2.$
has been known since ancient times. Of course, today we view this formula as expressing simply that the norm of complex numbers is multiplicative, i.e. $N((a+bi)(c+di))=N(a+bi)N(c+di).$
From this formula we see that the set $S$ of integers which are sums of two squares is closed under products. Thus it makes a lot of sense to ask ourselves which primes belong to $S$, for then all products of these primes will also belong to $S$. It will turn out that the primes in $S$ are precisely the primes of the form $4n+1$, as well as the prime $2$. This was claimed by Fermat and proven by Euler after years of effort.
In fact a better question is this: which elements of $S$ are irreducible with respect to their membership in $S$? In other words, which elements of $S$ cannot be written properly as the product of two elements of $S$? Obviously the primes in $S$ are irreducible in this sense, being irreducible in the wider sense. We can see immediately that squares of primes of the form $4n+3$ (which obviously belong to $S$) are also irreducible, and that together with the other primes, these are all the irreducible elements of $S$. With this information we can see easily that every element of $S$ can be uniquely written as a product of irreducible elements of $S$, thus leading to the following characterization of $S$:
An integer $n$ is the sum of two squares if and only if every prime of the form $4n+3$ which divides $n$ does so with even multiplicity.
All of this is of course intimately tied to factorization in $\mathbf{Z}[i]$: primes of the form $4n+1$ "split" as $p=a^2+b^2=(a+bi)(a-bi)$ where $a+bi$ and its conjugate are now irreducible in $\mathbb{Z}[i]$, the prime $2$ "ramifies" as $-i(1+i)^2$ and primes of the form $4n+3$ are "inert", remain prime. The elements of $S$ can be identified with the orbits of complex conjugation on $\text{Spec }\mathbf{Z}[i]$.