The inverse-square law of Newton's law of universal gravitation is used to calculate the attractive force acting on bodies, and their potential energy.
To calculate the potentialenergy gained or lost upon a distance change, the potential energy at the two distances must both be calculated and then one subtracted from the other. Note that the potential energy is always negative, because it is defined as 0 at an infinite separation.