### Background


Recall that, given two commutative rings $A$ and $B$, the set of morphisms of rings $A\to B$ is in bijection with the set of morphisms of schemes $\mathrm{Spec}(B)\to\mathrm{Spec}(A)$. Furthermore, we know that Spec$(A)$ has a base of open affine subsets, the "basic" or "principal" open affines $D(f)$ for all $f\in A$. Furthermore, $D(f)\cong \mathrm{Spec}(A\_f)$ as schemes, and the inclusion $D(f)\hookrightarrow\mathrm{Spec}(A)$ corresponds to the localization map $A\to A\_f$.


But answers to a [recent MathOverflow question](https://mathoverflow.net/questions/7153/open-affine-subscheme-of-affine-scheme-which-is-not-principal) show that open affine subschemes of affine schemes can arise in other ways.




---


### Question


In order to try to make sense of the situation above, I'd like to know the following.



> 
> Given a commutative ring $A$, is there a "ring-theoretic" characterization of the ring homomorphisms $A\to B$ that realize $\mathrm{Spec}(B)$ as an open affine subscheme of $\mathrm{Spec}(A)$ (more precisely, those morphisms such that the induced map $\mathrm{Spec}(B)\to\mathrm{Spec}(A)$ is an open immersion)?
> 
> 
> 


Of course, "ring-theoretic" is a bit vague. Let's certainly avoid any tautological characterizations. I would prefer if an answer didn't make any reference to the Zariski topology (for instance, the morphisms $A\to A\_f$ make perfect sense without the Zariski topology), but I'm not sure whether that's reasonable.




---


**Update:** I received two great answers, thank you both! I chose the one that was closer to the kind of condition that I had in mind. But Dan Petersen's answer was also very interesting and unexpected.



Ring-theoretic characterization of open affines?
**Theorem 1**: Let $R$ be an integral domain with field of fractions $K$, and $R \to A$ a homomorphism. Then $Spec(A) \to Spec(R)$ is an open immersion if and only if $A=0$ or $R \to K$ factors through $R \to A$ (i.e. $A$ is birational over $R$) and $A$ is flat and of finite type over $R$.


Proof: Assume $Spec(A) \to Spec(R)$ is an open immersion and $A \neq 0$. It is known that open immersions are flat and of finite type. Thus the same is true vor $R \to A$. Now $R \to K$ is injective, thus also $A \to A \otimes\_R K$. In particular, $A \otimes\_R K \neq 0$. Open immersions are stable under base change, so that $Spec(A \otimes\_R K) \to Spec(K)$ is an open immersion. But since $Spec(K)$ has only one element and $Spec(A \otimes\_R K)$ is non-empty, it has to be an isomorphism, i.e. $K \to A \otimes\_R K$ is an isomorphism. Now $R \to A \to A \otimes\_R K \cong K$ is the desired factorization.


Of course, the converse is not as trivial. It is proven in the paper



> 
> Susumu Oda, On finitely generated birational flat extensions of integral domains
>  Annales mathématiques Blaise Pascal, 11 no. 1 (2004), p. 35-40
> 
> 
> 


It is available [online](http://ambp.cedram.org/item?id=AMBP_2004__11_1_35_0). In the section "Added in Proof." you can find some theorems concerning the general case without integral domains. In particular, it is remarked that in E.G.A. it is shown that


**Theorem 2**: $Spec(A) \to Spec(R)$ is an open immersion if and only if $R \to A$ is flat, of finite presentation and an epimorphism in the category of rings.


More generally, in EGA IV, 17.9.1 it is proven that a morphism of schemes is an open immersion if and only if it is flat, a (categorical) monomorphism and locally of finite presentation.


There are several descriptions of epimorphisms of rings (they don't have to be surjective), see [this](https://mathoverflow.net/questions/109/what-do-epimorphisms-of-commutative-rings-look-like) MO-question.


