An exact expression for the decay of the transverse magnetization of spins diffusing in a field (B0 + g1z + g2z)z reveals that a natural length scale l(c) = (8D /gamma-g2)1/4, and a frequency associated with it OMEGA-0 = 4D/l(c)2 govern the problem. Here D is the diffusion constant and gamma is the gyromagnetic ratio. l(c) is the size of the packet of magnetization at long times, i.e., OMEGA-0t >> 1. For porous media we estimate l(c) is-similar-to (R(p)l*)1/2 Where R(p) is the pore size and l*2 = D/DELTA-omega, where DELTA-w is the spread in Larmor frequency (inhomogeneous broadening). For typical experimental conditions, l* is-similar-to 3-mu-m; therefore in rocks the effects of the extrema of the magnetic field can be as important as the wall effects. To estimate finite-pore-size effects we localize the spins in a potential well of size R(p). We find that the effective pore size is l(c) or R(p), whichever is smaller. At short times, the magnetization density \M(z,t)\ is-similar-to exp[-D-gamma-2(g1 + 2g2z)2t3/3], i.e., it is permissible to use an effective local gradient. The magnetization decays rapidly where the magnetic field varies rapidly-thus the magnetization accumulates at the extremum of the field. At long times, the magnetization decays as exp(-OMEGA-0t/2), as opposed to exp(-t3), in a uniform gradient. The phase distribution is not Gaussian, which leads the decay rate OMEGA-0 is-similar-to square-root g2 to be a nonanalytic function of g2. There is an overall shift OMEGA-0/2 (the "g-shift") in the effective Larmor frequency, due to diffusion. The signal from a pulse-field-gradient experiment is similar to that of an isolated pore of size l(c). We compute the Hahn- and Carr-Purcell-Meiboom-Gill-(CPMG-) echo envelopes and find qualitative agreement with experimental data on porous media. Extracting g2 from the observed inhomogeneous broadening gives correct crossover times toward the linear regime. The slopes of the CPMG envelopes depend linearly on pulse spacing, as observed experimentally.