(Background: In any category, an epimorphism is a morphism $f:X\to Y$ which is "surjective" in the following sense: for any two morphisms $g,h:Y\to Z$, if $g\circ f=h\circ f$, then $g=h$. Roughly, "any two functions on $Y$ that agree on the image of $X$ must agree." Even in categories where you have underlying sets, epimorphisms are not the same as surjections; for example, in the category of Hausdorff topological spaces, $f$ is an epimorphism if its image is dense.)

What do epimorphisms of (say commutative) rings look like? It's easy to verify that for any ideal $I$ in a ring $A$, the quotient map $A\to A/I$ is an epimorphism. It's also not hard to see that if $S\subset A$ is a multiplicative subset, then the localization $A\to S^{-1}A$ is an epimorphism. Here's a proof to whet your appetite.


  If $g,h:S^{-1}A\to B$ are two homomorphisms that agree on $A$, then for any element $s^{-1}a\in S^{-1}A$, we have
  $$g(s^{-1}a)=g(s)^{-1}g(a)=h(s)^{-1}h(a)=h(s^{-1}a)$$


Also, if $A\to B_i$ is a finite collection of epimorphisms, where the $B_i$ have disjoint support as $A$-modules, then $A\to\prod B_i$ is an epimorphism.

Is every epimorphism of rings some product of combinations of quotients and localizations? To put it another way, suppose $f: A\to B$ is an epimorphism of rings with no kernel which sends non-units to non-units and such that $B$ has no idempotents. Must $f$ be an isomorphism?

No, not every epimorphism of rings is a composition of localizations and surjections.
An epimorphism of commutative rings is the same thing as a monomorphism of affine schemes. Monomorphisms are not only embeddings, e.g., any localization is an epimorphism and the corresponding morphism of schemes is not a locally closed embedding.
Example: Let $C$ be the nodal affine cubic and let $X$ be its normalization. Pick any point $x$ above the node. Then $X\setminus\{x\}\to C$ is a monomorphism (see Proposition below). The corresponding homomorphism of rings is injective but not a localization.
Proposition (EGA IV 17.2.6): Let $f\colon X\to Y$ be a morphism locally of finite type between schemes. TFAE:

$f$ is a monomorphism.
Every fiber of $f$ is either an isomorphism or empty.

Incorrect remark from 2009: A flat epimorphism $A\to B$ is a localization if $A$ is normal and $\mathbb{Q}$-factorial. This is a result by D. Lazard and P. Samuel. [cf. Lazard, Autour de la platitude, IV, Prop 4.5]
Correction of this remark (May 2022):

A flat epimorphism $A\to B$ is a localization if $A$ is a normal noetherian domain with torsion class group. The result cited above proves this when $A$ is a Dedekind domain.
When $A$ is a Dedekind domain whose class group is not torsion, then there exists a flat epimorphism $A\to B$ of finite presentation (so an open immersion on Spec) which is not a localization [Lazard, Autour de la platitude, IV, Prop 4.6]. More generally, one can let $A$ be any normal domain whose Cartier class group is not torsion and let $\operatorname{Spec} B$ be the complement of a Cartier divisor $D$ whose class is not torsion.
The results 1-2 are best understood as follows. When $A$ is normal and locally $\mathbb{Q}$-factorial, then monomorphisms $A\to B$ correspond to subsets $U:=\operatorname{Spec} B\subseteq \operatorname{Spec} A$ such that $U$ is the complement of a, possibly infinite, union of irreducible divisors $\{D_i\}_{i\in I}$ [Raynaud, Un critère d’effectivité de descente, Cor. 2.7]. The complement of a Cartier divisor is always affine so it follows that $U$ is the intersection of the affine open subschemes $U_J$ where $J\subseteq I$ is finite and $U_J:=\operatorname{Spec} A\setminus \bigcup_{i\in J} D_i$. Equivalently, $B$ is the colimit (union if domain) of rings $B_J$ such that $A\to B_J$ is a monomorphism of finite type (an open immersion on Spec). When in addition $A$ has torsion class group, the $B_J$ are localizations (in one element) and it follows that $B$ is a localization.

Remark: There was a seminar on epimorphisms of rings directed by P. Samuel in 1967-68. Raynaud's paper is part of this as well as articles by Lazard that later went into his thesis Autour de la platitude.
