It occurs when the incident ray surpasses the critical angle of the medium it is travelling into.
only occurs when light is travelling from a more optically dense medium into a less optically dense medium (e.g. from water into air).
As this happens the incident ray bends away from the normal as it passes into the less dense medium.
If the incident angle is increased enough there will come a point when the refracted ray lies parallel to the surface of the two medium. We call that angle of incidence the critical angle .
Any ray that surpasses that angle is reflected back into the original medium and we call this type of reflection Total Internal Reflection.