Skip to content
Calcrivo

CNN Output Shape Calculator

Calculate the output height/width of a convolutional or pooling layer from kernel size, padding, and stride.

Inputs

px
px
px
px

Output Size (H or W)

112px

Raw (Pre-Floor) Size

111.500

Step by step

  1. Raw size: (input − kernel + 2 × padding) ÷ stride

    (224 − 3 + 2 × 1) ÷ 2

    = 111.500

  2. Output size: ⌊raw size⌋ + 1

    ⌊111.500⌋ + 1

    = 112

How it works

Every convolutional or pooling layer transforms spatial dimensions according to: output_size = floor((input_size − kernel_size + 2 × padding) / stride) + 1. This formula applies independently to height and width, so square inputs/kernels give square outputs, while rectangular inputs require running the calculation separately for each dimension. Padding compensates for the kernel 'eating into' the input at the borders (with 'same' padding chosen so output size matches input size at stride 1), while stride greater than 1 downsamples the spatial resolution, commonly used to reduce feature map size progressively through a network.

Formula

output_size = floor((input_size - kernel_size + 2 * padding) / stride) + 1

W
Input spatial size (height or width)
K
Kernel size
P
Padding (pixels added to each side)
S
Stride

Frequently Asked Questions

What padding gives 'same' output size (at stride 1)?

For stride 1, choosing padding = (kernel_size − 1) / 2 (when kernel_size is odd) keeps the output size equal to the input size, which is the common 'same' padding convention in CNN architectures.

What happens if the output size formula gives a non-integer raw size?

The result is floored — any 'leftover' pixels at the edge that don't form a complete kernel window are simply dropped, which is standard behavior for convolution operations in frameworks like PyTorch and TensorFlow.

How do I compute the output shape for rectangular (non-square) inputs?

Apply the same formula separately using the height and its corresponding kernel/padding/stride values, then again for the width, since the two spatial dimensions are computed independently.

Does this formula also apply to pooling layers (MaxPool, AvgPool)?

Yes, pooling layers use the identical output-size formula as convolutions, just without learnable weights — a MaxPool with kernel=2, stride=2, padding=0 uses this same calculation to halve spatial dimensions.

You might also need