Modules / Deep Learning / Convolutional Layer

Strides in CNN

Visualize how stepping the kernel by multiple pixels (Strides) acts as an efficient downsampling mechanism in Neural Networks.

Overview

What is a Stride?

In a Convolutional Layer, a kernel (filter) slides across the input image to produce a feature map. The Stride specifies exactly how many pixels this kernel shifts each time it moves.

By default, the stride is 1. The kernel moves 1 pixel to the right, and when it reaches the end of a row, it moves 1 pixel down. But what if we tell the kernel to jump 2 or 3 pixels at a time? This is called strided convolution.

Stride Amount (S)

Output Size Formula

O = ⌊(W - K) / S⌋ + 1
O = ⌊(9 - 3) / 1⌋ + 1 = 7

Filter Kernel (K = 3)

Understanding Strides in CNNs

How taking bigger steps across an image reduces computational load and extracts higher-level features.

Why use larger strides? (Downsampling)

If you process a massive high-resolution image pixel-by-pixel, the resulting feature map will also be massive. This requires enormous amounts of memory and computational power.

By increasing the stride, the kernel skips over sections of the image. This dramatically shrinks the width and height of the resulting feature map. We call this downsampling. Downsampling forces the network to summarize local features (like corners or edges) into higher-level, broader concepts, making the network faster and more robust to slight shifts in the image.

How far the filter jumps

Stride is the step size the filter takes as it slides. Stride 1 moves one pixel at a time and looks at every possible position. Stride 2 skips every other position, halving the output in both dimensions.

out = floor( (in + 2×pad − kernel) / stride ) + 1

A 32×32 input with a 3×3 kernel and padding 1:

StrideOutputPositions computed
132×321,024
216×16256
311×11121
48×864

Stride 2 cuts the output area to a quarter, and therefore cuts the computation of every subsequent layer to a quarter as well. That compounding is why striding matters so much for cost.

What you gain and what you lose

Gained: computation and memory. Halving both spatial dimensions quarters the work. In a deep network the early layers are the expensive ones, because the maps are largest, so downsampling early is where the savings are.

Gained: receptive field. After a stride-2 layer, each subsequent filter covers twice as much of the original image per step. Striding is one of the two ways a network gets a wide enough view to see whole objects (depth is the other).

Lost: spatial precision. Positions are skipped, so fine detail is discarded and cannot be recovered. For classification that is usually acceptable — you want to know what, not exactly where. For segmentation and detection it is a real cost, and architectures work hard to recover the lost resolution.

Lost: shift stability. Striding makes the network's output depend slightly on where the object sits relative to the sampling grid. Shift an image by one pixel and a strided network can produce a noticeably different prediction, an effect that has been measured and named — aliasing from downsampling without a low-pass filter.

Strided convolution versus pooling

Both reduce spatial size, and modern practice has moved from one to the other.

 Max poolingStrided convolution
ParametersNoneLearned
What it keepsThe strongest response in each windowWhatever the filter learns to keep
CostVery cheapA convolution, so more
Used inVGG, older architecturesResNet and most modern designs

The argument for strided convolutions is that downsampling is a decision, and a learned decision is usually better than a fixed rule. The argument for pooling is simplicity and a small amount of built-in shift tolerance. In practice both work, and the difference is smaller than the architecture around them.

Global average pooling is a special case worth knowing: it collapses each feature map to a single number at the end of the network, replacing the flatten-and-dense head. It removes millions of parameters and makes the network accept any input size.

Guided Experiments with This Interactive

  1. Observe the Default (S = 1):

    Leave Stride at S = 1. Click Slide Window. Watch the red box (kernel) move smoothly, pixel by pixel, across the input. The output feature map is 7x7. It's a dense, highly detailed representation of the input.

  2. Jump by Two (S = 2):

    Select S = 2. Notice the Output canvas instantly shrinks to 4x4. Click Slide Window again. Now watch the red box literally skip every other pixel. Because it's taking larger steps, it requires fewer operations to cross the image, producing a smaller, summarized output.

  3. Aggressive Downsampling (S = 3):

    Select S = 3. The output shrinks to a tiny 3x3 grid. The kernel now only stops at 9 specific locations on the entire input board. This is incredibly fast to compute, but notice how "blocky" and low-resolution the resulting feature map has become.

  4. Check the Formula:

    Look at the formula box in the center. Notice the division operation: $(W - K) / S$. The larger the Stride ($S$) in the denominator, the drastically smaller the final Output ($O$) becomes. The $⌊ ⌋$ brackets mean we round down (floor) if the kernel doesn't fit perfectly at the end of a row.

