Formula Bro

Math and physics formulas, explained like you are new.


Convolution Output Size

In one sentence: This formula counts how many spots a small sliding window can land on across an image, so you know how wide a convolution layer’s output will be.

O=⌊W−K+2PS⌋+1O = \left\lfloor \frac{W - K + 2P}{S} \right\rfloor + 1

Read it out loud: “O equals the floor of W minus K plus 2 P, all divided by S, then plus 1. The floor means round down to a whole number, dropping any decimal part. O is the output size. W is the width of the input, K is the width of the sliding window, called the kernel, P is the padding added on each side, and S is the stride, how far the window jumps each time. The number 1 counts the very first position.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Pixels and image width

A pixel is one tiny dot of colored light in a picture. An image’s width is counted in pixels, so an image 32 pixels wide has 32 dots in each row. The formula works on one side of the image at a time, so the width WW is the count along one side.

Convolution layer and kernel

A neural network is a computer model built from stages called layers. A convolution layer is a layer that works on images. It slides a small grid of numbers, called a kernel, across the image. At each stop, it multiplies the kernel’s numbers by the pixels under it and adds the results. The kernel’s width is written KK. A 3×33 \times 3 kernel covers 3 pixels in each direction.

Padding

Padding adds extra pixels around the edge of the image before the window slides, usually filled with zeros. Padding of P=1P = 1 adds one pixel on the left and one on the right, so the image becomes 2P=22P = 2 pixels wider in total. The extra edge lets the window reach the border pixels.

Stride

The stride, written SS, is how many pixels the window jumps between stops. A stride of 1 moves it one pixel at a time, and a stride of 2 skips every other spot. A bigger stride means fewer stops, so the output becomes smaller.

The floor, which rounds down, ⌊x⌋\lfloor x \rfloor

The floor of a number, written ⌊x⌋\lfloor x \rfloor, is the largest whole number that is not bigger than xx. For a positive number, you drop the decimal part. So ⌊15.5⌋=15\lfloor 15.5 \rfloor = 15, and ⌊4⌋=4\lfloor 4 \rfloor = 4.

Feature map

A feature map is the grid of numbers that a convolution layer produces from its input. The output size OO is the number of values along one side of that grid. The next layer of the network receives the feature map, which is why the sizes must be tracked from layer to layer.

What each symbol means

SymbolMeaning

OO

The output size, the number of values the layer produces along one side of its output, such as the width. It is a whole number of positions, with no unit.

WW

The input size along the same side, which is the width of the image in pixels. A 32-pixel-wide image has W=32W = 32.

KK

The kernel size, the width of the sliding window in pixels. A 3 by 3 kernel has K=3K = 3.

PP

The padding, the number of extra pixels added to each side of the input, counted in pixels. P=1P = 1 adds one pixel on the left and one on the right.

SS

The stride, how many pixels the window jumps between stops, counted in pixels. S=1S = 1 moves the window one pixel at a time, and S=2S = 2 moves it two pixels at a time.

⌊x⌋\left\lfloor x \right\rfloor

The floor of xx: the largest whole number that is not greater than xx. It rounds down, so 15.515.5 becomes 1515, and any partial jump is dropped.

11

The number 1, added at the end to count the very first stop, the window’s starting position. It has no unit.

The formula piece by piece

WW

The input width, the room the layer has to work with, measured in pixels. Every calculation starts from this count.

W−KW - K

The room left after the window is placed. Subtracting KK takes away the window’s own width, so W−KW - K is how far the window can move past its starting position, counted in pixels.

W−K+2PW - K + 2P

Add the padding. Each side adds PP pixels, so the total extra room is 2P2P, and the room the window can use becomes W−K+2PW - K + 2P pixels.

W−K+2PS\frac{W - K + 2P}{S}

Divide by the stride to count the jumps. A jump of SS pixels uses up SS pixels of room, so the number of possible jumps is the room divided by SS. With W−K+2P=31W - K + 2P = 31 and S=2S = 2, that gives 15.515.5 jumps.

⌊W−K+2PS⌋\left\lfloor \frac{W - K + 2P}{S} \right\rfloor

Round down. A partial jump is not allowed, because the window would stick out past the edge of the padded image. So the floor keeps only the whole jumps.

O=⌊W−K+2PS⌋+1O = \left\lfloor \frac{W - K + 2P}{S} \right\rfloor + 1

The output size equals the number of whole jumps the window can make, plus one for the starting position. That is the whole formula in one sentence.

O=⌊W+2P−KS⌋+1O = \left\lfloor \frac{W + 2P - K}{S} \right\rfloor + 1

