$HfO_x$ films are increasingly under scrutiny for applications in resistive random-access memory (ReRAM) devices. $HfO_x$-based structures have a fast-switching speed, excellent stability, and can be easily integrated in complex devices. However, changes in crystal structure when current and voltage are applied are not well understood and are crucial to guide the rational design of $HfO_x$-based devices. To this end, a $TiN/HfO_x/TiN$ implemented in nanodevices was studied with in situ scanning transmission electron microscopy (STEM). We observed crystallization of the initially amorphous $HfO_x$ films and grain growth of crystals during repeating switching with increasing applied current and voltage. The formation and growth of crystalline region could then correlate to changes in measured conductance on the sample studied with in situ STEM. In situ electron energy loss spectroscopy (EELS) showed the depletion in oxygen of crystalline phases compared to the initial amorphous $HfO_x$ phase: This is due to the displacement of oxygen vacancies that concentrate in the crystalline grains and is the cause of the neuromorphic properties of the $HfO_x$ film. Oxygen migration toward the $TiN/HfO_x$ interface and the importance of crystallization at the interfaces are also discussed. The atomistic understanding of crystallization and structural changes of $HfO_x$ in $TiN/HfO_x/TiN$ can then be used to guide the rational design of multilayered materials for electronic applications.