The Gravitational force between two objects is given by F=Gm1m2/d2, where d is the distance between the objects, m1 and m2 are their masses and G is the gravitational constant.
Newton showed that this formula is true not only for point masses, but also for spheres, assuming that r1+r2<d, where r1 and r2 are the radii of the spheres and d is the distance between their centers. It is a standard problem in classical mechanics texts. It also appears in electricity and magnetism, since an electrostatic field obeys the same inverse square law. Gauss’s law makes this quite simple to show.
For r<r1 (inside the surface of the body 1), only the portion of the mass inside of r contributes, assuming spherical symmetry. The portion with r>r1 cancels out. Again, you can easily show this from Gauss’s law.
If you want to determine the gravitational acceleration g at the surface of the Earth you can get a good value from the above formula and Newton’s Second law in the form F=m2g, with g=Gm1/d2=9.8 meters/sec2. Of course, the Earth and other celestial bodies are not perfect spheres. For most applications the deviations are not signficant. In a few cases (artificial satellites of the Earth, and, I think, our moon) they are noticeable. It is possible to deal with these deviations, but there is no simple formula. You have to know in detail how the Earth or whatever differs from a perfect sphere. Be prepared for multipole expansions and perturbation series! See a modern (post Sputnik) celestial mechanics book.