Visual walkthrough — Stride, padding, and dilation
This is the flagship visual companion to Stride, padding, and dilation. If a symbol shows up, we draw it first.
Step 1 — A row of pixels is just a row of boxes
WHAT. Forget images for a moment. An input row is a line of numbered boxes. We will use a row of 7 boxes, labelled .
WHY. Convolution in 2D is the same counting problem done twice (once for width, once for height). If we nail the 1D row, the 2D formula is free. So we shrink the problem until it is countable on our fingers.
PICTURE. Look at the row below. The number under each box is its position index — its address. The red bracket marks the whole width, which we call (the "in" means input). Here .

Step 2 — The filter is a small window you slide
WHAT. A filter (or kernel) is a tiny window that covers boxes at once. We use : a window three boxes wide.
WHY. A neural net does not look at the whole row at once; it looks through a small window and slides it along, reading a few boxes at every stop. We must count how many stops the window can make. That count is the output width. So the very first thing we need is the window's own width, .
PICTURE. The red window below sits at the far left. Its left edge is at position ; because it is 3 wide, its right edge is at position . The window occupies boxes .

The matters: a 3-wide window starting at ends at , not . Count on your fingers — box , box , box : that is three boxes, last index .
Step 3 — How far right can the window go? The "slack"
WHAT. Slide the window right one box at a time. The window may move only while it still fits — its right edge must not fall off the row. The last legal left-edge position is where the right edge just touches the last box.
WHY. Every stop the window makes produces one output number. So the number of stops is the output width. To count stops we first find the farthest legal stop, then count everything from box up to it.
PICTURE. The red window has slid to its rightmost legal spot. Its right edge sits on box (the last box), so its left edge sits on box . The distance from the first left-edge (0) to the last left-edge (4) is the slack — the free room the window has to travel.

Right edge at last box means left edge at:
The slack is : left-edge can sit at — five positions.
Step 4 — Stride: don't stop at every box
WHAT. Stride is how many boxes we jump between stops. Stride stops everywhere; stride stops at every other box.
WHY. Stopping at every box is expensive and often redundant. Jumping by throws away stops to sample the row faster — this is downsampling. We now need: how many stops fit inside the slack if each jump is long?
PICTURE. Below, . The window starts at box (red), jumps to , then to . Positions and are skipped (greyed). Three stops survive: .

Number of jumps that fit in the slack:
Why divide by ? The slack is a distance; each jump eats boxes of it. Distance jump-length number of jumps. Exactly like "40 metres, 2 metres per step → 20 steps".
Step 5 — The : count the starting spot too
WHAT. The count of jumps is not the count of stops. Add one for the very first stop, which took no jump to reach.
WHY. This is the single most common error (the parent note flags it). "How many stops?" and "how many jumps?" differ by exactly one: the launch position is a stop you get for free.
PICTURE. Two jumps drawn as red arcs connect three red stops. Arcs: . Stops: . The lone starting box has no incoming arc — it is the .

Step 6 — Padding: glue on a margin first
WHAT. Padding adds extra boxes (usually zeros) on each side, before any sliding. Total added: .
WHY. Without padding, corner boxes are touched by the window only once, while middle boxes are touched many times — edges are under-represented, and the row shrinks every layer. Padding gives edges more visits and lets us control the output size.
PICTURE. The original 7 red boxes now have one white pad box on the left and one on the right. Effective width is . Everywhere appeared, it becomes .

- — padded width, the new box count
- — window still eats boxes → slack
- — jumps that fit
- — launch stop
Same-padding check. To keep the output equal to the input (), set : For : . Odd gives a whole-number ; even would force an uneven left/right pad.
Step 7 — Dilation: spread the window's teeth apart
WHAT. Dilation inserts empty gaps between neighbouring window slots. The window keeps only real slots, but its effective span stretches.
WHY. We want the window to see wider — capture far-apart context — without paying for more weights or stacking more layers. Dilation stretches the reach while the parameter count stays at .
PICTURE. A window with : real slots (red) sit on boxes , and the box between each pair (position and ) is a hollow gap. The window's span is now boxes even though it holds only weights.

Count the span: real slots, plus gaps between them, each gap boxes wide: For : .
Step 8 — Snap the pieces together
WHAT. Take the Step 6 formula and swap the plain for the span . That single swap absorbs dilation.
WHY. Padding changed the box count; stride changed the jump length; dilation changed the window span. Each edited exactly one symbol, so the master formula is just the counting story with three edits applied.
PICTURE. The full assembly line: padded row → stretched window slides by stride → count stops. Every symbol is labelled where it acts.

Full worked case ():
Step 9 — The edge cases (never leave a hole)
WHAT. Four scenarios that break naive counting.
WHY. A formula you cannot trust at the corners is a formula you cannot trust. We poke each degenerate input.
PICTURE. Four mini-panels: window bigger than row (no fit), exact fit (one stop), stride overshoots slack (floor rescues), collapse.

- Window too big (): numerator negative, . Zero (or fewer) valid stops — the window cannot fit even once. Legal answer: no output; add padding.
- Exact fit (): numerator , . The window fits in precisely one spot — one output box.
- Stride overshoots slack (e.g. slack , ): , so . The floor discards the illegal third stop that would hang off the edge — this is why we floor, not round.
- (no dilation): . The general law collapses to the plain-stride formula from Step 5 — consistency check passed.
The one-picture summary

This last figure is the whole derivation compressed: a padded row, a dilated window at its stretched span , red jump-arcs of length marching across the slack, and the surviving stops counted — jumps plus one.
Recall Feynman retelling — say it back in plain words
Imagine a strip of numbered boxes. First you tape a margin of boxes onto each end, so the strip is now long. You have a little window that grips boxes — but you spread its fingers apart with dilation , so its whole hand now spans boxes. You lay the window at the far left and slide it rightward, but you don't stop at every box: you leap boxes each time. You keep leaping only while the window still fits on the strip; the room it has to travel is the slack . Count the leaps that fit: . Then add one, because the spot you launched from was itself a stop. That final count is — the number of output boxes. Do this once for width, once for height, and you have every convolution output size there is.
Recall Quick self-test
Why is there a ? ::: The launch position is a stop you reach with zero jumps; jumps count arcs, stops count boxes, and boxes exceed arcs by one (fence-post rule). What does the floor protect against? ::: A partial jump that would push the window off the edge — an illegal stop — so we drop the fraction. With , what is ? ::: ; the general formula collapses to plain convolution. Why swap for but nothing else, when adding dilation? ::: Dilation only changes how wide the window spans; the fitting-and-counting logic is untouched.
See also: Receptive Field Analysis (why grows the field), Pooling Layers (stride's downsampling cousin), Semantic Segmentation Architectures (where dilation shines), Network Depth vs Width, and Convolutional Layer Basics.