Scientists can tell by observing the seismic waves that are recorded all over the surface of the earth from distant earthquakes. The seismic waves are reflected (bounced off) layers of different density, and they are refracted (bent) when they enter layers of different density.