The same formula with the terms in another order. Textbooks often write it this way, and it gives exactly the same number as the form above.

What the formula is doing, and why

The input is the width WW of one side of the image, the window width KK, the padding PP on each side and the stride SS. The output is one number, OO: how many stops the window makes along that side. Each stop becomes one value in the output. The formula counts the stops without sliding the window one stop at a time.

Why W−K+2PW - K + 2P? The window must fit completely inside the padded image. The padded image is W+2PW + 2P pixels wide, and the window covers KK of them. The room left for the window to move is the padded width minus the window width, which is W+2P−KW + 2P - K. That is why padding appears twice: it adds room on both sides.

Why divide, round down and add 1? The stride SS decides how much room each jump uses, so dividing by SS counts the jumps. A jump that cannot be finished would stick out past the edge, so the floor drops it. Finally we add 1, because the window also has a first stop at the very start, before any jump is made.

Why do padding and stride matter? Padding keeps the edge pixels in play. With a stride of 1 and an odd kernel width, padding of P=K−12P = \frac{K - 1}{2} on each side keeps the output the same size as the input. A stride of 2 makes the window jump two pixels at a time, so the output is about half as wide and half as tall.

When it applies. The formula is for an ordinary convolution with one window size, applied to height and width separately. It does not cover dilated windows, which have gaps between their numbers, or transposed convolutions, which make the image bigger instead of smaller. Those need their own size rules.

An everyday picture

Think of a cardboard frame of fixed width that slides along a shelf, taking a snapshot at each stop. The frame may only stop where it fits entirely on the shelf. Padding is like adding a little extra shelf at each end. The stride is how far you slide between snapshots, and the number of snapshots is the output size.

Worked example: Output width of a 3 by 3 convolution on a 32-pixel image

A small picture, 32 pixels wide, goes into a convolution layer with a 3×33 \times 3 kernel, so K=3K = 3 pixels wide. The layer uses padding of P=1P = 1 pixel on each side and a stride of S=2S = 2. We want the width of the output, in pixels.

  1. Write down the inputs. The input width is W=32W = 32 pixels, the kernel width is K=3K = 3 pixels, the padding is P=1P = 1 pixel on each side, and the stride is S=2S = 2 pixels per jump. Every number is a count of pixels, so the answer will also be a count of pixels, with no unit conversion needed.
  2. Find the room for the window. Add the padding on both sides and subtract the window width: W−K+2P=32−3+2×1=31W - K + 2P = 32 - 3 + 2 \times 1 = 31. The padded picture is 32+2=3432 + 2 = 34 pixels wide, the window takes 3 of them, and 34−3=3134 - 3 = 31 pixels are left for it to move across.
  3. Divide by the stride to count the jumps. A jump of 2 pixels uses 2 pixels of that room, so the count is 312=15.5\frac{31}{2} = 15.5 jumps. The 0.5 is a partial jump, one that the window cannot finish inside the picture.
  4. Round down. The floor drops the partial jump: ⌊15.5⌋=15\lfloor 15.5 \rfloor = 15. A window that cannot fit completely is not used, so only 15 whole jumps count.
  5. Add 1 for the starting position. The window also stands at the very start, before any jump. So O=15+1=16O = 15 + 1 = 16. Counting the stops directly agrees: the window starts at pixels 0, 2, 4 and so on up to 30, which is 16 stops.
  6. Compare with a stride of 1. With the same padding and a stride of 1, the room is still 31, but each jump uses only 1 pixel, so 311+1=32\frac{31}{1} + 1 = 32. The output is the same width as the input, which is the usual way padding of 1 with a 3 by 3 kernel keeps the size.

Answer: The output is 16 pixels wide. The stride of 2 roughly halves the width, from 32 down to 16. With a stride of 1 and the same padding, the output would be 32 pixels wide, the same as the input.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

What is a kernel?

The small grid of weights that slides over the input. A 3×33 \times 3 kernel covers 3 pixels in each direction at every stop.

Does the formula work for height and width separately?

Yes. Apply it to the height and to the width on their own. If the input, kernel, padding and stride are the same in both directions, the output is square.

Why does a stride of 2 roughly halve the size?

Dividing by 2 halves the number of jumps the window can make, so the output is about half as wide and half as tall.

What if the result is not a whole number?

The floor rounds it down. The last partial window does not fit, so the formula does not count it.

Sources

  1. Convolutional neural network, Wikipedia
  2. Stanford CS231n, Convolutional Neural Networks notes
  3. Dumoulin and Visin, A guide to convolution arithmetic for deep learning (arXiv:1603.07285)

| All AI & ML formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: ai-ml/convolution-output-size.md.