The escape velocity of an object in a gravitational field is the energy the object must acquire to escape the field. It us easiest to think of the object travelling radially outwards from the mass that causes the field.
The gravitational potential energy of an object of mass
$m$
a distance
$r$
from centre of a spherical mass
$M$
is
$GRAVITATIONAL \: POTENTIAL \: ENERGY=GPE=- \frac{GMm}{r}$
.
The body is given a speed is
$v_{ESCAPE}$
, just sufficient to escape the gravitational field, and have zero energy.
Then
$TOTAL \: ENERGY=KINETIC \: ENERGY + GPE=\frac{1}{2}mv^2_{ESCAPE}- \frac{GMm}{r^2} =0$
.
Rearranging gives
$v_{ESCAPE}= \sqrt{\frac{2GM}{r}}$
.
Suppose now that the particle is a photon. A photon is massless, but the same formula applies, with
$v_{ESCAPE}=c$
, the speed of light.
$c=\sqrt{\frac{2GM}{r}}$
. Rearranging again for
$r$
gives
$r=\frac{2GM}{c^2}$
.
This is an important concept. A mass
$M$
$r=\frac{2GM}{c^2}$