Light bends when it passes between materials, by an amount fixed by a simple ratio. The rule governs every lens, every fibre optic cable and the appearance of a straw in a glass of water, and it was written down in Baghdad six centuries before the man it is named after.
Light travels at different speeds in different materials, slower in denser optical media. The ratio of its speed in vacuum to its speed in a material is that material's refractive index: about 1.33 for water, 1.5 for common glass, 2.4 for diamond.
When light crosses a boundary at an angle, the change in speed changes its direction. The standard analogy is a marching column crossing from pavement onto mud at an angle: the rank reaches the mud unevenly, one end slows first, and the column pivots.
The law states that the sine of the angle of incidence divided by the sine of the angle of refraction equals the ratio of the two refractive indices. Light entering a denser medium bends toward the perpendicular; leaving it, away.

Ibn Sahl, working in Baghdad, described the correct relationship in a manuscript on burning mirrors and lenses in 984. His formulation is geometric rather than trigonometric and is equivalent, and he used it to design lenses that focus without aberration.
The manuscript was identified and its significance recognised only in 1990, by Roshdi Rashed.
Thomas Harriot found the law in England around 1602 and did not publish. Willebrord Snellius derived it in 1621 and also did not publish; it appeared in his papers after his death.

Rene Descartes published it in 1637, and whether he had seen Snell's work was disputed at the time and remains unresolved. In France the relationship is generally called Descartes' law, and in some accounts the Snell-Descartes law, which is a reasonable compromise that leaves out the person who had it first.
Pierre de Fermat gave the principle in 1662: light takes the path requiring the least time between two points.
That is not the shortest path. If part of the journey is through a slower medium, the quickest route bends to spend less distance in it, exactly as a lifeguard running along sand and then swimming should enter the water at an angle rather than heading straight at the swimmer.
Fermat's principle yields the law directly, and it is a striking result: a local rule about bending at a surface follows from a global statement about the whole path.
The deeper explanation came with wave optics and later with quantum electrodynamics, in which the path of least time is where contributions from all possible paths reinforce rather than cancel. Richard Feynman used this as his standard illustration of how quantum mechanics reproduces classical optics.
Light leaving a denser medium bends away from the perpendicular, and beyond a certain angle it cannot leave at all: it reflects entirely back inside.
This is total internal reflection, and it is not partial. Unlike a mirror, which absorbs a few percent at every bounce, the reflection is complete, which is what makes long-distance optical transmission possible.
Optical fibre is a glass core surrounded by cladding of slightly lower refractive index. Light entering within the acceptance angle strikes the boundary beyond the critical angle and reflects along the fibre, bouncing thousands of times per metre with negligible loss. A modern fibre loses a small fraction of its signal over tens of kilometres.
Essentially all long-distance internet traffic travels this way. The submarine cables carrying intercontinental data are bundles of glass strands operating on a principle described in the eleventh century.
Lenses. A curved boundary refracts different parts of a beam by different amounts, bringing them to a focus. Every camera, telescope, microscope and pair of spectacles is an application, and the eye's cornea does most of its focusing.
Rainbows. Sunlight enters a raindrop, refracts, reflects off the back, and refracts again on leaving. Refractive index varies slightly with wavelength, so the colours emerge at slightly different angles, spreading into an arc.
Mirages. Air near hot ground is less dense and has a lower refractive index, so light from the sky curves upward toward the eye and appears to come from the ground, looking like water.
The bent straw. The straw is straight and the light from its submerged part refracts on leaving the water, so the brain, which assumes light travels in straight lines, places it wrongly.
Diamond's brilliance. Its very high refractive index gives a small critical angle, so light entering the top reflects internally many times before leaving, and cuts are designed around exactly this.