TIR occurs when light travels from a medium with a higher refractive index to one with a lower refractive index and strikes the interface at an angle greater than the critical angle. The critical angle can be determined using Snell's law, which relates the angles of incidence and refraction to the refractive indices of the two media.