The phase difference of an electromagnetic wave changes by 180° when reflected from a denser medium due to the boundary's behavior as a "hard boundary." This phenomenon is explained by the change in impedance and the need for continuity of electric and magnetic fields at the interface. When a wave crosses into a medium with a different phase velocity, a reflected wave is generated to maintain energy conservation, resulting in one of the fields being out of phase. Specifically, a wave reflects with a 180° phase shift when moving from a medium with a lower index of refraction to one with a higher index. Understanding this principle clarifies why reflections at boundaries with varying refractive indices exhibit different phase behaviors.