Nuclear magnetic resonance (NMR) has become a versatile tool for the evaluation of underground hydrocarbon reservoirs. Formation attributes such as rock porosity and rock pore size distributions, as well as the relative concentrations of water, oil and gas, can be inferred from subsurface NMR. The hydrogen NMR signal encodes porosity as amplitude, pore sizes as relaxation times and fluid properties asa mixture of relaxation and diffusion rates. The paper describes the basic operating principles for NMR on cable (wireline), NMR on a drill string (logging-while-drilling) and NMR for downhole fluid sampling. The geometry of the borehole requires a magnet that projects its field into the surrounding rock, implying a grossly inhomogeneous field distribution. Experience shows that even under these circumstances, saturation-recovery and Carr-Purcell-Meiboom-Gill sequences can work well and yield meaningful T~ and T 2 information.