a window function
Look at the world through a porthole with sharp metal edges and the rim creates harsh glare; look through one whose glass fades gently to opaque at the rim and the view is softer. A window function does the same to a chunk of signal before you analyze it: instead of chopping out N samples with a hard rectangular cut, it fades the samples smoothly down to zero at both ends, so the analysis sees no jarring edge.
Mechanically, a window is just a fixed array of weights w_0, ..., w_{N-1} that you multiply your samples by, point for point, before taking the DFT. A rectangular window (all weights 1) does nothing — it is the hard cut that causes maximal leakage. The popular Hann window uses weights shaped like half a cosine bump, w_n = 0.5 * (1 - cos(2*pi*n/(N-1))), rising from 0 at the left edge to 1 in the middle and back to 0 at the right edge. Because the windowed data now tapers to zero at both ends, its periodic extension has no discontinuity, so spectral leakage is dramatically reduced. Other named windows — Hamming, Blackman, Kaiser, flat-top — each shape the taper differently to trade off two competing qualities: how narrow the main spectral lobe is (frequency resolution) and how low the side lobes are (leakage suppression).
Windowing is everyday practice in spectral analysis, but it is a genuine trade-off, not a pure gain. Tapering the edges throws away signal at the ends, which always WIDENS the main lobe — so you buy lower leakage with poorer ability to separate two close frequencies. A flat-top window measures a single tone's amplitude very accurately but blurs frequencies together; a rectangular window resolves frequencies finely but leaks badly. The right choice depends on whether you most need accurate amplitudes, fine frequency separation, or low leakage, and there is no single window that wins on all three.
Analyze a quiet 1000 Hz tone sitting next to a loud 1050 Hz tone. With a rectangular window the loud tone's leakage skirt drowns the quiet one. Switch to a Hann or Blackman window and the side lobes drop by tens of decibels, so the quiet tone reappears as its own peak — at the cost of slightly fatter peaks overall.
Tapering the edges trades wider peaks for far lower leakage.
There is no universally best window; each is a different compromise between main-lobe width and side-lobe level. Also, a window reduces the signal's total energy, so amplitude estimates need a correction factor for the window's gain.