An element of $\mathbb{R}[x]$ is a sum of two squares if it is nonnegative as a function on $\mathbb{R}$.  This can be seen by noting that its real roots have even multiplicity, its irreducible quadratic factors are of the form $(x-a)^2+b^2$, a product of sums of two squares is a sum of two squares, and a square times a sum of two squares is a sum of two squares.

See [Qiaochu's question on Hilbert's 17th problem][1] for what happens in more than one variable.


  [1]: https://mathoverflow.net/questions/8579/are-all-polynomial-inequalities-deducible-from-the-trivial-inequality