A pencil dipped partially in water appears bent because of :
Snell's law gives the relation between angle of incidence and refraction and the Refractive index of the respective medium.
μ1sin(i)=μ2sin(r)
where, i, r are the angles of incidence and refraction respectively.