# A guide to convolution arithmetic for deep learning

Researchers derive output-size rules for convolution, pooling and transposed convolution

Vincent Dumoulin, Francesco Visin · arXiv · 2016-3-23

- **Problem** Convolution output shape depends on input size, kernel, padding and stride together, which is hard to work out by hand.
- **Method** The authors derive output-size formulas for each layer type, then rewrite each transposed convolution as an equivalent direct convolution.
- **Results** The authors show that a stride-1 transposed convolution equals a direct convolution with padding k − 1.

## Why layer shapes are hard to predict

Convolutional networks are central to modern deep learning, yet their layers are hard to reason about on paper. The output shape of a convolutional layer depends on the input shape, the kernel shape, the zero padding and the strides together. Fully-connected layers avoid this, because their output width stays fixed whatever the input size is.

Pooling adds a further layer of complexity, and transposed convolutions have spread across recent work. Their relation to ordinary convolutions has been explained with uneven clarity, which is the gap this guide targets.

The guide sets two aims: explain how convolutional layers relate to transposed convolutional layers, and give an intuitive picture of how input shape, kernel shape, padding, stride and output shape interact in convolution, pooling and transposed convolution. The results are kept independent of any framework, so they apply to Theano, Torch, TensorFlow and Caffe alike.

## Discrete convolution as a sliding kernel

The key idea is that one small kernel of weights slides over every position of the input, so each output unit depends on only a few inputs. This matters because images, sound and similar data have axes where order matters, while a plain affine layer treats all axes alike. A discrete convolution keeps that ordering, and it reuses the same weights at every location.

At each position the kernel elements are multiplied with the input elements they overlap, and the products are summed to give one output value. Repeating this with different kernels builds as many output feature maps as needed. With several input feature maps, each one is handled by its own kernel slice, and the results are added elementwise.

Stride sets how far the kernel moves between positions, and a larger stride is equivalent to keeping only some of the outputs. The guide keeps the name convolution even though signal processing separates it from cross-correlation, since the kernel is learned anyway.

## Output size with unit strides

The output size can be counted as the number of places the kernel can take along an axis. Each one-step move adds a position, and the starting position adds one more. With no padding and stride 1 this gives o = (i − k) + 1, so a 3×3 kernel over a 4×4 input yields a 2×2 output.

Padding adds p zeros on each side, which changes the effective input size from i to i + 2p. That gives o = (i − k) + 2p + 1 for stride 1. For example, a 4×4 kernel over a 5×5 input with p = 2 follows the same rule.

A common choice is half padding, which keeps the output equal to the input when k is odd. With k = 2n + 1, using p = ⌊k/2⌋ = n and stride 1 makes o = i. Figure 2.3 shows the case i = 5, k = 3 and p = 1.

Full padding goes the other way and grows the output. With p = k − 1 and stride 1, o = i + (k − 1). Every partial or complete overlap of the kernel with the input is counted, which is why this is called full padding. Figure 2.4 shows the case i = 5, k = 3 and p = 2.

## Strides and the floor function

With stride s, the kernel jumps by s between positions, so the number of steps is divided by s. The output size is the number of steps plus one, which gives o = ⌊(i − k)/s⌋ + 1 when there is no padding. The floor appears because the last jump can stop before the kernel reaches the far edge, leaving some input units unused.

Padding enters by replacing i with i + 2p, which gives the general case o = ⌊(i + 2p − k)/s⌋ + 1. Where i + 2p − k is a multiple of s, the floor makes several input sizes share one output size, and this happens only when s \> 1. Figure 2.6 uses i = 5 and Figure 2.7 uses i = 6, both with k = 3, s = 2 and p = 1, and they produce the same output size.

The authors note that this ambiguity doesn't affect convolutions but complicates transposed convolutions.

## Pooling reuses the same arithmetic

Pooling slides a window across the input and feeds its contents to a function, often the maximum or the average. Unlike a convolution, it replaces the weighted sum with that function, but the sliding geometry is the same. Because the geometry is shared, the convolution relations can be reused, and only the repeated function changes.

Pooling involves no zero padding, so the output size is o = ⌊(i − k)/s⌋ + 1 for any type of pooling. Figure 1.6 shows max pooling with a 3×3 window on a 5×5 input at 1×1 strides. Average pooling in Figure 1.5 uses the same geometry, but its outputs are means.

## Convolution as a matrix and its transpose

Unroll the input and output into vectors, and a convolution becomes a sparse matrix C whose non-zero entries are kernel weights. The backward pass multiplies the error by C transposed, so the same kernel supplies both passes.

A transposed convolution goes the other way, from 4 dimensions to 16 while keeping the same connectivity. It does this by swapping the forward and backward passes, so the forward step multiplies by C transposed. The same kernel defines a direct or a transposed convolution depending on which passes are used. Frameworks usually implement it as the gradient of a direct convolution with respect to that convolution's input.

