When light passes from one medium to another that is optically less dense, eg. from glass to air, the ray is bent away from the normal. If the incident ray meets the surface at such an angle that the refracted ray must be bent away at an angle of more than 90 degrees, the light cannot emerge at all, and is totally internally reflected.