Universal gravitation and the inverse square law
Every mass pulls on every other mass, and the pull weakens with the square of the distance between their centres, so moving twice as far away leaves only a quarter of the force, and three times as far leaves a ninth.
A worked example
Find the gravitational field strength at Earth's surface, using Earth's mass of 5.97 × 10²⁴ kg and its radius of 6.37 × 10⁶ m. The field is g = Gm ÷ r² = (6.67 × 10⁻¹¹)(5.97 × 10²⁴) ÷ (6.37 × 10⁶)² = 9.81 N/kg, which matches the measured acceleration of a falling object. Notice that the distance is measured from Earth's centre, because the planet attracts as though its entire mass were concentrated at that single point.
The mistake people actually make
The distance in the formula is measured between the centres of the two masses, not between their surfaces. A satellite orbiting 300 km above the ground is approximately 6.67 × 10⁶ m from Earth's centre, not 3.00 × 10⁵ m, so always add the planet's radius to the altitude before you square the distance.