Let $X$ be compact Hausdorff topological space. Consider the ring $C(X)$ of continuous functions $X \rightarrow \mathbb C$ (we do not consider the C* algebra structure, just consider $C(X)$ as a ring) and its (purely algebraic) spectrum $\text{Spec}(C(X))$. There is a injective continuous map $X \rightarrow \text{Spec}(C(X))$ sending $x$ to the maximal ideal $\mathfrak m_x = \{f \in C(X) : f(x) = 0\}$. Under which conditions on $X$ is this map surjective? Under which conditions is it a homeomorphism to its image?

1$\begingroup$ By "compact" I assume you mean "compact Hausdorff", as otherwise the map you describe may not be injective. $\endgroup$ – Eric Wofsey Feb 27 '15 at 0:38

1$\begingroup$ By "Spec" you mean the collection of prime (not maximal) ideals, right? Otherwise, I think the map should always be surjective. $\endgroup$ – John Binder Feb 27 '15 at 1:38

$\begingroup$ Yes, I indeed meant compact Hausdorff (I now added the Hausdorff in the question.). With "Spec" I meant the space of all prime ideals with the Zariski topology. $\endgroup$ – Jens Reinhold Feb 27 '15 at 1:58

3$\begingroup$ Questions of this nature were studied intensively in the 40's and 50's of the previous century. A celebrated and definitive survey is in "Rings of continuos functions" by Gillman and Jerison. Of interest to you would be the concept of real compactness. $\endgroup$ – weather Feb 27 '15 at 9:30

1$\begingroup$ @AlexM. The Zariski topology, which exists on $\mathrm{Spec}$ of any commutative ring without the need for a topology on the ring. $\endgroup$ – David E Speyer Feb 27 '15 at 16:52
The map $i:X\to\operatorname{Spec}(C(X))$ is a homeomorphism onto its image iff $X$ is completely regular; this is essentially the definition of complete regularity. However, it is very rarely surjective.
Indeed, suppose $X$ is completely regular and $i:X\to\operatorname{Spec}(C(X))$ is surjective and hence a homeomorphism. Then for any $f\in C(X)$, the subset $D(f)\subset\operatorname{Spec}(C(X))$ of prime ideals that do not contain $f$ is compact, being naturally homeomorphic to $\operatorname{Spec}(C(X)_f)$. But this means that every cozero subset of $X$ is compact and thus clopen. It follows easily that $X$ must be finite. More generally, a similar argument shows that if the spectrum of a ring is Hausdorff, it must be totally disconnected.
Note, however, that for $X$ compact Hausdorff, the image of $i$ is exactly the maximal ideals of $C(X)$: the closure of any proper ideal is proper since every function sufficiently close to $1$ is invertible, so every maximal ideal is closed. Furthermore, any prime ideal is contained in a unique maximal ideal: for any two points $x,y\in X$, we can find functions $f,g\in C(X)$ such that $fg=0$ but $f(x)\neq0$ and $g(y)\neq 0$, and so no prime can be contained in both $\mathfrak{m}_x$ and $\mathfrak{m}_y$. So in some sense, $X$ really isn't that far from being the same as $\operatorname{Spec}(C(X))$.
Edit: Here's an example of what these nonmaximal prime ideals might look like. Let $X$ be the 1point compactification of a countable discrete space and identify $C(X)$ with the ring of convergent sequences. Fix a nonprincipal ultrafilter $U$ on $\mathbb{N}$ and let $P$ be the set of sequences $(x_n)$ which converge to $0$ and for which $(n^kx_n)$ converges to $0$ with respect to $U$ for all $k$. Then I claim $P$ is a prime ideal (which is strictly contained in the maximal ideal corresponding to the point at infinity). It is easy to see it is an ideal; suppose $(x_n)\not\in P$ and $(y_n)\not\in P$. Then for $k$ sufficiently large, $(n^kx_n)$ and $(n^ky_n)$ both go to infinity with respect to $U$. It follows that for large $k$, $(n^{2k}x_ny_n)$ also goes to infinity with respect to $U$, and thus $(x_ny_n)\not\in P$.

1$\begingroup$ An interesting followup question is whether it is possible to construct nonmaximal primes in $C(X)$ without the axiom of choice. $\endgroup$ – Eric Wofsey Feb 27 '15 at 6:31