The process begins with the preparation of a crystalline sample. When X-rays are directed at the crystal, they are scattered by the electrons within the atoms. This scattering creates a diffraction pattern that can be captured on a detector. By analyzing these patterns using mathematical algorithms, the electron density within the crystal can be reconstructed, revealing the positions of the atoms.