A lot of optical illusions can be explained by Fermat's principle of least time, but why does light obey it? On a fundamental level, it all comes down to quantum mechanics, specifically quantum optics, where we use the famous "Feynman path integral formulation" to explain light through photons.