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.

Stride Amount (S)

Output Size Formula

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

Filter Kernel (K = 3)

Overview

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

In this guide
  1. What is a Stride?
  2. Why use more strides? (Downsampling)
  3. How far the filter jumps
  4. What you gain and what you lose
  5. Strided convolution versus pooling
  6. Guided Experiments with This Interactive
  7. The Universal Formula
  8. Where that leaves you
  9. Going the other way: transposed convolution
  10. Dilated convolution: reach without cost
  11. Skipping positions, and what it costs
  12. Questions people ask
  13. Recap in one screen

Understanding Strides in CNNs

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

What is a Stride?

In a Convolutional Layer, a kernel (filter) slides across the input pic to give a feature map. The Stride names just 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. The output size follows the formula floor((input + 2*padding - kernel) / stride) + 1. So a stride of 2 roughly halves each spatial dimension and gives a feature map with one quarter the area. That reduction serves the same purpose as pooling — downsampling to capture more-scale features and reduce computation — but it does so inside the convolution it rather than in a split layer. Modern designs (ResNet, EfficientNet) often replace max-pooling with strided convolutions since the stride is a learned step (the filter weights are trained) while pooling discards information by a fixed rule. The tradeoff is that a more stride skips positions fully. So small features between steps are invisible to that layer. This page animates the kernel at other strides, shows the output dimensions updating live, and covers the interaction between stride and padding.

Why use more strides? (Downsampling)

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

By raising the stride, the kernel skips over sections of the pic. 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 more-level, broader concepts, making the network faster and more reliable to slight shifts in the pic.

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 each possible position. Stride 2 skips each 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 each later 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 costly ones, since the maps are largest. So downsampling early is where the savings are.

Gained: receptive field. After a stride-2 layer, each later filter covers twice as much of the first pic 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 often acceptable — you want to know what, not just where. For segmentation and detection it is a real cost. And designs 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 pic by one pixel and a strided network can give a noticeably other 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 often 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 gap is less than the design around them.

Global average pooling is a special case worth knowing: it collapses each feature map to a single count at the end of the network, replacing the flatten-and-dense head. It removes millions of params 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 form 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 each other pixel. Since it's taking more steps, it needs fewer steps to cross the pic, giving a less, summarized output.

  3. Aggressive Downsampling (S = 3):

    Select S = 3. The output shrinks to a tiny 3x3 grid. The kernel now just stops at 9 set locations on the whole input board. This is incredibly fast to compute. But notice how "blocky" and low-resolution the resulting feature map has turn.

  4. Check the Formula:

    Look at the formula box in the center. Notice the division step: $(W - K) / S$. The more the Stride ($S$) in the denominator, the drastically less the final Output ($O$) turns. 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: Max detail, slow computation, large output map.
  • Stride > 1: Downsamples the spatial dimensions of the pic.
  • Strides reduce the count of params and computations in a network.
  • Often used as an option to "Pooling" layers to reduce pic 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 nets need to increase spatial size. And a stride of less than 1 is the idea — built 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 get contributions from more input positions than others, giving 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. It avoids the problem fully 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 with just 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 nets such as WaveNet. There 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

Building on the same setup, the next block shows the left cases.

example_02.pyNumPy
Output

The next block covers the left steps.

example_03.pyNumPy
Output

The next block continues with the left demonstrations.

example_04.pyNumPy
Output

Building on the same setup, the next block shows the left cases.

example_05.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? Since the input is large and the early layers are the most costly. ResNet's first layer is a 7×7 convolution with stride 2, at once followed by a stride-2 pool, cutting 224×224 to 56×56 before the real work begins.

Does stride affect the count of params? No. The filter is the same size. Just how often it is applied changes.

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

How do I recover resolution after striding? Transposed convolution or upsampling, often mixed with skip connections from earlier, more-resolution layers — which is just what U-Net does.

Is striding the same as pooling? Both downsample. Pooling applies a fixed rule with no params. 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 since 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 more strides? (Downsampling)”?

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

Cheat sheet

Strides in CNN

Increase the stride from 1 to 2 and watch the feature map shrink to a quarter of its area in a single convolution step.

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.