TITLE: Euclidean domain $\mathbb{Z}[\sqrt{d}]$
QUESTION [9 upvotes]: I am trying to generalized, for which integral values of $d$, 
$\mathbb{Z}[\sqrt{d}] = \{ a + b\sqrt{d} \vert a,b\in\mathbb{Z}\}$ is an Euclidean domain? 
I am interested specially in positive integral values of $d$.

REPLY [5 votes]: I just want to fill in a detail that was hinted at in Monstrous Moonshine's answer, which is too long for a comment.
If $d \equiv 1 \pmod 4$, then $\mathbb Z[\sqrt d]$ is certainly not an Euclidean domain. It suffices to try $\gcd(2, 1 + \sqrt d)$. Clearly both numbers are of even norm, and the latter has a norm with absolute value larger than the former, which suggests the former ought to be a divisor of the latter.
But $$\frac{1 + \sqrt d}{2} \not\in \mathbb Z[\sqrt d].$$ Worse, $1 + \sqrt d$ is probably irreducible, which would mean this domain does not have unique factorization.
However, $$N\left(\frac{1 + \sqrt d}{2}\right) = \left(\frac{1}{2}\right)^2 - \left(\frac{\sqrt d}{2}\right)^2 = \frac{1}{4} - \frac{d}{4} = \frac{1 - d}{4},$$ which is an integer because $d \equiv 1 \pmod 4$, so this number that does not look like an algebraic integer is in fact an algebraic integer.
So $\mathbb Z[\sqrt d]$ is not a "complete" domain of algebraic integers. "Lacks integral closure," is the technical term, I believe. If we broaden our view to this "larger" domain, which we can notate $\mathcal O_{\mathbb Q(\sqrt d)}$, then to solve $\gcd(2, 1 + \sqrt d)$ with $1 + \sqrt d = 2q + r$ so that $-4 < N(r) < 4$, we simply set $$q = \frac{1 + \sqrt d}{2}$$ and $r = 0$. Of course this does not guarantee that every pair of numbers in $\mathcal O_{\mathbb Q(\sqrt d)}$ can have its GCD resolved by the Euclidean algorithm with some Euclidean function, let alone the norm function specifically.

A concrete example: $\mathbb Z[\sqrt{21}]$. Then 2 has a norm of 4, and $1 + \sqrt{21}$ has a norm of $-20$, which in absolute value is greater than 4. We see that $$\frac{1 + \sqrt{21}}{2}$$ is an algebraic integer having a minimal polynomial of $x^2 - x - 5$ and a norm of $-5$, and that's clearly a divisor of $-20$.