Introduction to Padding

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.

  • Without padding, output size decreases and edge information may be lost
  • Padding adds extra pixels to preserve spatial information and control output size
  • In Valid padding there is no padding, output shrinks
  • In Same padding output size remains equal to input

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. 

  • Adds extra pixels (usually zeros) around the input before convolution
  • Helps preserve spatial dimensions and avoid loss of edge information
  • Valid Padding: No padding is added, so output size is smaller
  • Same Padding: Padding is added to keep output size equal to input
  • Padding size depends on kernel size and desired output
  • Improves model performance but slightly increases computation cost

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.

  • Output size reduces after each convolution:(n - f + 1) \times (n - f + 1)
  • Example: 8×8 image with 3×3 filter gives 6×6 output
Padding in convulational neural network
Padding in convulational neural network 
  • Repeated convolutions shrink the image, limiting network depth
  • Corner pixels are used least (e.g., pixel A used once)
  • Edge pixels are used moderately (e.g., pixel B used a few times)
  • Middle pixels are used most (e.g., pixel C used multiple times)
  • Leads to loss of important border information
  • Causes imbalance in feature learning across the image

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 
  • Prevents shrinking of the image after convolution
  • If p is padding, then input size becomes: (n \times n) \rightarrow (n + 2p) \times (n + 2p)
  • Output size after convolution: (n + 2p - f + 1) \times (n + 2p - f + 1)

For example:

  • By adding one layer of padding to an (8 x 8) image and using a (3 x 3) filter we would get an (8 x 8) output after performing a convolution operation.
  • Increases contribution of border pixels by bringing them into computation
  • Helps preserve information at edges as well as in the center

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.

  • No padding is added to the input
  • Output size reduces after convolution
  • Removes border information during processing
  • Useful for dimensionality reduction and feature compression

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.

  • Adds padding to maintain input and output size
  • Preserves spatial information, especially at edges
  • Commonly used in deep networks to avoid shrinking feature maps

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

  • Preserves spatial dimensions of the input feature map
  • Retains important edge and border information
  • Allows deeper networks without rapid size reduction
  • Improves feature extraction across the entire image
  • Provides better control over output size

Limitations

  • Increases computational cost due to added pixels
  • May introduce artificial information (zeros) at borders
  • Can slightly affect feature learning near edges
  • Excessive padding may reduce model efficiency
Comment