Why does $M \mathbin{\otimes_R} N \cong M_\mathfrak{p} \mathbin{\otimes_{R_\mathfrak{p}}} N$? 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...
 A: Let $A,B$ be associative rings with $1$. Let $X$ be a right $A$-module, $Y$ an $(A,B)$-bimodule, and $Z$ a left $B$-module. Then the obvious functorial morphisms 
$$
(X\otimes_AY)\otimes_BZ \rightleftarrows X\otimes_A(Y\otimes_BZ)
$$ 
are inverse isomorphisms.
Here are two references: 


*

*Bourbaki, Algèbre, II.3.8, Proposition 8, p. 64.

*Cartan-Eilenberg, Homological algebra, II.5, Proposition 5.1, p. 27. 
EDIT. Cartan and Eilenberg don't really give a proof. It doesn't seem easy to find an online proof. So, I thought it might be worth writing such a proof here. I looked at Bourbaki's and Atiyah-MacDonald's proofs. The one below is closer to Atiyah-MacDonald, but I think things get more transparent when one zooms less on the objects themselves, and more on the functors they represent. 
Let $A$ and $C$ be rings, let $X$ be a right $A$-module, $Y$ an $(A,C)$-bimodule, and $Z$ a left $C$-module. We must show that there is a (unique) $\mathbb Z$-linear morphism 
$$
\left(X\ \underset{A}{\otimes}\ Y\right)\ \underset{C}{\otimes}\ Z\to 
X\ \underset{A}{\otimes}\ \left(Y\ \underset{C}{\otimes}\ Z\right)
$$ 
satisfying 
$$
(x\otimes y)\otimes z\mapsto x\otimes(y\otimes z).\tag1
$$ 
Let $M$ be a $\mathbb Z$-module. Let $B$ be the $\mathbb Z$-module of those $\mathbb Z$-bilinear maps
$$
b:\left(X\ \underset{A}{\otimes}\ Y\right)\times Z\to M
$$ 
which satisfy identically $b(\tau c,z)=b(\tau,cz)$, and let $T$ be the $\mathbb Z$-module of those $\mathbb Z$-trilinear maps
$$
t:X\times Y\times Z\to M
$$ 
which satisfy identically $t(xa,y,z)=t(x,ay,z)$ and $t(x,yc,z)=t(x,y,cz)$. 
Consider the $\mathbb Z$-linear map from $B$ to $T$ which attaches to $b$ in $B$ the element $t$ of $T$ defined by $t(x,y,z):=b(x\otimes y,z)$. 
Given a $t$ in $T$ we'll define an element $b$ in $B$ by a construction inverse to the one in the previous sentence. 
Pick a $z$ in $Z$, and form the $\mathbb Z$-bilinear map
$$
b_z:X\times Y\to M
$$ 
given by $b_z(x,y):=t(x,y,z)$. One checks that $b_z$ induces a $\mathbb Z$-linear map 
$$
\ell_z:X\ \underset{A}{\otimes}\ Y\to M,
$$ 
and that $b(\tau,z):=\ell_z(\tau)$ fits the bill. 
Put 
$$
F(X,Y,Z):=\left(X\ \underset{A}{\otimes}\ Y\right)\ \underset{C}{\otimes}\ Z,\quad 
G(X,Y,Z):=X\ \underset{A}{\otimes}\ \left(Y\ \underset{C}{\otimes}\ Z\right).
$$ 
The above observations provide a functorial isomorphism 
$$
\text{Hom}_{\mathbb Z}(F(X,Y,Z),?)\simeq\text{Hom}_{\mathbb Z}(G(X,Y,Z),?).
$$ 
Yoneda's Lemma gives then a functorial isomorphism $F\to G$, and one easily verifies that it satisfies (1).
A: 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 ).
