One short record
Two tones, 1000 Hz and 1250 Hz, play together. A converter samples them 8000 times a second and keeps N = 16 samples: a record 2 ms long. Can its spectrum show two tones, only 250 Hz apart?
The DFT turns 16 samples into 16 values X[k]. Bin k sits at k·fs/N, so the bins are fs/N = 500 Hz apart. The tallest is 1000 Hz (0.63); 1500 Hz reads 0.34. One bump, not two.
The 16 DFT values are samples of a smooth curve: the DTFT of this 16-sample record. Bins every 500 Hz are a coarse look. The 1250 Hz tone falls between bins 2 and 3, so no bin sits on it.
Zero-padding
Append 48 zeros so the list holds 64 values. That is zero-padding. The zeros carry no news about the tones: the real record is still 16 samples, 2 ms. But a 64-point DFT has bins every 125 Hz.
The 64 bins land exactly on the same curve, four times as dense. Now the top of the bump shows: bin 9 at 1125 Hz, height 0.70. Zero-padding interpolates the spectrum. It fills in between the old bins.
Pad to 1024 or a million points: the dots only trace this curve more finely. It has one hump, peak 1139 Hz. Each tone's lobe is 2·fs/N = 1000 Hz wide at its base, so tones 250 Hz apart blur together.
Real resolution
Two tones show as two peaks when they are about one lobe width apart: 250 Hz ≥ 2·fs/N. So N ≥ 2 × 8000 / 250 = 64 real samples, 8 ms of signal. Resolution comes from recording longer, not from zeros.
The converter keeps recording: 64 samples, 8 ms. The zeros are gone; every one of the 64 values is real signal. The DFT length is 64 again, so the bins are again 125 Hz apart.
Now the curve has two peaks. The bins at 1000 Hz and 1250 Hz read 0.50, with a dip to 0.00 at 1125 Hz between them. Same bin spacing as the padded DFT, but four times the data. White: the old curve.
In code
In numpy, np.fft.rfft(x, n=64) pads x with zeros to 64 points before the FFT. np.fft.rfftfreq(64, 1/fs) gives each bin's frequency: 0, 125, 250 ... 4000 Hz. Padding is one argument; resolution means recording longer.
The working
# step 1/10 · record
x[n] = cos(2π·1000·n/fs) + cos(2π·1250·n/fs)
fs = 8000 samples per second
N = 16 samples
record length = N / fs = 16 / 8000 s
= 2 ms
the two tones are 1250 − 1000 = 250 Hz apart
Every number is computed from this model: two tones of amplitude 1 at 1000 Hz and 1250 Hz, sampled at 8000 samples a second. Heights are |X| divided by the number of real samples, so a tone that stands alone reads 0.5. The plot stops at 2500 Hz; above it, up to fs/2 = 4000 Hz, there is only small ripple. "About one main-lobe width, 2·fs/N" is the rectangular-window rule from J. O. Smith's Spectral Audio Signal Processing. It is a rule of thumb: tapered windows (the Windowing lesson) trade a wider lobe for lower side lobes.