SeeingML
Neural Networks & Deep Learning Guide 6 of 6 · tap to switch
✦ Interactive Visual Guide 9 min · 4 hands-on labs · Beginner friendly

Convolutional Neural Networks (CNNs)

See how sliding 3x3 magnifying filters, stride, padding, and pooling let neural networks recognize visual patterns anywhere in an image.

To your eyes, a photograph of a coffee mug is made of edges, curves, and handles. To a computer, it is a giant spreadsheet of pixel brightness numbers (1 = dark, 8 = bright white).

Instead of connecting every single pixel directly to every neuron, a Convolutional Neural Network (CNN) slides a tiny 3×3 magnifying glass step by step across the image. Inside that window sits a 3×3 pattern-spotting template of numbers called a filter (or kernel). At every stop, the CNN multiplies the 9 overlapping pixels by the 9 filter numbers and adds them up into a single score.

Collecting all of those scores into a new grid produces a feature map: the score grid showing exactly where that pattern (such as a vertical edge or a bright bar) lit up!

Pick an image pattern and a 3×3 filter below, then click any cell in the 4×4 Feature Map to slide the glowing purple 3×3 window across the input grid and watch the 9-pair arithmetic update live!

Interactive Lab 1: Slide a 3×3 Filter Across Pixels (Click Any Output Cell!)
Row 2, Col 2 → Score: +21
Image:
3×3 Filter:
6×6 Input Pixels (Purple = 3×3 Window)
1
1
1
8
8
8
1
1
1
8
8
8
1
1
1
8
8
8
1
1
1
8
8
8
1
1
1
8
8
8
1
1
1
8
8
8
1 = dark8 = bright
3×3 Filter (Kernel)
-1
0
+1
-1
0
+1
-1
0
+1
Multiply & sum 9 pairs ->
4×4 Feature Map (Click Any Cell!)
Green (+ match)0 (flat)Coral (- opposite edge)
Live 9-Pair Math for Row 2, Col 2+21 -> Strong Vertical Edge!
1×(-1)=-1
1×0=0
8×+1=+8
1×(-1)=-1
1×0=0
8×+1=+8
1×(-1)=-1
1×0=0
8×+1=+8
Sum of 9 matching products = +21 -> Strong Vertical Edge!
Vertical Edge Filter at Row 2, Col 2: Bright 8s lined up with the +1 side of the filter while dark 1s lined up with the -1 side, adding up to +21 (green match)! Click a flat area to see the score drop to 0.

The magical part of Deep Learning is that you never hand-design those 3×3 numbers: Backpropagation automatically learns the exact edge, corner, eye, and wheel filters needed from labeled images!


How CNN Convolutions Work: Stride & Zero Padding

Notice what happened above: sliding a 3×3 filter across a 6×6 image shrank the output to 4×4 because the filter cannot step off the edges! Stack 10 unpadded layers and your image vanishes to nothing.

Two simple knobs control the output grid size cleanly:

  • Zero Padding (P = 1) wraps a 1-pixel frame of zeros around the border so 3×3 filters inspect corner and edge pixels fairly. Because adding 1 cell on each side (+2 total) cancels the 2 border cells a 3×3 filter normally trims off, your output stays the exact same width and height (Same Padding), whether the input is 6×6 or 16×16.
  • Stride (S = 2) makes the filter hop 2 pixels per step instead of 1, neatly shrinking the grid in half!

Try the quick presets below or toggle Stride 1 versus Stride 2 to watch the dashed teal second filter step slide or jump across the grid while the output shape recalculates live!

Interactive Lab 2: Stride & Zero-Padding Geometry Calculator
Output Grid: 4 × 4 (Trimmed)
Quick Presets:
Input (6×6) + Zero Border (0) = 6×6 Grid
····································1st2nd (+1)
1st position2nd position (slides 1 cell right)
Output Feature Map (4×4 = 16 Scores)
1
2
Plain English: 6 wide minus 3 filter = 3 cells left -> 3 jumps of 1 + 1 start = 4
Formula: floor((6 + 2 × 0 - 3) / 1) + 1 = 4
6×6
Filter Size (K)
Zero Padding (P)
Step Size / Stride (S)
What is happening: Without zero padding (P = 0), the 3×3 filter cannot step past the border, trimming your 6×6 grid down to 4×4. Click "Keep Same Size (Pad 1, Step 1)" above to add a border of zeros and keep every cell!

Max Pooling: shrinking maps while ignoring tiny shifts

Once a convolutional layer spots an edge or a cat ear, you usually do not care whether that ear sat at pixel (14, 22) or (14, 23): you only care that an ear appeared in that neighborhood!

2×2 Max Pooling divides the feature map into non-overlapping 2×2 patches and keeps just the single loudest number inside each patch, shrinking the grid area by 4× (half as wide and half as tall). Click Shift Peaks 1 Pixel Right below to see why Max Pooling keeps the output 100% identical, and compare it with Average Pooling, which blends all 4 numbers together and softens sharp peaks!

