In this article
Before you start
Convolutional networks are one kind of neural network; you need only school arithmetic plus the four ideas below.
Why interviewers ask this
A wrong parameter count or output size is the quickest sign in a machine learning round that a candidate memorised convolution without understanding it. Candidates report convolution questions in machine learning interviews at companies of many kinds; these are reports by candidates, not a public list of askers.
Interviewers use the topic to separate three levels. A weak answer says a convolution is "a filter that extracts features". A strong answer describes the sliding multiply-and-add, explains why weights are shared, and gives the formulas for output size and parameter count. A Staff-level answer adds the receptive field, the effective receptive field that is smaller than the theoretical one, and the trade-off against recurrent and attention-based layers. The same few formulas also decide whether a network fits in memory, so they come up again in system design rounds.
Convolutional networks from first principles
- Convolutional network
- A convolutional network is a neural network built from layers that apply the same small learned kernels at every position of a grid-shaped input, so each output depends on a local patch and the layer needs far fewer parameters than a dense layer on the same input.
- Feature map
- A feature map is the grid of outputs made by sliding one kernel over its input; each value says how strongly the kernel's pattern appears at that position, and a layer with C kernels outputs C feature maps, also called channels.
- Receptive field
- The receptive field of an output value is the region of the original input that can change that value, measured in input pixels along one side; it grows as convolutional layers are stacked, and a larger field lets the output use more context.
In plain words
Picture a metal detector swept over a beach. The detector has one setting and gives one reading per spot. A high reading means something matching that setting is buried there. A convolutional layer does the same to a picture. The kernel is the setting, the patch under it is the spot, and the grid of readings is the feature map.
The analogy breaks in one place. A layer holds many kernels at once, and nobody tunes their settings by hand. Training nudges the weights to reduce errors on examples, and that is how the kernels are learned.
In one precise sentence: a convolutional layer computes, at every position, a weighted sum of the local patch. The weights are the kernel's, and training learns them.
Step 1: A kernel multiplies one small patch and adds the products
A kernel turns one patch into one number by multiplying each weight by the pixel under it and adding the products. A colour image has three channels, so the patch has depth as well as height and width. A 3×3 kernel on that image holds 3 × 3 × 3 = 27 weights (illustrative sizes). The layer multiplies the 27 weights by the 27 pixel values beneath them, adds the products, and adds one bias, a learned constant for that kernel.
Input: a 3×3×3 patch. Output: one number.
Deep learning libraries such as PyTorch do not flip the kernel before multiplying. The PyTorch Conv2d documentation (stable version, accessed October 2026) calls the operation a 2D cross-correlation. The flip is a convention only: the weights are learned, so a flipped version would simply learn the flipped kernel. You now know how one patch becomes one number. The next step repeats it everywhere.
Step 2: Sliding one kernel shares its weights, so parameters do not depend on image size
Sliding the same kernel to every position reuses its weights, so the parameter count of a convolutional layer depends on the kernel size and the channel counts, never on the image size. LeCun et al. (1998) describe a feature map as "a set of units whose weights are constrained to be identical". A layer with one kernel per output channel has this many parameters:
Here is the kernel side, the input channels, the output channels, and the +1 is each kernel's bias. For 3 channels in, 64 out and 3×3 kernels, P = (27 + 1) × 64 = 1,792, made of 1,728 weights and 64 biases, at 32×32 and at 224×224 alike.1 A dense layer joining the 3,072 inputs to the 65,536 outputs (padding 1 keeps the output 32×32) needs 201,392,128 parameters, about 112,000 times more.1 Locality and sharing make the convolution cheap. The next step counts how many outputs the sliding produces.
Step 3: The CNN output size formula: stride and padding set the size
Stride and padding decide how many positions the kernel visits, and so how large the output is. Stride is the pixel step between kernel positions, and padding is the count of zero pixels added to each border. With input side i, kernel side k, padding p and stride s, the output side is (PyTorch documentation, Dumoulin and Visin, 2018):
The sum i + 2p − k is how far the kernel can travel. Dividing by s counts whole strides, and floor drops a partial stride that would overhang. The +1 counts the starting position, as a fence with n gaps has n + 1 posts. A 5-pixel side with k = 3, p = 0, s = 1 gives 3; 8 with k = 3, s = 2 gives floor(2.5) + 1 = 3, so the last column is never read.1 With dilation d, which spaces the weights apart, k becomes d(k − 1) + 1.
Step 4: Stacked layers widen the receptive field
Stacking convolutional layers widens the receptive field, because each layer reads outputs that already summarise patches of the layer before. With 3×3 kernels and stride 1, L layers see 2L + 1 pixels per side. Pooling, which replaces each small window by its maximum or average, and stride 2 double the input distance between neighbouring outputs. Track the receptive field r and the jump j, the input distance between neighbouring outputs, which starts at 1 and multiplies by each stride:
Araujo, Norris and Sim (2019) derive this recursion. An activation function such as the rectified linear unit (ReLU) between layers stops the stack collapsing into one linear layer. Luo et al. (2017) show that the effective receptive field, the part that really influences an output, fills only a fraction of the theoretical one.
Step 5: Stacked blocks end in a classifier
A convolutional network classifies an image by repeating a block of convolution, activation and pooling, then ending in a classifier head. The head flattens the last feature maps into one list of numbers, or averages each map to one number (global average pooling), and feeds fully connected (dense) layers whose last output is one score per class. Softmax turns those scores into probabilities that sum to one. In short, a classifier head of flatten, dense layers and softmax ends the network. LeCun et al. (1998) built LeNet-5 this way: convolution and subsampling layers, then a convolution layer called C5, a fully connected layer F6 and the output layer.
Krizhevsky et al. (2012) describe five convolutional layers, some followed by max-pooling, then three fully connected layers ending in a 1000-way softmax. Early layers typically respond to simple patterns such as edges; because the receptive field widens with depth, later layers combine them into parts and objects. Nobody sets the kernels by hand: backpropagation, which passes the error backwards through the layers to show how each weight should change, adjusts them during training. You now have the whole path from pixels to class scores.
Step-by-step description
- The kernel multiplies a patch and adds the products.
- The same weights move one column right.
- The formula gives side 3 and the row 0, 27, 27.
- A second layer sees a 5-pixel patch.
- Blocks repeat, then dense layers and softmax.
- The kernel with rows of -1, 0, 1 gives 0 on the first patch and 27 on the second.
- The output side is (5 - 3) / 1 + 1 = 3, and the output row is 0, 27, 27.
- Two stacked 3×3 layers see 5 pixels per side.
- A classifier head of flatten, dense layers and softmax ends the network.
Knowing it is half the job. Saying it is the other half.
Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.
Start Free Trial →Worked example
Take a small illustrative image of five rows and five columns. Each row reads 0, 0, 0, 9, 9, so brightness jumps between the third and fourth columns. The kernel has three rows of −1, 0, 1, a vertical-edge detector. With no padding and stride 1, the output side is 5 − 3 + 1 = 3.
The first patch covers columns one to three, which are all zero, so the output is 0. The second patch covers columns two to four: each row contributes −0 + 0 + 9 = 9, and three rows give 27. Every output row reads 0, 27, 27, large exactly where the brightness steps up.1 A true convolution that flips the kernel gives −27 instead, the same pattern with the sign reversed.1
Now the parameter bill. The layer of Step 2 takes a 32×32 colour image to 64 channels with 3×3 kernels, padding 1 and stride 1, so its output is 32×32 by the formula of Step 3.
| Quantity | Value (computed or illustrative) |
|---|---|
| Weights in one 3×3 kernel over 3 channels | 27 |
| Parameters, 3 to 64 channels, 3×3 kernels, with bias | 1,792 |
| Parameters, same layer without bias | 1,728 |
| Parameters of a dense layer for the same input and output | 201,392,128 |
| Dense parameters divided by convolution parameters | 112,384 |
| Multiply-adds of the convolution for one image | 1,769,472 |
| Parameters, 3 to 64 channels, 5×5 kernels | 4,864 |
| Parameters of a second layer, 64 to 128 channels, 3×3 | 73,856 |
| First layer of the 2012 network: 96 kernels of 11×11×3 | 34,944 parameters |
The last row follows from the layer shape that Krizhevsky et al. (2012) report, and the formula of Step 2 gives 34,944 parameters including biases. That is 0.058% of the 60 million parameters they report for the whole network.1
Finally the receptive field, derived on paper for an illustrative seven-layer stack: conv 3×3, conv 3×3, pool 2×2 with stride 2, conv, conv, pool, conv. Start at r = 1, j = 1. The first conv gives 1 + 2 × 1 = 3 and the second gives 5. The pool gives 5 + 1 × 1 = 6 and doubles j to 2.
The next convs give 6 + 2 × 2 = 10 and 14. The second pool gives 14 + 1 × 2 = 16 and sets j to 4, and the last conv gives 16 + 2 × 4 = 24.1 Seven stride-1 layers would reach only 15. Each pooling layer doubles the step between outputs, so every later convolution adds more.
Text description of the diagram
- The receptive field of the seven-layer stack is 24 pixels per side.
- Seven stride-1 layers would reach only 15.
- Each pooling layer doubles the step between outputs, so every later convolution adds more.
Trade-offs and edge cases
A convolutional layer trades reach for economy. It sees only a local window, which is why it is cheap, and distant context must come from depth, pooling, dilation or a different layer type. A recurrent neural network (RNN) shares weights over time steps and carries a hidden state, a running summary of the steps so far, so its steps run in sequence.
Self-attention lets every token (a word or word piece) read every other token in one layer and runs in parallel. Its compute grows with the square of the sequence length , since each of tokens attends to tokens, and so does its memory when the score matrix is stored; fused kernels that never store that matrix keep memory linear.
Text description of the diagram
- A convolutional layer sees a local window and processes every position in parallel.
- A recurrent layer passes a hidden state and processes steps in sequence.
- Self-attention lets every token read every other token, and its cost grows with the square of the length.
Small kernels beat large ones at equal reach. Three stacked 3×3 layers and one 7×7 layer both have a receptive field of 7. With 64 channels in and out and no bias, the stack has 110,592 weights and the single layer 200,704, so the stack has 44.9% fewer, and it adds two more nonlinearities.1
Depthwise-separable convolutions cut the bill much further. A depthwise convolution gives each input channel its own small kernel (groups equal to the channel count), and a 1×1 pointwise convolution then mixes channels. With groups , the parameter count becomes . For 64 to 128 channels with 3×3 kernels, a standard layer has 73,856 parameters, while depthwise (640) plus pointwise (8,320) gives 8,960, about 8.2 times fewer.1
Convolutional networks also compete with vision transformers (ViT), which cut an image into patches and apply self-attention to them. A convolution builds in locality and weight sharing; Dosovitskiy et al. (2020) note that a transformer lacks these built-in assumptions, so it generalises less well on too little training data but does very well after pre-training on large datasets. Liu et al. (2022) modernised a standard convolutional network with design choices borrowed from transformers and report that it competes with them. The practical reading: with limited data the convolution's assumptions help, and with large data attention's global context catches up.
Edge cases to name. Zero padding adds artificial zeros, so outputs near the border differ from interior ones. A convolution is equivariant, not invariant: shifting the input shifts the feature maps. Stride and pooling make that equivariance only approximate, and invariance comes mainly from pooling, the final layers and data augmentation, which trains on shifted copies. Deep stacks need help to train, through residual connections, batch normalisation and care with exploding gradients. Convolutions also remain the core of object detectors such as the YOLO (You Only Look Once) family, covered in YOLO and Darknet.
How to answer it in an interview
Explain how a convolutional network works.
A convolutional network slides small learned kernels across an image. Each kernel multiplies a patch by its weights and adds the products, and the same weights are reused at every position. So the parameter count is kernel side squared times input channels, plus one, times output channels, whatever the image size. Stride and padding set the output size, and stacking layers widens each output's receptive field. The trade-off is locality: one layer sees only a small patch, so long-range context needs depth, pooling, dilation or attention.
The spoken structure: say the sliding multiply-and-add, then the weight sharing and the parameter formula, then stride and padding, then the receptive field and what locality costs.
Common mistakes
- "The parameter count grows with the image size." (wrong) Weights are shared across positions. (right) "The count depends on kernel size and channels; a bigger image only adds multiply-adds."
- "A 3×3 kernel has 9 weights." (wrong) It spans every input channel. (right) "It has 3 × 3 × the number of input channels in weights, 27 on a colour image."
- "A layer of 64 kernels on 3 channels has 1,728 parameters." (wrong) That omits the 64 biases. (right) "It has 1,792: 1,728 weights plus 64 biases."
- "The output size is (i − k) divided by s." (wrong) That drops the floor and the starting position. (right) "It is floor((i + 2p − k) / s) + 1."
- "Two 3×3 layers see 6 pixels." (wrong) Each extra stride-1 3×3 layer adds only 2. (right) "They see 5, and L layers see 2L + 1."
Follow-up questions
Why do we use odd kernel size in a conv layer?
An odd kernel has a centre pixel, so each output sits exactly on the input position it describes, and size-preserving stride-1 padding is (k − 1) / 2 per side, a whole number. For k = 4 that padding would be 1.5, and on an 8-pixel side padding 1 gives 7 outputs while padding 2 gives 9.1 Odd sizes are a convention that keeps the geometry clean, not a law.
Why are convolutions so effective for images?
Images have two properties: nearby pixels are related, and a pattern means the same wherever it appears. A convolution builds both in, through local patches and shared kernels, so the layer in this page needs 1,792 parameters instead of 201,392,128 and reuses one detector at every position.
How many trainable parameters does a conv2d layer have, and what changes if the sizes change?
Use . Moving to 5×5 kernels gives 4,864, dropping the bias gives 1,728, and a second layer from 64 to 128 channels gives 73,856, so later layers dominate the total because channel counts multiply.1
What is the difference between convolutional neural networks and recurrent neural networks?
A convolutional layer shares weights across positions in space and reads a local window in parallel. A recurrent layer shares weights across time and passes a hidden state step by step; the long short-term memory (LSTM) cell is its gated form.
How did models evolve from CNN to RNN to LSTM to transformer, and why did transformers become more effective?
Convolutions handled grid data, recurrence handled sequences, LSTM gates helped information survive longer sequences, and transformers replaced recurrence with attention so a whole sequence trains in parallel and any token reads any other directly. The price is compute that grows with the square of the length. More deep learning interview questions follow this thread.
Where does batch normalisation go in a convolutional block?
It usually sits between the convolution and the activation. For a convolutional layer it computes one mean and one variance per channel over the batch and every position, then rescales; see batch versus layer normalisation. Because batch normalisation subtracts each channel's mean, a bias in the convolution just before it is redundant, so that convolution is usually built without one.
- A convolutional layer multiplies each local patch by a small kernel and reuses the same weights at every position.
- Parameters equal , independent of image size.
- Output side equals floor((i + 2p − k) / s) + 1; the +1 counts the starting position.
- Stacked layers widen the receptive field, faster with pooling or stride, and the effective field is smaller than the theoretical one.
- The cost of locality is limited reach, which depth, dilation or attention must repair.
Sources
- Conv2d, PyTorch stable documentation — PyTorch Foundation, accessed 2026-10-26, 26 Oct 2026
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale (arXiv 2010.11929) — arXiv (Dosovitskiy et al.), 22 Oct 2020
- A ConvNet for the 2020s (arXiv 2201.03545) — arXiv (Liu et al.), 10 Jan 2022
- Computing Receptive Fields of Convolutional Neural Networks — Distill (Araujo, Norris, Sim), 4 Nov 2019
- A guide to convolution arithmetic for deep learning (arXiv 1603.07285v2) — arXiv (Dumoulin and Visin), accessed 2026-10-26, 11 Jan 2018
- Understanding the Effective Receptive Field in Deep Convolutional Neural Networks (arXiv 1701.04128) — arXiv (Luo, Li, Urtasun, Zemel), accessed 2026-10-26, 15 Jan 2017
- Gradient-Based Learning Applied to Document Recognition — Proceedings of the IEEE (LeCun, Bottou, Bengio, Haffner), accessed 2026-10-26, 1 Nov 1998
- ImageNet Classification with Deep Convolutional Neural Networks — NeurIPS (Krizhevsky, Sutskever, Hinton), accessed 2026-10-26, 3 Dec 2012