CNN Output Size Calculator — Conv, Pooling & Transposed Conv
Work out the exact output size of any Conv2d, pooling or ConvTranspose2d layer. Enter the input size, kernel, stride, padding and dilation to get H×W, the full (N, C, H, W) shape, parameters and FLOPs — plus a copy-ready PyTorch/Keras snippet. Uses the official PyTorch formulas, runs entirely in your browser.
How it works
Every convolution slides a kernel across the input and records one value per valid window position. The number of positions that fit is the output size. This tool implements the formulas exactly as published in the PyTorch layer documentation — nothing is estimated.
Convolution and pooling share one formula, applied independently to height and width:
H_out = floor( (H_in + 2·padding − dilation·(kernel − 1) − 1) / stride + 1 )
The dilation·(kernel − 1) term is the effective (dilated) kernel span. Pooling uses dilation 1 and keeps the channel count unchanged (C_out = C_in), while convolution sets C_out to the number of filters. With a pooling layer's ceil_mode on, the floor becomes a ceil; the calculator also applies PyTorch's rule that drops a trailing window which would start entirely inside the right-hand padding.
"same" and "valid" padding follow Keras/TensorFlow semantics. valid means no padding. same keeps the output equal to the input at stride 1 (padding = dilation·(kernel − 1) / 2) and gives ceil(H_in / stride) at larger strides. When the required total padding is odd, TensorFlow pads one side more than the other; the tool reports the correct output size and flags the asymmetry.
Transposed convolution (also called deconvolution or fractionally-strided convolution) reverses the spatial mapping and is used to upsample in GAN decoders and U-Net expansive paths:
H_out = (H_in − 1)·stride − 2·padding + dilation·(kernel − 1) + output_padding + 1
Parameters (groups = 1) are C_out·(C_in·kH·kW) + C_out, where the final term is the optional bias. Compute is reported as MACs (multiply-accumulates): for Conv2d, H_out·W_out·C_out·C_in·kH·kW per sample, with FLOPs ≈ 2 × MACs. Transposed conv is input-driven, so its MACs use H_in·W_in. The single-layer receptive fieldis dilation·(kernel − 1) + 1, and stack mode composes it across layers using the jump/receptive-field recurrence from Dumoulin & Visin.
Worked examples
Frequently asked questions
Sources & references
- PyTorch — torch.nn.Conv2d (output-size + dilation formula, parameters)
- PyTorch — torch.nn.ConvTranspose2d (transposed-conv formula, output_padding)
- PyTorch — torch.nn.MaxPool2d (pooling output size, ceil_mode)
- Dumoulin & Visin (2016) — A guide to convolution arithmetic for deep learning (arXiv:1603.07285)
- TensorFlow / Keras — Conv2D (same/valid padding semantics)
Formulas on this page were last cross-checked against the PyTorch documentation on 2026-07-04. The three worked-example output sizes (112, 56, 14) and the parameter/MAC figures reconcile exactly to the cited sources.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.