Definition
A Convolutional Neural Network (CNN) is a neural network that slides the same small set of learned filters across an image rather than wiring every pixel to every neuron. Reusing one set of weights at every position is the whole idea, and the arithmetic shows why it mattered.
A 224×224 colour image is 224 × 224 × 3 = 150,528 numbers. Feed it to a single fully connected layer of 1,000 units and that one layer needs just over 150 million weights, before the network has learned anything at all. A convolutional layer with 64 filters of size 3×3 needs 64 × 3 × 3 × 3 = 1,728 weights — and needs exactly that many whether the image is 224 pixels across or 4,000.
Cheapness is only half the benefit. A filter that has learned to respond to an edge responds to that edge anywhere in the frame, because it is the same filter applied at every position; a fully connected network would have to learn "edge in the top-left" and "edge in the bottom-right" as two unrelated facts, from separate examples. That built-in assumption — that what a patch means does not depend on where it sits — is why CNNs learn to see from far less data than a generic network, and equally why they are the wrong choice for data whose meaning is tied to absolute position.
That same trade is the honest answer to the question most readers now arrive with: is a CNN still worth learning when transformers took over vision? Yes, and for a precise reason rather than nostalgia. A Vision Transformer carries almost none of these assumptions, so it must learn locality and position-independence from examples — which costs data. Trained on a million labelled images a good CNN still wins; trained on a few hundred million the transformer's freedom pays off and it wins instead. The architecture is not obsolete and it is not superior; the built-in assumption is a data-efficiency trade, and knowing which side of that trade your dataset sits on is the actual decision.
How It Works
Two assumptions are wired into the network before training starts, and everything a CNN is good and bad at follows from them. The first is locality: a unit looks at a small window of its input — 3×3 or 7×7 pixels — not the whole frame, because the evidence for an edge or a corner is contained in a handful of neighbouring pixels. The second is weight sharing: the same window of weights is applied at every position, so the network cannot learn a pattern that only exists in the top-left. Neither is a hyperparameter you tune. They are priors baked into the wiring, and they are what the network gets for free instead of learning it. The mechanics of the sliding operation itself — kernels, stride, padding, output sizes — are covered in convolution; this page is about why the resulting layers are stacked the way they are.
The stack is a repeated three-step motif: convolve, apply a non-linear activation function, then downsample with pooling or a strided convolution. Each repetition trades spatial resolution for channel depth. VGG-16 is the clearest example: it takes a 224×224 input through five downsampling stages, halving the spatial size each time — 224 → 112 → 56 → 28 → 14 → 7 — while the channel count climbs 64 → 128 → 256 → 512 → 512. By the last stage the feature map is 7×7 with an effective stride of 32, meaning one unit there corresponds to a 32-pixel step across the original image.
That resolution-for-depth trade is what produces the hierarchy, because the window a unit effectively sees — its receptive field — grows with every layer. A first-layer unit sees 3×3 pixels and can only detect something as simple as an oriented edge or a colour transition. Stack layers and the windows compose: two 3×3 convolutions see a 5×5 patch, three see 7×7, and by the final convolutional layer of VGG-16 a single unit is influenced by roughly 212 of the 224 pixels across — essentially the whole frame. Early layers therefore respond to edges and textures, middle layers to motifs like corners and repeated patterns, and late layers to object parts and whole objects, not because anyone assigned those roles but because that is the only level of structure each depth can see.
Composition is also why depth is cheaper than width. A single 7×7 filter over C channels costs 49C² weights; three stacked 3×3 filters cover the same 7×7 window for 27C² weights and pass through two extra non-linearities on the way. Building an "eye" detector from existing edge and texture detectors costs far less than learning it from raw pixels — which is also why a pretrained CNN transfers so well: early layers of every image model converge on nearly the same edge filters, so only the late layers need retraining.
The end of the stack has changed, and the change is instructive. Early networks flattened the final feature map into fully connected layers, which threw away the parameter savings the convolutions had just won: of VGG-16's 138 million weights, about 123 million — 89% — sit in its three fully connected layers, and only 15 million in the thirteen convolutional layers that do the actual seeing. ResNet replaced the flatten with global average pooling — average each channel's 7×7 map down to one number, then a single linear classifier — and that, together with residual skip connections that let gradients reach layers 50 deep, gave ResNet-50 better accuracy than VGG-16 with 25.6 million parameters and about 3.8 billion multiply-adds per image, roughly a quarter of VGG-16's compute. The filters themselves are never designed; they are ordinary weights learned by backpropagation, which is why the same architecture learns Gabor-like edge filters on photographs and something entirely different on spectrograms.
Real-World Applications
Medical imaging is the clearest case where a CNN is still the right default, and the reason is the data ceiling rather than tradition. The U-Net architecture — a convolutional encoder that downsamples, a decoder that upsamples, and skip connections that restore the spatial detail the encoder discarded — won the ISBI 2012 cell-segmentation challenge trained on 30 annotated images, using elastic deformations to multiply them. Its descendants remain the standard baseline for segmenting tumours and organs in CT and MRI volumes, where a labelled dataset is hundreds or a few thousand studies because each one costs a radiologist's time. See AI in healthcare for how those systems are deployed.
Real-time detection under a compute budget is the second stronghold. Single-pass detectors in the YOLO family run the whole image through one convolutional network and emit boxes directly, which is what makes them fast enough for factory inspection lines, traffic cameras and drone navigation on embedded hardware that has no room for a large model. The same pressure explains why phone camera pipelines — face and portrait segmentation, document detection, on-device OCR — are built on compact convolutional backbones such as MobileNet and EfficientNet: a few million parameters, a per-frame budget measured in milliseconds, and no network connection. Edge AI and model compression cover that deployment envelope in more detail.
Convolution also survives inside the transformer era rather than beside it. The encoder and decoder that map between pixels and latent space in latent-diffusion image generators are convolutional; the diffusion model works in a compressed latent grid, but something has to get it there and back, and a conv net does it at a fraction of the cost of attention over pixels. And because the architecture only assumes a grid, not an image, the same stack handles audio spectrograms for keyword spotting, one-dimensional convolutions over ECG and sensor traces, and three-dimensional convolutions over video and volumetric scans.
Key Concepts
Inductive bias is the name for what a model assumes before it sees any data. A CNN's bias is strong and specific: features are local, and their meaning is translation-independent. A transformer applied to images makes almost no such assumption. A Vision Transformer cuts a 224×224 image into 16×16 patches — 196 of them — and from the very first layer every patch can attend to every other through self-attention. Nothing tells it that adjacent patches are related; that has to be learned, and learning it takes examples.
The original ViT paper measured exactly this. Trained on ImageNet-1k alone — 1.28 million images — Vision Transformers fell short of comparably sized ResNets. Pre-trained on the 303-million-image JFT-300M dataset and then fine-tuned, the same architectures overtook them. Nothing about the operator changed between those two results; only the amount of data did. That is the crossover, and it is the whole argument: a weak prior is a liability when data is scarce and an asset when it is abundant, because a strong prior that is slightly wrong eventually becomes the thing holding you back.
Cost pushes in the same direction. Attention is quadratic in the number of tokens — 196 patches means 38,416 pairwise interactions per head per layer — while a convolutional layer's cost is linear in the number of pixels. Double the input to 448×448 and a CNN does 4× the work, while global attention over 784 patches does about 16×. This is why the architectures that actually shipped are hybrids: Swin Transformers restrict attention to local windows and shift them between layers, reintroducing locality and hierarchy by hand, and most modern vision backbones use convolutional stems for the early high-resolution stages and attention only where the feature map has already shrunk.
The other half of the story is that some of the ViT advantage was never about attention at all. ConvNeXt took a plain ResNet and changed only the recipe — larger 7×7 depthwise kernels, fewer activation and normalisation layers, AdamW, long schedules and heavy augmentation borrowed from transformer training — and matched or beat a Swin Transformer of the same size on ImageNet-1k, using nothing but convolutions. The honest summary for 2026 is neither "CNNs are obsolete" nor "CNNs still win": the operator is a data-efficiency trade, the training recipe explains more of the historical gap than the architecture does, and most production vision systems are some blend of both.
Challenges
Translation invariance is the only invariance you get, and even it is approximate. Rotation and scale are not built in at all: a CNN trained on upright faces has no mechanism that recognises the same face rotated 90°, and will simply fail unless rotated examples appeared in training. This is the real reason data augmentation is not optional — flips, crops, rotations and colour jitter are how you buy invariances the architecture does not provide. Worse, the translation invariance itself leaks: strided convolutions and pooling downsample without an anti-aliasing filter, so shifting an input image by a single pixel can change a network's top-1 prediction, a failure documented in Zhang's shift-invariance work.
CNNs lean on texture more than shape. In a study of cue-conflict images — a cat's outline rendered with elephant skin — human observers named the shape about 96% of the time, while an ImageNet-trained ResNet-50 named the texture in roughly four cases out of five. Local filters over small windows see texture first, and nothing in the loss forces the network to prefer global form. It is a direct consequence of the locality prior, and it explains a family of real failures: models that collapse when lighting, sensor or image compression changes while the objects stay identical.
The architecture bakes in a resolution. Receptive-field sizes are fixed by the layer stack, so a model trained at 224×224 does not simply improve when handed a 4K image; small objects that were a few pixels wide in training are now hundreds, and the filters that matched them no longer do. Global average pooling lets the network accept variable input sizes, and feature-pyramid designs run detection at several scales, but both are patches over an assumption that never went away.
Weight sharing is also an attack surface. Because a filter fires wherever its pattern appears, an adversarial patch — a printed sticker with a crafted texture — works from anywhere in the frame, at any position the camera happens to catch it. The property that makes the architecture data-efficient is the same one that makes a single physical object a reusable exploit.
Future Trends
The hybrid design has settled rather than the debate resolving: convolutional stems handling early high-resolution stages, attention where the feature map is small enough to afford it, and window-restricted attention in between. Expect that to remain the default shape of vision backbones rather than a transition state.
The second direction is downward. Knowledge distillation from a large transformer teacher into a small convolutional student, combined with int8 quantization, is now the standard route to a model that runs on a camera or a phone — and the student is a conv net precisely because its inductive bias means it can be small without collapsing. As long as inference happens on hardware with a milliwatt budget, and as long as most labelled datasets are measured in thousands rather than millions of images, the architecture that assumes locality for free will keep earning its place.
Code Example
This makes the parameter arithmetic from the Definition visible: the convolutional layers that do the seeing are tiny, and a flattening classifier head dwarfs them until global average pooling removes it.
import torch
import torch.nn as nn
def count(module):
return sum(p.numel() for p in module.parameters())
features = nn.Sequential(
nn.Conv2d(3, 32, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 32x32 -> 16x16
nn.Conv2d(32, 64, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 16x16 -> 8x8
nn.Conv2d(64, 128, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 8x8 -> 4x4
)
# Old-style head: flatten the 128x4x4 map into a dense layer.
flatten_head = nn.Sequential(nn.Flatten(), nn.Linear(128 * 4 * 4, 512), nn.ReLU(), nn.Linear(512, 10))
# Modern head: average each channel to one number, then classify.
gap_head = nn.Sequential(nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(128, 10))
print(f"conv stack: {count(features):>8,}") # conv stack: 93,248
print(f"flatten head: {count(flatten_head):>8,}") # flatten head: 1,054,218
print(f"gap head: {count(gap_head):>8,}") # gap head: 1,290
x = torch.randn(4, 3, 32, 32)
print(features(x).shape) # torch.Size([4, 128, 4, 4])
print(gap_head(features(x)).shape) # torch.Size([4, 10])
The three convolutional layers hold about 93,000 weights; the flattening head holds over a million, more than ten times as many, and learns nothing about images that the convolutions did not already extract. Replacing it with global average pooling cuts the model by 92% and makes it accept any input size — the same substitution ResNet made against VGG, in eight lines.