Interactive Lab 3: 2×2 Max Pooling vs. Average Pooling
Watch the loud peaks (9 and 7) when you shift them 1 pixel right:
4×4 Feature Map (4 Colored 2×2 Zones, 16 Cells)
9
2
1
0
1
3
2
1
0
1
7
2
1
0
1
3
Original state: 9 sits at Col 1, 7 sits at Col 3
2×2 Max Output (4 Cells, 4× Smaller)
9
2
1
7
Top-left zone: max([9, 2, 1, 3]) = 9
Takeaway: Max Pooling keeps only the single loudest detection in each 2×2 patch (9, 2, 1, 7), shouting "Yes, this pattern appeared in this neighborhood!" Click "Shift Peaks 1 Pixel Right ->" above to see the output stay completely unchanged.

Why CNNs crushed dense MLPs on vision: Parameter Sharing

Still wondering why we cannot just flatten a photo into one giant 1D list of pixels and hand it to a plain Multi-Layer Perceptron (MLP)?

Because a CNN uses parameter sharing: it slides the exact same compact 3×3 templates across every part of the image instead of wiring a brand-new weight to every pixel location. Look at the exact weight count for a 32-filter 3×3 CNN layer reading a color (Red, Green, Blue) photo:

  • Each 3×3 filter looks at 9 pixels across all 3 RGB color channels plus 1 baseline offset: (3×3 grid × 3 RGB colors) + 1 baseline = 28 weights.
  • Multiply by 32 filters: 32 filters × (3×3 grid × 3 RGB colors + 1 baseline) = 896 shared weights!

Whether the photo is a tiny 28×28 color icon or a 512×512 HD photo, doubling the width and height adds zero extra weights to that CNN layer (the computer simply slides the same 32 templates across more spots). Click through the photo resolutions below to watch a single dense MLP layer explode past 200 Million weights, while our 32-filter 3×3 CNN stays frozen at 896 shared weights!

Interactive Lab 4: Why Dense MLPs Explode on Photos (Parameter Sharing!)
MLP needs 43,008× MORE weights!
Input size: 224×224 × 3 RGB = 150,528 color numbersLog-scale visual comparison (1,000× per tick)
Flattened Dense MLP Layer (256 neurons)38,535,168 weights
224×224 × 3 RGB × 256 neurons = 38,535,168 connection weights
3×3 Convolutional Layer (32 shared RGB filters)896 weights (Constant!)
32 × (3×3 × 3 + 1) = 896 shared weights (32 filters, each with 27 RGB weights + 1 baseline)
Note: Bars use a log scale so both fit on screen. On a linear bar for a 224×224 photo, the CNN bar would be 43,008× shorter (thinner than 1 pixel!).
Takeaway (224×224 (Standard Photo)): A dense MLP wires a separate weight to every single color value in the 224×224 grid, exploding to 38,535,168 weights in just ONE layer (and forgetting what a cat looks like if it shifts 5 pixels left!). A CNN shares the exact same 32 tiny 3×3 templates (896 weights total) across the entire image at every resolution!
See Multi-Channel 2D Convolution, Output Geometry & Receptive FieldsThesis / Reference

1. Multi-Channel Discrete 2D Cross-Correlation (LeCun et al., 1998): Given an input tensor X∈RCin×H×W\mathbf{X} \in \mathbb{R}^{C_{\text{in}} \times H \times W} (for example Cin=3C_{\text{in}} = 3 RGB channels) and CoutC_{\text{out}} learnable kernels K∈RCout×Cin×k×k\mathbf{K} \in \mathbb{R}^{C_{\text{out}} \times C_{\text{in}} \times k \times k} with bias bob_o, output feature map oo at spatial index (i,j)(i, j) computes:

Yo,i,j=bo+∑c=1Cin∑u=0k−1∑v=0k−1Ko,c,u,v Xc, i⋅S+u−P, j⋅S+v−P\mathbf{Y}_{o, i, j} = b_o + \sum_{c=1}^{C_{\text{in}}} \sum_{u=0}^{k-1} \sum_{v=0}^{k-1} \mathbf{K}_{o, c, u, v}\,\mathbf{X}_{c,\, i \cdot S + u - P,\, j \cdot S + v - P}

Total learnable parameters equal strictly Cout⋅(Cin⋅k2+1)C_{\text{out}} \cdot (C_{\text{in}} \cdot k^2 + 1), completely independent of spatial resolution H×WH \times W!

2. Spatial Output Geometry & Translation Equivariance: With square input size NN, kernel KK, zero-padding PP, and stride SS:

Nout=⌊N+2P−KS⌋+1N_{\text{out}} = \left\lfloor \frac{N + 2P - K}{S} \right\rfloor + 1

