Connection 1 of 4
Pad first, then slide
Padding builds a larger array before any filtering: the original pixels stay unchanged inside, and the border cells hold values chosen by a rule. With one cell on every side the 17 × 18 picture becomes 19 × 20. The window is anchored at its top-left cell in this padded array, so with a 3 × 3 kernel output (y, x) is centred on original pixel (y, x).
output[y][x] = Σₐ Σ_b K[a][b] · padded[y·Sh + a][x·Sw + b]Read it as: The usual unflipped weighted sum; some of the nine values may be supplied rather than observed.
Connection 2 of 4
One border response

With one cell of zero padding, the window centred on row 10, column 0 reads three supplied zeros (striped) and six original pixels; the products add up to 12.
With zero padding, the window centred on row 10, column 0 holds [0 8 8; 0 8 0; 0 0 4]. The filter [−1 0 1] on each row multiplies the supplied left column by −1, giving zeros, ignores the middle column, and adds the right column: 8 + 0 + 4 = 12. Over plain background further up the edge the same zeros produce 24, more than the unpadded maximum of 19.
(−1)·0 + 0·8 + 1·8 + (−1)·0 + 0·8 + 1·0 + (−1)·0 + 0·0 + 1·4 = 12Read it as: The left terms used supplied zeros, so this response depends on the padding rule.
Connection 3 of 4
Count window starts

A 5 × 6 crop has 3 × 4 window starts without padding and 5 × 6 with one cell on each side; the whole watermelon gives 15 × 16 and 17 × 18.
The output length along an axis is the number of places the window can start. The first start is 0; the last is the padded length minus the kernel size. Dividing that span by the stride, rounding down and adding one counts the starts. A 5 × 6 crop gives 3 × 4 without padding and 5 × 6 with one cell on each side.
out = ⌊(n + before + after − k) / s⌋ + 1Read it as: Padding enlarges the length before the kernel is subtracted; only then does the stride divide.
Connection 4 of 4
Same is a stated rule
SAME_UPPER aims for ⌈n / s⌉ outputs and puts any odd padding cell after the input. For five pixels and a four-wide kernel the total padding is (5 − 1)·1 + 4 − 5 = 3, split one before and two after, and the output is five wide. With stride 2 the same rule aims for three outputs, not five.
target = ⌈n / s⌉, total = max((target − 1)·s + k − n, 0), before = ⌊total / 2⌋Read it as: Name the convention: other libraries may place the odd cell before the input.
Connect it back to the picture
Padding changes the array the window slides over: it decides the output size together with the kernel and stride, and it decides the border responses through its rule. It does not observe the scene beyond the edge or make the filter reversible.
Full notation and technical reference
The expressions below collect the operations discussed above. You can return here when you want the compact notation.
output[y][x] = Σₐ Σ_b K[a][b] · padded[y·Sh + a][x·Sw + b]
out = ⌊(n + before + after − k) / s⌋ + 1, per axis
SAME_UPPER: target = ⌈n / s⌉, total = max((target − 1)·s + k − n, 0), before = ⌊total / 2⌋- Zero-based indices; the window is anchored at its top-left cell in the padded array; the kernel is not flipped (cross-correlation).
- Zero supplies 0; replicate copies the nearest edge pixel ([a, b, c] → [a, a, b, c, c]); reflect mirrors without repeating the edge ([a, b, c] → [b, a, b, c, b]).
- Same sizing is a named convention: SAME_UPPER puts the odd padding cell after the input, and aims for ⌈n / s⌉ outputs, not n, when the stride exceeds one.
Numerical reference
On the watermelon, the window centred on the edge pixel at row 10, column 0 with one cell of zero padding is [0 8 8; 0 8 0; 0 0 4]; with K = [−1 0 1; −1 0 1; −1 0 1] it gives 8 + 0 + 4 = 12. Replicate gives −4 and reflect 0. The 17 × 18 picture gives 15 × 16 without padding and 17 × 18 with it.
Where this explanation stops
Padded values are supplied, not observed: zero padding beside plain background creates a response of 24, larger than the unpadded maximum 19. Matching size does not preserve information or make the filter reversible. Dilation and transposed convolution are not covered.