

We want to bring the z axis to z’ axis,
I)
we rotate around the positive z axis with angle $\varphi$ . The rotation matrix is:
$$R_z(\varphi)=\left[ \begin {array}{ccc} \cos \left( \varphi \right) &-\sin
\left( \varphi \right) &0\\ \sin \left( \varphi
\right) &\cos \left( \varphi \right) &0\\ 0&0&1
\end {array} \right]
$$
II)
we rotate around the y’ axis with angle $\vartheta$ . The rotation matrix is:
$$R_{y'}(\vartheta)=\left[ \begin {array}{ccc} \cos \left( \vartheta \right) &0&\sin
\left( \vartheta \right) \\ 0&1&0
\\ -\sin \left( \vartheta \right) &0&\cos \left(
\vartheta \right) \end {array} \right]
$$
III)
thus we get to picture III, now we can rotate about the z' axis with the angle $\psi$ the rotation matrix is :
$$R_{z'}(\psi)=\left[ \begin {array}{ccc} \cos \left( \psi \right) &-\sin \left(
\psi \right) &0\\ \sin \left( \psi \right) &\cos
\left( \psi \right) &0\\ 0&0&1\end {array} \right]
$$
thus the transformation matrix between body fixed coordinate system and inertial system is:
$$R=R_z(\varphi)\,R_{y'}(\vartheta)\,R_{z'}(\psi)\quad,R^{-1}=R^T$$
where $\varphi\,,\vartheta\,,\psi$ are the Euler angle
Remark
after the three rotation you get:
the x axis $\mapsto$ x' axis $\mapsto$ x'' axis.
the y axis $\mapsto$ y' axis $\mapsto$ y'' axis.
z axis $\mapsto$ z' axis
where
$x''\perp y''\perp z'$ are the body fixed coordinate system