What are the integers $n$ such that $\mathbb{Z}[\sqrt{n}]$ is integrally closed? I was recently reading about integral ring extensions. One of the first examples given is that $\mathbb{Z}$ is integrally closed in its quotient field $\mathbb{Q}$. Another is that $\mathbb{Z}[\sqrt{5}]$ is not integrally closed in $\mathbb{Q}(\sqrt{5})$ since for example $(1+\sqrt{5})/2\in\mathbb{Q}[\sqrt{5}]$ is integral over $\mathbb{Z}$ as a root of $X^2-X-1$, but $(1+\sqrt{5})/2\notin\mathbb{Z}[\sqrt{5}]$.

Now I'm  curious, can we find what are all integers $n$ such that $\mathbb{Z}[\sqrt{n}]$ is integrally closed (equal to its integral closure in its quotient field)?

One thing I do know is that unique factorization domains are integrally closed, so I think rings like $\mathbb{Z}[\sqrt{-1}]$, $\mathbb{Z}[\sqrt{-2}]$, $\mathbb{Z}[\sqrt{2}]$ and $\mathbb{Z}[\sqrt{3}]$ are integrally closed, as they are Euclidean domains, and thus are UFDs. But can we say what all integers $n$ are such that $\mathbb{Z}[\sqrt{n}]$ is integrally closed? Thanks!

$\mathbb Z[\sqrt{n}]$ is integrally closed in $\mathbb Q(\sqrt{n})$ ($n\in\mathbb Z$, $n\neq1$) if and only if $n$ is square free and $n$ is not congruent to $1$ mod $4$ (or $n$ is a perfect square, in that case we have $\mathbb Z$ and $\mathbb Q$; thanks Arturo). 
Moreover, if $n\equiv1 \pmod 4$, then $\mathbb Z[\frac{1+\sqrt{n}}{2}]$ is integrally closed in $\mathbb Q(\sqrt{n})$. 
Sketch of proof of why $\mathbb Z[\sqrt{n}]$ is integrally closed in $\mathbb Q(\sqrt{n})$ for $n$ a square free number not congruent to $1$ modulo $4$. Let $\mathcal O$ be the set of integers numbers in $\mathbb Q(\sqrt{n})$. We can see that $\mathbb Z[\sqrt{n}]\subseteq\mathcal O$ (looking for suitable polynomials).
Let $\alpha=p+q\sqrt{n}\in\mathcal O-\mathbb Z$ with $p,q\in\mathbb Q$. $\alpha$ is a root of the polynomial
$$
f(x)=(x-\alpha)(x-\bar\alpha)=x^2-2px+(p^2-nq^2).
$$
But $f(x)$ is monic and of minimal degree (with coefficients in $\mathbb Q$), so it has to divide to the monic polynomial $g(x)\in\mathbb Z[x]$ which $g(\alpha)=0$. This implies that $f(x)\in\mathbb Z[x]$, thus $2p,\; p^2-mq^2\in\mathbb Z$. Now, you should prove that $p$ and $q$ are in $\mathbb Z$ since $n\equiv 2,3\pmod4$.
