Light is reflected when it changes in direction at a boundary between two different media, and the reflected light remains within the medium from which it originates.
Total internal reflection occurs when a ray of light strikes a boundary between two media at an angle larger than a "critical" angle relative to the normal to the boundary. If the refractive index of the medium of the far side of of the boundary is lower, no light pass through the boundary. It is all reflected within the same medium.
When a ray of light crosses at an angle from a rare to a dense medium, or vice versa (such as through an air-to-glass boundary or a glass-to-air boundary), it is refracted towards or away from the the normal. An everyday example of this can be seen by placing a straight rod in to a glass container filled with water. The rod will appear to bend as it passes through the surface of the water. The change in direction of a ray of light is caused by a change in the speed of propagation through the new medium. The phenomenon of refraction is not observed when a ray of light passes through a boundary normal to the surface (ie at right-angles to the boundary), but the phase velocity of the ray is changed.
Refraction is responsible for rainbows and for the manner in which white light is split, as it passes through a prism, in to the colours of the visible spectrum. Glass has a refractive index greater than that of air and, since the angle of refraction varies with the frequency of the various elements of the light (ie the colours), a phenomenon known as dispersion occurs. Components of the white light are therefore refracted at different angles and become visibly separated.
The phase velocity of a wave is the rate at which a particular frequency propagates through a medium. A change in the speed of propagation results in a change in direction (refraction) as can be seen in the animation. A similar change of speed of propagation, and hence direction, occurs as the wavefront passes from the dense-to-rare medium boundary.