The basic idea behind is that nucleons with a spin also have a magnetic moment. Now when a small magnetic field is applied this magnetic moment could be aligned with the field or aligned against it. The energy of these two configurations is slightly different.

Now when you apply a radio frequency pulse of just the right frequency this causes transitions between these two energy states. This precisely defined frequency depends not only the nucleus but also the chemical atmosphere which the nucleus is in and by determining it you can make a lot of deductions.

In its early days NMR was done by applying a radio frequency pulse and constantly modifying its frequency till maximum absorption was observed. Nowadays with Fourier Transform NMR you just apply one pulse(Which might have a rectangular or Gaussian or some other frequency spread). Now you Fourier transform the observed signal and this lets you determine the frequency of maximum absorption.