Snell's Law says that light going into a lower index bends away from the normal. Tilt the ray more and more, and the refracted ray swings toward the surface. At one angle it skims right along the surface. Beyond that, there is no refracted ray at all.
🔑 Key idea
Going from a higher index $n_1$ to a lower index $n_2$, light at more than the critical angle $$\sin\theta_c = \frac{n_2}{n_1}$$ is totally reflected. It cannot happen going from a lower index into a higher one.
💡 Why it works
At the critical angle the refracted ray runs along the surface, $\theta_2 = 90^\circ$. Snell's law gives $n_1\sin\theta_c = n_2\sin 90^\circ = n_2$. For a bigger angle, Snell's law would need $\sin\theta_2 > 1$, which no angle has, so no light gets out: it all reflects. Going into a higher index, $\sin\theta_2 = \frac{n_1}{n_2}\sin\theta_1$ is always less than 1, so a refracted ray always exists.
Glass to air. Past the critical angle, about $42^\circ$ for glass, all of the light reflects.
⚠️ Common mistake
Expecting total internal reflection when light goes from air into glass. Light entering a higher index always bends toward the normal and always gets in (some also reflects). Check the order: total internal reflection needs $n_1 > n_2$, light trying to leave the denser material.
✏️ Worked example: Glass and air
Find the critical angle for glass ($n = 1.50$) in air.
$55^\circ > 48.8^\circ$, so the light is totally reflected back into the water.
This is why, looking up from under water, you see the sky only inside a circle overhead.
Answer: No: it is totally reflected
✏️ Worked example: Glass under water
Find the critical angle for light in glass ($n = 1.50$) meeting water ($n = 1.33$).
$\sin\theta_c = \dfrac{1.33}{1.50} = 0.887$.
$\theta_c = 62.5^\circ$. Closer indices give a larger critical angle, so it is harder to trap light.
Answer: $62.5^\circ$
Optical fibers trap light by total internal reflection, carrying internet signals across oceans. Diamond's small critical angle, about $24^\circ$, traps light inside a cut stone until it leaves through the top: that is its sparkle.