Introduction to Padding (original) (raw)

Last Updated : 13 May, 2026

Padding is used in convolution to preserve input size and avoid loss of border information. Since convolution reduces output size, adding extra pixels (usually zeros) helps retain edge details and control the output feature map size.

Padding in CNNs

Padding is a technique used to preserve the spatial dimensions of the input image after convolution operations on a feature map. Padding involves adding extra pixels around the border of the input feature map before convolution.

**Limitations of Convolution Without Padding

When convolution is applied without padding, it leads to loss of spatial information and uneven usage of pixels across the image.

Padding in convulational neural network

Padding in convulational neural network

**Effect Of Padding On Input Images

Padding adds layers of zeros around the input image to preserve its size and retain border information during convolution.

padding in convolutional network

padding in convolutional network

**For example:

Types of Padding

Padding is used to control the output size and preserve spatial information during convolution.

Valid Padding (No Padding)

Valid padding applies convolution without adding any extra pixels, so the output feature map becomes smaller than the input.

**Formula:

(n \times n) * (f \times f) \rightarrow (n - f + 1) \times (n - f + 1)

Same Padding

Same padding ensures that the output feature map has the same spatial dimensions as the input by adding zeros around the borders.

**Formula:

(n + 2p) \times (n + 2p) * (f \times f) \rightarrow (n \times n)

**Padding value depends on kernel size:

p = \frac{f - 1}{2}

Advantages

Limitations