This paper is part of the special publication Developments in petrophysics (eds M.A. Lovell and P.K. Harvey). The in situ attenuation is computed through 2.1 km of the upper ocean crust in the vicinity of ODP Hole 504B on the southflank of the Costa Rica Rift in the eastern equatorial Pacific. The results strongly tie crustal properties to seismic measurables and observed geological structures; we find that the attenuation can be used to define seismic layer boundaries and is closely related to vertical heterogeneity. The in situ attenuation Q -1 consists of both intrinsic and scattering contributions, but is dominated by the scattering attenuation unless porosities are near zero, when it approaches typical estimates from seismic refraction studies. The attenuation is analytically modeled by multiple backscattering from heterogeneities observed in a sonic V(p) log and is found to decrease step-wise from Q=25 to Q>300 between the top of seismic layer 2A and a sharp discontinuity at 1.3 km depth. These changes correspond with heterogeneities at 1.0-1.3 m and at 10.0 m wavelengths that are associated with fracturing and the structure of pillow basalts and lava flows in seismic layers 2A and 2B. Although seismic velocity studies suggest that the layer 2-3 boundary also occurs at about 1.3 km, the large variation in Q (140 to 460) below this depth indicates that a seismically homogeneous layer 3 has not been reached in Hole 504B. From the observed results, we derive an empirical relationship between attenuation and porosity Q -1 = Q -10 e(β∅), where Q -10 = 0.004, β = 25, that may be applicable at other oceanic crust locations and useful for constraining seimic inversion models.