The authors avoid the term deconvolution, since it denotes an inverse rather than this operation.

## Transposed convolution as a padded direct convolution

The simplest picture treats the transposed input as the output of some direct convolution, and asks for the shape of the original map. A 3×3 kernel over a 4×4 input with stride 1 gives a 2×2 output, so its transpose maps a 2×2 input to a 4×4 output.

The kernel and stride stay the same, but the transposed input is now zero padded. The padding is chosen so that the first kernel placement touches only the top-left pixel, which means padding equals kernel size minus one. The same reasoning gives Relationship 8, so with s = 1 and p = 0 the transposed padding is k − 1 and o′ = i′ + (k − 1).

This equivalent is much less efficient, since the zero multiplications are wasteful, and software normally skips them.

## Padded convolutions in transposed form

Since the transpose of an unpadded convolution behaves like a fully padded one, the transpose of a padded one should use less padding. Relationship 9 gives p′ = k − p − 1 and o′ = i′ + (k − 1) − 2p for stride 1. Figure 4.2 shows i = 5, k = 4 and p = 2, which is equivalent to a 4×4 kernel over a 6×6 input padded with a 1×1 border.

Half-padded convolutions have the same input and output size, so their transpose should also be half-padded. With k = 2n + 1, p = n and stride 1, the transposed version keeps p′ = p and o′ = i′. Figure 4.3 covers i = 5, k = 3 and p = 1.

The transpose of a fully padded convolution is an unpadded one. With p = k − 1 and stride 1, the transposed padding is zero and o′ = i′ − (k − 1). Figure 4.4 gives i = 5, k = 3 and p = 2, equivalent to a 3×3 kernel over a 7×7 input without padding.

## Strided transposed convolutions

Figure 4.5 shows i = 5, k = 3 and s = 2 with no padding. Its equivalent is a 3×3 kernel over a 2×2 input with one zero inserted between units, padded by a 2×2 border.

Relationship 12 covers p = 0 and i − k a multiple of s. In Figure 4.5 the stretched input has size 3 for an original input of size 2.

With padding p, Relationship 13 requires i + 2p − k to be a multiple of s, with p′ = k − p − 1 and o′ = s(i′ − 1) + k − 2p.

Its output size is o′ = s(i′ − 1) + a + k − 2p. Figure 4.7 applies this to i = 6, k = 3, s = 2 and p = 1, with a = 1.

## Dilated convolutions widen the kernel

A dilated kernel inserts spaces between its elements, controlled by a dilation rate d. Usually d − 1 spaces go between kernel elements, so d = 1 gives an ordinary convolution. This widens the receptive field without adding weights, which helps when several dilated layers are stacked. The authors point to WaveNet, which uses such layers to condition raw audio on a long past context.

The effective kernel size is k + (k − 1)(d − 1), and substituting it into the formula gives Relationship 15. Relationship 15 reads o = ⌊(i + 2p − k − (k − 1)(d − 1))/s⌋ + 1. Figure 5.1 shows a 3×3 kernel over a 7×7 input with d = 2, s = 1 and p = 0.

## Limits of the analysis

The derivations use 2-D convolutions with square inputs, square kernels, and equal stride and padding along both axes. The authors state that the results carry over to N-D and non-square cases, but the worked examples all use the square 2-D setting.

A transposed convolution isn't the inverse of a convolution, so it doesn't recover the original input. It only returns a feature map with the same width and height. Emulating it with a direct convolution is always possible but needs many zero rows and columns, which makes it much less efficient.

The guide reports no benchmark numbers, and its figures are worked examples of the output-size formulas.

## Paper info

