Skip to content
ML Visualization

Convolution

Deep LearningIntermediate~7 min

ConvolutionConvolution slides a small grid of weights (a kernel) across an input, computing a weighted sum at every position. The same kernel is reused everywhere, so it detects one local pattern — an edge, a blob, a texture — wherever it appears in the image.

A convolution is a tiny stencil that slides across an image, and at every stop it multiplies-and-adds the pixels underneath it. Reuse one small kernel across the whole picture and you get a feature detector that finds its pattern anywhere — the core operation that makes CNNs see.

Input · the kernel window slides → Output feature map

Iteration 0 / 48
Kernel
Kernel weights
10-120-210-1

The same little grid of weights slides over every position, multiplying and adding the pixels underneath. An edge kernel lights up boundaries; a blur kernel averages them away — switch to Blur and watch the sharp rim it needs to detect dissolve.

The idea in plain words

A convolution is a tiny stencil — a small grid of weights called a kernel — that slides across an image. At every stop it multiplies the pixels underneath it by its weights and adds them up, writing one number into an output grid called a feature map.

The trick is that the same kernel is reused at every position. So a kernel that responds to a vertical edge finds vertical edges anywhere in the picture — this reuse is called weight sharing, and it’s what makes convolutional networks efficient. Swap the kernel and the same machinery becomes an edge detector, a sharpener, or a blur.

Now, the math

Each output pixel is the weighted sum of a small window of the input (cross-correlation, the operation CNNs actually use):

yr,c=ijKi,jxr+i,c+j+by_{r,c} = \sum_{i}\sum_{j} K_{i,j}\, x_{r+i,\,c+j} + b
xx
the input image (or previous feature map).
Ki,jK_{i,j}
the kernel weights — the same grid reused at every position.
yr,cy_{r,c}
one pixel of the output feature map.
bb
a bias added to every position.
Show the derivation

With a k×kk\times k kernel and no padding, an H×WH\times W input produces an (Hk+1)×(Wk+1)(H-k+1)\times(W-k+1) output — the kernel can’t hang off the edge, so the map shrinks by k1k-1. Adding a border of zeros (padding) keeps the size the same; taking bigger steps (stride) shrinks it faster. Because every output reuses one small set of weights, a convolution has far fewer parameters than a fully-connected layer over the same pixels.

Now Break It

Try this: A blur kernel on a sharp edge washes out the very structure the next layer needs.

Control: Kernel preset (switch to blur)

What happens: Wrong kernel! A blur smooths away the edges — the feature the next layer was counting on is gone.

Where convolution is used

Convolution is the workhorse behind almost everything computers do with images. Photo apps use learned kernels to sharpen, denoise, and blur; medical-imaging systems convolve scans to highlight tumors and fractures; self-driving cars run convolutions over camera frames to find lane lines and pedestrians. The same operation powers document scanning (detecting text edges), satellite analysis, and the first layers of every convolutional network that classifies or generates images.

A common misconception is that a convolution “looks at the whole image.” It does not — each output pixel only sees a tiny local window (the receptive field). Global understanding is built up by stacking convolutions, so deeper layers indirectly see more of the image. Another trap is confusing convolution with the fully-connected layers of an MLP: because a kernel reuses the same weights everywhere, it has far fewer parameters and — crucially — detects its pattern anywhere it appears, which a dense layer cannot do. Finally, note the sign convention: deep-learning “convolution” is really cross-correlation (no kernel flip), which is why the interactive slides the kernel without mirroring it.

Frequently asked questions

What is a kernel (or filter) in convolution?
A kernel is a small grid of weights — often 3×3 — that slides across the input. At each position it multiplies the pixels underneath it by its weights and sums them into one output value. The same kernel is reused at every position, so it acts as a detector for one specific local pattern, such as a vertical edge, wherever that pattern appears.
What is the difference between convolution and cross-correlation?
True mathematical convolution flips the kernel before sliding it; cross-correlation does not. Deep-learning frameworks actually implement cross-correlation but call it convolution. Since the kernel weights are learned, the flip makes no practical difference to what the network can represent, so the distinction rarely matters in practice.
What do padding and stride do?
Padding adds a border of zeros around the input so the kernel can sit over edge pixels; with the right padding the output stays the same size as the input instead of shrinking. Stride is how far the kernel jumps between positions — a stride of 2 skips every other position, halving the output size and reducing computation.
Why does the output feature map get smaller than the input?
Without padding, the kernel cannot hang off the edge of the image, so its center can only visit interior positions. A k×k kernel on an H×W input yields an (H−k+1)×(W−k+1) output — it shrinks by k−1 in each dimension. Padding with zeros restores the original size.
Why use convolution instead of a fully-connected layer for images?
Weight sharing. A convolution reuses one small set of weights across the whole image, so it has far fewer parameters than a dense layer wiring every pixel to every neuron, and it detects a feature regardless of where it appears. This makes it both efficient and translation-tolerant — properties a fully-connected layer lacks.

Written & reviewed by the ML Visualization team · Last updated .