When an object is thrown up into the air there is a battle between the object's kinetic energy and the gravitational pull on the object (its gravitational potential energy). If our object is to escape the gravitational pull of the Earth, its kinetic energy must balance the gravitational force acting upon it.
The kinetic energy = ½ mv2, where m is the mass of the object and v is its velocity.
The gravitational potential energy of an object = GmM/r, where G is the gravitational constant, m is the mass of the object, M is the mass of the Earth and r is the Earth's radius.
For a balance between kinetic energy and gravitational potential energy we must have:
½ mv2 = GmM/r
Doing simple algebra, we obtain our escape velocity formula:
Vesc = √ (2MG/r)
This formula can be applied to any object trying to escape from any other object.