- **Authors**: Vincent Dumoulin, Francesco Visin
- **Venue**: arXiv · Preprint
- **First published**: 2016-3-23
- **Added**: 2026-11-12
- **Updated**: 2018-1-11
- **Version**: v2
- **arXiv**: 1603.07285
- **Category**: stat.ML · cs.LG · cs.NE
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1603.07285v2) · [PDF ↗](https://arxiv.org/pdf/1603.07285v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Vincent Dumoulin, Francesco Visin (2016). A guide to convolution arithmetic for deep learning. arXiv:1603.07285v2. https://arxiv.org/abs/1603.07285v2

**BibTeX**

```
@misc{dumoulin2016guide,
  title = {{A guide to convolution arithmetic for deep learning}},
  author = {Vincent Dumoulin and Francesco Visin},
  year = {2016},
  eprint = {1603.07285},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1603.07285v2}
}
```

## Related papers

- [Unlocking Noise-Resistant Vision: Key Architectural Secrets for Robust Models Against Gaussian Noise](https://refivu.com/en/papers/9fe8e470-936c-4fac-810d-ab4f5fb89aeb-unlocking-noise-resistant-vision-key-architectural-secrets.md)
- [An Introduction to Convolutional Neural Networks](https://refivu.com/en/papers/6b236b8c-8750-484a-8c31-87433f51f2eb-an-introduction-to-convolutional-neural-networks.md)
- [Brain Tumor Segmentation with Deep Neural Networks](https://refivu.com/en/papers/f8979d44-9f07-47e9-978e-db57b4a732e6-brain-tumor-segmentation-with-deep-neural-networks.md)
- [When Random Saliency Looks Trained: Architectural Center Bias in CNN Interpretability](https://refivu.com/en/papers/dedacf70-34e7-40a0-b505-6e9e917d078c-when-random-saliency-looks-trained-architectural-center-bias.md)
- [A Neural Algorithm of Artistic Style](https://refivu.com/en/papers/7a83cd1c-7f82-4bea-8cb3-b9282fec51d7-a-neural-algorithm-of-artistic-style.md)
- [Advanced Steel Microstructural Classification by Deep Learning Methods](https://refivu.com/en/papers/40557ea6-2c03-4d59-8884-5b126f8414d1-advanced-steel-microstructural-classification-by-deep.md)

## Other paper commentary

- [Explainable Artificial Intelligence: Understanding, Visualizing and Interpreting Deep Learning Models](https://refivu.com/en/papers/6bd22a78-4fb3-465f-b297-2113b18ee3f2-explainable-artificial-intelligence-understanding.md)
- [SCA-CNN: Spatial and Channel-wise Attention in Convolutional Networks for Image Captioning](https://refivu.com/en/papers/51e17bf0-d47d-4aca-8ce3-e07e4204a821-sca-cnn-spatial-and-channel-wise-attention-in.md)
- [Attention Gated Networks: Learning to Leverage Salient Regions in Medical Images](https://refivu.com/en/papers/63b212b7-3fc0-42f4-b6d8-1724e918c784-attention-gated-networks-learning-to-leverage-salient.md)
- [Deeper Depth Prediction with Fully Convolutional Residual Networks](https://refivu.com/en/papers/4ef3d92a-82ea-4f76-8b77-ec72d726dd77-deeper-depth-prediction-with-fully-convolutional-residual.md)
- [ResNeSt: Split-Attention Networks](https://refivu.com/en/papers/7bce75cd-ce67-4d10-8c3b-89c0b6a895bd-resnest-split-attention-networks.md)
- [A Time Series is Worth 64 Words: Long-term Forecasting with Transformers](https://refivu.com/en/papers/15822929-13f1-40c7-8503-ce263dcf1639-a-time-series-is-worth-64-words-long.md)
- [Semantic Similarity in a Taxonomy: An Information-Based Measure and its Application to Problems of Ambiguity in Natural Language](https://refivu.com/en/papers/2aedc905-eee8-4237-bf2e-929c6d3718a0-semantic-similarity-in-a-taxonomy-an-information-based.md)
- [Activation Functions: Comparison of trends in Practice and Research for Deep Learning](https://refivu.com/en/papers/b7691c32-6640-47d3-9dda-c4586bd48272-activation-functions-comparison-of-trends-in-practice-and.md)
- [Learning Hand-Eye Coordination for Robotic Grasping with Deep Learning and Large-Scale Data Collection](https://refivu.com/en/papers/7027eeb7-fc1d-48f5-a7af-9efbaa9ad813-learning-hand-eye-coordination-for-robotic-grasping-with.md)
- [Conditional Prompt Learning for Vision-Language Models](https://refivu.com/en/papers/aafdc9ad-313a-44a6-bed9-42556a8097ea-conditional-prompt-learning-for-vision-language-models.md)
- [Imagen Video: High Definition Video Generation with Diffusion Models](https://refivu.com/en/papers/79ba3745-980d-44fe-a5b0-70a6fbd0bc66-imagen-video-high-definition-video-generation-with-diffusion.md)
- [Unsupervised Data Augmentation for Consistency Training](https://refivu.com/en/papers/7940975d-f8e6-4178-9d29-c4dc7f994398-unsupervised-data-augmentation-for-consistency-training.md)

## Terms in this paper

- [convolutional neural networks](https://refivu.com/en/terms/936419759d72-convolutional-neural-networks)
- [max pooling](https://refivu.com/en/terms/5fb6ec0ed2d6-max-pooling)
- [dilated convolution](https://refivu.com/en/terms/7c0300102517-dilated-convolution)
- [dilated convolutions](https://refivu.com/en/terms/4866e4b2f351-dilated-convolutions)
- [transposed convolution](https://refivu.com/en/terms/5345831f54b4-transposed-convolution)
- [zero padding](https://refivu.com/en/terms/9ba05b7fdd35-zero-padding)
- [Pooling](https://refivu.com/en/terms/01a8e69b59fd-pooling)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/7690e8f8-368e-4a59-a827-7093c4415777-a-guide-to-convolution-arithmetic-for-deep-learning)
