Light refracts (bends) as it travels at different speeds in different media. If light in a slow medium comes to a faster medium, the outgoing beam bends away from the normal to the boundary. Light coming from the slow medium could reach the boundary at an angle that made the refracted out going beam graze the surface of the boundary as it will always have a larger outgoing angle than the slower incoming beam. This is the critical angle. Any larger incoming angle from the slow medium causes the light tor reflect back into the slow medium. This is total internal reflection, the light can't get out of the slow medium. Light pipes work this way as well as optical fibers.