I'm reading the book $\textit{The Geometry of Schemes}$ and am a bit confused about the definition of the structure sheaf of an affine scheme.
For a ring $R$, we define the $\textit{distinguished open sets}$ of $X=\text{Spec}R$ to be the sets $$X_f= \text{Spec}R-V(f)=\{p \in \text{Spec}R : f \not\in p \}.$$
To define a sheaf $\mathcal{O}$ on $X$, we assign to each $X_f$ the ring $R_f$, i.e. the localization of $R$ at the element $f$.
Now the book says that if $X_g \subseteq X_f$, we have $g^n \in (f)$, for some integer $n$. Why is that?
Also, for the morphisms, the book says to define $$\text{res}_{X_f, X_g}: R_f \to R_{gf}=R_g$$ as the localization map. What does this mean? I'm mostly confused about the terminology here (what is the localization map?).
If $X_g \subset X_f$ then $V(f) \subset V(g)$. So, every prime ideal that contains $f$ also contains $g$, hence $g \in \sqrt{(f)}$. It means there exist some $n$ such that $g^n \in (f)$.
(Edit: leibnewtz has pointed out a typo in the definition of the map)
Let's say $g^n = fh$, for some $h \in R$. The restriction map is just the map $R_f \to R_g$ that sends $\frac{a}{f^k} \in R_f$ to $\frac{ah^k}{g^{nk}} \in R_g$.
It's quite straightforward to check that this map is in fact well defined and satisfies the composition requirement.