The Universal Formula

Assuming Padding (P) is 0, the output dimension ($O$) is calculated as:

O = ⌊(W - K) / S⌋ + 1

  • W = Input width/height
  • K = Kernel size
  • S = Stride (step size)
  • ⌊ ⌋ = Floor (round down)

Where that leaves you

  • Stride = 1: Maximum detail, slow computation, large output map.
  • Stride > 1: Downsamples the spatial dimensions of the image.
  • Strides reduce the number of parameters and computations in a network.
  • Often used as an alternative to "Pooling" layers to reduce image size.

By manipulating strides, we force neural networks to transition from looking at individual pixels to recognizing high-level abstract shapes.

Going the other way: transposed convolution

Segmentation, super-resolution and generative models need to increase spatial size, and a stride of less than 1 is the idea — implemented as transposed convolution, sometimes misleadingly called deconvolution.

Conceptually it inserts zeros between the input pixels and then convolves, so a stride-2 transposed convolution doubles the resolution. The weights are learned, so the upsampling is adaptive rather than a fixed interpolation.

Its known weakness is checkerboard artefacts: when the kernel size is not divisible by the stride, some output positions receive contributions from more input positions than others, producing a visible grid pattern. Two fixes are standard — make the kernel size a multiple of the stride (4×4 with stride 2), or use nearest-neighbour upsampling followed by an ordinary convolution, which avoids the problem entirely and is now the more common choice.

Dilated convolution: reach without cost

There is a third way to widen the receptive field, distinct from both stride and depth. Dilated (or atrous) convolution spreads the filter's taps apart, so a 3×3 kernel with dilation 2 covers a 5×5 area while still using only nine weights.

The output size is unchanged, so nothing is downsampled and no resolution is lost. Stacking layers with dilations of 1, 2, 4 and 8 grows the receptive field exponentially while keeping full resolution throughout.

This is why dilated convolutions are standard in semantic segmentation (DeepLab) and in audio models such as WaveNet, where the network needs a very wide view of a long signal without throwing away detail.

Skipping positions, and what it costs

A stride is how far the kernel jumps between applications. It shrinks the output, cuts the compute quadratically, and throws away information that no later layer can recover.

example_01.pyNumPy
Output

Questions people ask

What stride should I use? 1 for the convolutions that extract features, 2 where you deliberately want to halve the resolution. Strides above 2 are rare outside the very first layer of some networks.

Why do some networks use stride 2 in the first layer? Because the input is large and the early layers are the most expensive. ResNet's first layer is a 7×7 convolution with stride 2, immediately followed by a stride-2 pool, cutting 224×224 to 56×56 before the real work begins.

Does stride affect the number of parameters? No. The filter is the same size; only how often it is applied changes.

Can stride be different per dimension? Yes — (2, 1) halves the height and preserves the width, which is used in spectrogram models where the two axes mean different things.

How do I recover resolution after striding? Transposed convolution or upsampling, usually combined with skip connections from earlier, higher-resolution layers — which is exactly what U-Net does.

Is striding the same as pooling? Both downsample. Pooling applies a fixed rule with no parameters; strided convolution learns what to keep.

Recap in one screen

  • Stride is how far the filter moves; stride 2 halves each spatial dimension and quarters the work.
  • Downsampling widens the receptive field and cuts cost, at the price of spatial precision.
  • Strided convolutions have largely replaced pooling because the reduction is learned.
  • Transposed convolution upsamples; watch for checkerboard artefacts, or upsample then convolve.
  • Dilated convolution widens the view without downsampling at all — the tool for segmentation and audio.

Recall check

0 of 3

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. What does this module say about “What is a Stride”?

  2. What does this module say about “Why use larger strides? (Downsampling)”?

  3. What does this module say about “How far the filter jumps”?

Cheat sheet

Strides in CNN

In a Convolutional Layer, a kernel (filter) slides across the input image to produce a feature map. The Stride specifies exactly how many pixels this kernel shifts each time it moves.

COMPUTER VISION · vizlearn.in/computer_vision/strides_in_cnn.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.