Answer:
Earthquakes occur in the crust or upper mantle, which ranges from the earth's surface to about 800 kilometers deep (about 500 miles).
The strength of shaking from an earthquake diminishes with increasing distance from the earthquake's source, so the strength of shaking at the surface from an earthquake that occurs at 500km deep is considerably less than if the same earthquake had occurred at 20 km depth.
Also, the depths of earthquakes gives us important information about the Earth's structure and the tectonic setting where the earthquakes are occurring. The most prominent example of this is in subduction zones, where plates are colliding and one plate is being subducted beneath another. By carefully plotting the location and depth of earthquakes associated with a subduction zone, we can see details of the zone's structure, such as how steeply it is dipping, and if the down-going plate is planar or is bending. These details are important because they give us insight into the mechanics and characteristics of the deformation in the subduction zone.
Within continents, and along continental plate boundary transform faults such as the San Andreas, faults are only active in the shallow crust - perhaps to depths of approximately 20 km.
Accurately determining the depth of an earthquake is typically more challenging than determining its location, unless there happens to be a seismic station close and above the epicenter. So generally, errors on depth determinations are somewhat greater than on location determinations.