Calculate the ring of integers of quadratic number field $\mathbb{Q}(\sqrt{d})$
Solution:
Let $F$ be an algebraic number field. Then an element $b\in F$ is integral iff its monic irreducible polynomial has integer coefficients.
For example, $\sqrt{d}$ for integer $d$ is integral.
If $d\equiv 1 \bmod 4$, then the monic irreducible polynomial of $(1+\sqrt{d})/2$ over $\mathbb{Q}$ is $x^2 -x + (1-d)/4 \in \mathbb{Z}[x]$, so $(1+\sqrt{d})/2$ is integral.
Thus the integral closure of $\mathbb{Z}$ in $\mathbb{Q}(\sqrt{d})$ contains the subring $\mathbb{Z}[\sqrt{d}]$, and the subring $\mathbb{Z}[(1+\sqrt{d})/2]$ if $d\equiv 1 \bmod 4$. We show that there are no other integral elements.
An element $a+b\sqrt{d}$ with rational $a$ and $b\neq0$ is integral iff its monic irreducible polynomial $x^2 -2ax +(a^2 -db^2)$ belongs to $\mathbb{Z}[x]$. Therefore, $2a$,$2b$ are integers. If $a=(2k+1)/2$, for $k\in\mathbb{Z}$, then it is easy to see that $a^2 - db^2 \in \mathbb{Z}$ iff $b=(2l+1)/2$ for some $l\in\mathbb{Z}$, and $(2k+1)^2 - d(2l+1)^2$ is divisible by $4$. The latter implies that $d$ is a quadratic residue modulo $4$, i.e. $d\equiv 1 \bmod 4$. In turn, if $d\equiv 1 \bmod 4$ then every element $(2k+1)/2 +(2l+1)\sqrt{d}/2$ is integral.
Thus, integral elements of $\mathbb{Q}(\sqrt{d})$ are equal to $\mathbb{Z}[\sqrt{d}]$ if $d\not \equiv 1 \bmod 4$, and $\mathbb{Z}[(1+\sqrt{d})/2]$ if $d\equiv 1 \bmod 4$.
Can someone explain why $\sqrt{d}$ for integer $d$ is integral, and why the monic irreducible polynomial of an integral element $a+b\sqrt{d}$ is of the form $x^2 -2ax +(a^2 -db^2)$?