Ring of Integers for $\mathbb{Z}[\sqrt{d}]$ I'm pretty sure this is a very basic thing, but my background is in physics and I have never previously done any number theory. 
We have as a theorem that for an algebraic number field $K$, $\alpha \in K$ is an algebraic integer if and only if its minimal polynomial in $\mathbb{Q}$ has coefficients in $\mathbb{Z}$. The minimum polynomial for $\alpha = a + b \sqrt{d}$ in the field $\mathbb{Q}[\sqrt{d}]$ is then: 
$$ (X - (a + b \sqrt{d}))(X - (a - b\sqrt{d})) = X^{2} - 2aX + (a^{2} - b^{2}d) $$ 
Therefore $\alpha$ is an algebraic integer $\iff 2a \in \mathbb{Z}, a^{2}-b^{2}d \in \mathbb{Z}$. 
Fine, but why is this claim true?
$$
    d = 2,3 \; \bmod \; 4 \implies \mathscr{O}_{\mathbb{Q}[\sqrt{d}]} = \mathbb{Z}[\sqrt{d}]  
$$
$$ d= 1\; \bmod \; 4 \implies \mathscr{O}_{\mathbb{Q}[\sqrt{d}]} = \mathbb{Z}
\bigg[\frac{1+\sqrt{d}}{2}\bigg]$$ 
Is this somehow related to the elementary theorem about when the sum of two squares is an integer? 
 A: You got $n=2a \in\Bbb Z$ and $a^2-db^2\in \Bbb Z.$  These imply $m=2b\in\mathbb Z$ and $n^2-dm^2\in\Bbb Z.$ $n^2$ and $m^2\equiv 0$ or $1\pmod4$. If $n^2\equiv dm^2\pmod4$ and $d\equiv2 $ or $3\pmod4$, the only solution is $n^2\equiv m^2\equiv0\pmod4$ so $n\equiv m\equiv 0\pmod2$ so $a, b \in\Bbb Z$.  If $d\equiv1\pmod4$ there is also the solution $n^2\equiv m^2\equiv1\pmod4$, in which case $a$ and $b$ are half odd integers. 
A: Yes, it is related to that result. If $a$ and $b$ are both rational numbers (not necessarily integers), and $d$ is an integer, then $a^2 - db^2$ is sure to be rational, but it may or may not be an integer.
If $a$ and $b$ are both halves of odd integers (call them $\alpha$ and $\beta$), and $d \equiv 1 \pmod 4$, it will happen that $$a^2 = \left(\frac{\alpha}{2}\right)^2 = \frac{\alpha^2}{4}$$ with $\alpha^2 \equiv 1 \pmod 4$, and likewise $$b^2 = \left(\frac{\beta}{2}\right)^2 = \frac{\beta^2}{4}$$ with $\beta^2 \equiv 1 \pmod 4$. Since $d \equiv 1 \pmod 4$ as well, we then have $$a^2 - db^2 = \frac{\alpha^2}{4} - \frac{d \beta^2}{4},$$ from which it obviously follows that $\alpha^2 - d \beta^2$ is a multiple of 4.
It often helps to work these things out with concrete examples. Since you mention a physics background, I'm going to assume you're well-versed in the arithmetic of complex numbers.
Try $d = -3$. Given the number $$\frac{-11}{2} + \frac{7 \sqrt{-3}}{2},$$ we readily see that the trace (the $2a$) is $-11$ and the norm (the $a^2 - db^2$) is 67. The relevant polynomial is then $x^2 + 11x + 67$.
Now try $d = -5$ and the number $$\frac{-11}{2} + \frac{7 \sqrt{-5}}{2}.$$ The trace is indeed $-11$ for this number as well, but the norm is... $$\frac{121}{4} + \frac{5 \times 49}{4} = \frac{183}{2},$$ and the polynomial is $2x^2 + 22x + 183$.
