TITLE: Why does $M \mathbin{\otimes_R} N \cong M_\mathfrak{p} \mathbin{\otimes_{R_\mathfrak{p}}} N$?
QUESTION [9 upvotes]: Let $R$ be a commutative ring, $\mathfrak{p}$ a prime ideal of $R$, $M$ a $R$-module, and $N$ a $R_\mathfrak{p}$-module. Why do we have this isomorphism?
$$M \mathbin{\otimes_R} N \cong M_\mathfrak{p} \mathbin{\otimes_{R_\mathfrak{p}}} N$$
I can prove this by bare hands by taking one map to be defined by $m \otimes n \mapsto (m / 1) \otimes n$ and the other map by $(m / s) \otimes n \mapsto m \otimes (n / s)$. A little work is required to show that the latter is well-defined, but when that is done we have two mutually inverse $R$-linear (and $R_\mathfrak{p}$-linear) maps. But what is the conceptual reason for this isomorphism? Expanding the right hand side a bit, we see that we are saying
$$M \mathbin{\otimes_R} N \cong (M \mathbin{\otimes_R} R_\mathfrak{p}) \mathbin{\otimes_{R_\mathfrak{p}}} N$$
and expanding the left hand side, it seems that what we want to prove is
$$M \mathbin{\otimes_R} (R_\mathfrak{p} \otimes_{R_\mathfrak{p}} N) \cong (M \mathbin{\otimes_R} R_\mathfrak{p}) \mathbin{\otimes_{R_\mathfrak{p}}} N$$
but I see no reason why tensor products over different rings should associate like that...

REPLY [13 votes]: As often, a more general result is easier to understand.
So let us forget about localizations  and consider a morphism of commutative rings $\phi:A\to B$, an $A$-module $M$ and a $B$-module $N$.
Every $B$-module $T$ can also be considered as an $A$-module ("forgetful functor", "restriction of scalars"), which we will denote by $T_A$.  
We then have a canonical isomorphism of $A$-modules 
$$M\otimes_A (N_A )\stackrel {\sim} {\to} ((M\otimes_A B)\otimes_B N)_A                           $$  
sending 
$$m\otimes n \mapsto(m\otimes1)\otimes n            $$
which specializes to what you want.
The geometric picture  is that you have a morphism of affine schemes $f=\phi^*:Y=Spec(B)\to X=Spec(A)$, a quasi-coherent sheaf $\mathcal M=\tilde M$ on $X$ and a quasi-coherent sheaf $\mathcal N=\tilde N$ on $Y$.
The above isomorphism of modules translates into the isomorphism of sheaves of $\mathcal O_X$-Modules 
$$\mathcal M   \otimes_{\mathcal O_X} f_* \mathcal N   \stackrel {\sim} {\to} f_*(f^*\mathcal M   \otimes_{\mathcal O_Y}    \mathcal N)               $$ 
In algebraic geometry, this is called the  projection formula (it also appears in other contexts ).