Because the exact same filter slides across all coordinates, convolution is mathematically translation equivariant (shifting the input shifts the feature map identically), and stacking two 3×33\times 3 layers achieves the exact 5×55\times 5 receptive field of one 5×55\times 5 kernel using 28% fewer parameters (1818 vs. 2525) plus an extra non-linearity (VGG, Simonyan & Zisserman, 2015; ResNet, He et al., 2016; ConvNeXt, Liu et al., 2022).

See a Clean Modern CNN Classifier in PyTorchOptional Code
python
import torch.nn as nn

# Clean Conv -> BatchNorm -> ReLU -> Pool vision block
cnn = nn.Sequential(
  # Stage 1: 3 RGB channels -> 32 edge filters (Same Padding: k=3, p=1)
  nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, padding=1, bias=False),
  nn.BatchNorm2d(32),
  nn.ReLU(),
  nn.MaxPool2d(kernel_size=2),          # halves H and W

  # Stage 2: 32 edge maps -> 64 higher-level part detectors
  nn.Conv2d(32, 64, kernel_size=3, padding=1, bias=False),
  nn.BatchNorm2d(64),
  nn.ReLU(),
  nn.AdaptiveAvgPool2d((1, 1)),         # Global Average Pooling -> (B, 64, 1, 1)
  nn.Flatten(),
  nn.Linear(64, 10),                    # 10 class logits
)

Congratulations: you just completed Path 04!

Across Neural Networks & Deep Learning, you went from a single weighted Perceptron and ReLU/GELU activations all the way through Backpropagation, Gradient Descent with AdamW & Cosine Warmup, Dropout & Batch/Layer Normalization, and Convolutional Neural Networks!

Ready to see how Transformers, Self-Attention, LoRA, RAG, and AI Agents power modern LLMs? Continue straight into Path 05: Modern AI & LLMs (Tokenization & Word Embeddings) or browse the complete Visual Library.

✓ Self-Check

Quick Intuition Check

Four quick real-world scenarios. No scores, just test your intuition.

1

You slide a 3×3 filter across a 16×16 grid using a 1-pixel zero border (padding = 1) and moving 1 cell per step (stride = 1). What is the output grid size?

Pick an option first, or peek anytime
2

You double a color photo's resolution from 224×224 pixels up to 448×448 pixels. How many MORE learnable weights does a 32-filter 3×3 CNN layer need?

Pick an option first, or peek anytime
3

What two benefits does 2×2 Max Pooling deliver inside a Convolutional Neural Network?

Pick an option first, or peek anytime
4

In a modern CNN, engineers manually hard-code fixed numbers like [-1, 0, +1] inside every convolutional layer rather than letting Backpropagation learn the filter weights.

Pick an option first, or peek anytime
Quick Reference

Common Questions

What does a Convolutional Neural Network (CNN) filter actually do?
A CNN filter (kernel) is a small grid of learnable weights (usually 3x3) that slides across every patch of an image, multiplying overlapping pixels and summing them up. Early layers learn edge and colour filters; deeper layers combine those feature maps into textures, object parts, and full scenes.
Why are CNNs so much better than plain dense MLPs for images?
Flattening a 224x224 RGB image into a dense layer creates tens of millions of weights in a single layer and destroys 2D pixel neighborhood geometry. A CNN shares the exact same compact 3x3 kernels across the whole image, using thousands of times fewer weights and recognizing an object regardless of where it appears.
What is the CNN output size formula for Stride and Padding?
For an N x N input, K x K kernel, zero-padding P, and stride S, the output grid size is floor((N + 2P - K) / S) + 1. Setting K = 3, P = 1, S = 1 keeps the exact same width and height ('Same Padding'), while S = 2 halves spatial dimensions.
What is the purpose of Max Pooling in a CNN?
Max Pooling (commonly 2x2 with stride 2) keeps the strongest feature activation inside each small patch, slashing spatial memory and compute by 4x, expanding the receptive field of deeper layers, and making detections resilient to slight 1-pixel shifts.
Are CNNs still used now that Vision Transformers (ViTs) exist?
Absolutely! Modern CNN families like ConvNeXt and EfficientNet rival Vision Transformers in accuracy while running vastly faster on phones, medical devices, autonomous cars, and small-to-medium image datasets thanks to their strong built-in spatial inductive bias.

Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference

https://seeingml.com/learn/convolutional-neural-networks/ Open GitHub issue Suggest an edit
Cite this guide in a paper, thesis, or course (BibTeX & APA)
BibTeX
@misc{irshad2026convolutionalneuralnetworks,
  author       = {Irshad, Muhammad Aashir},
  title        = {Convolutional Neural Networks (CNNs): Interactive Visual Guide},
  howpublished = {SeeingML},
  year         = {2026},
  month        = {dec},
  url          = {https://seeingml.com/learn/convolutional-neural-networks/},
  note         = {Interactive visual guide}
}
APA

Irshad, M. A. (2026). Convolutional Neural Networks (CNNs): Interactive Visual Guide. SeeingML. https://seeingml.com/learn/convolutional-neural-networks/