esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Do Residual Connections Do?

What a residual connection is, why it helped very deep networks train, and where transformers use one, explained simply for your AI interview.

In short

A residual connection adds a layer's input back onto its output, so the layer only has to learn the change. It helped very deep networks train, and transformers put one around each of their sub-layers.

12 min readIntermediateCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A residual connection adds a layer's input back onto its output. So the layer only has to learn the change, and the rest passes straight through. ResNet used this in 2015 to train much deeper networks. Transformers use it around each attention and feed-forward block. It keeps the signal, and the learning signal, travelling through a deep stack.

What is a residual connection, in plain words?

A layer takes a signal in and hands a new signal out. A residual connection copies the layer's input along a shortcut and adds that copy to the layer's output. The layer then only has to learn what to change. Anything it does not need to change arrives intact.

Deep networks are long stacks of layers, and stacking them caused trouble at first. The 2015 ResNet abstract opens with the problem: "Deeper neural networks are more difficult to train." Their residual connections were the answer, and their networks went up to 152 layers.

Picture a hospital patient record updated shift by shift. The nurse adds what changed, and the older notes stay on the page. A residual block works the same way: the input stays, and the layers add a correction on top of it. In a legal search ranker with 40 blocks, the document's original signal survives the whole stack, and each block only adds a small correction.

Key words

Residual connection
A shortcut that adds a layer's input back onto its output.
Weights
The numbers a model learns. Training adjusts them.
Sub-layer
One of the smaller parts inside a transformer layer: attention, which lets each word look at the others, or a feed-forward network, which works on each word on its own.
Gradient
How much the error changes when a weight moves a little. Training uses it to decide which way each weight moves.
Overfitting
A model that does well on its training examples but poorly on new ones.

How does a residual block work?

A residual block has two paths side by side. One runs the layers, which compute a change. The other is the shortcut, which copies the input without touching it. The two are added, and the sum is the block's output.

How one residual block is wired

Block input

the signal x coming in

Two paths

Layers

the only part that trains

Shortcut

copies x, with no weights

Add the two paths

input plus change

Block output

goes to the next block

  1. 1The input goes into the layers.
  2. 2A copy of the input goes along the shortcut.
  3. 3The layers send back only the change they learned.
  4. 4The shortcut sends its copy back, unchanged.
  5. 5The sum goes on to the next block.
The input goes two ways: through the layers, which learn only a change, and along the shortcut, which copies it. The two are added, and the sum goes to the next block. The shortcut adds no weights.
  1. 1

    Copy the input

    Send x along the shortcut, untouched.

  2. 2

    Learn the change

    The layers compute what to adjust. This is the only part the block learns.

  3. 3

    Add and pass on

    Add the change to the copy. The sum goes to the next block.

Because the shortcut has no weights, it adds no parameters. Its technical name is an identity shortcut, because it passes the input through unchanged. ResNet puts it plainly: "Identity shortcut connections add neither extra parameter nor computational complexity."

The original transformer's encoder uses the same wiring. Each encoder layer has two sub-layers: an attention sub-layer and a feed-forward sub-layer. The decoder adds a third, which looks at the encoder's output. The paper puts a residual connection around each sub-layer, followed by layer normalisation, which rescales the numbers so they stay in a steady range.

  • “We explicitly reformulate the layers as learning residual functions with reference to the layer inputs, instead of learning unreferenced functions.”

    ResNet paper, 2015

  • “Similar to the encoder, we employ residual connections around each of the sub-layers, followed by layer normalization.”

    Attention Is All You Need

Why do very deep networks need it?

In theory, a deeper network could copy a shallower one and do no worse. In practice, plain deep networks often did worse. The ResNet paper calls this a degradation problem: "with the network depth increasing, accuracy gets saturated (which might be unsurprising) and then degrades rapidly."

The 20-layer and 56-layer plain networks, tested on CIFAR-10, a dataset of images in 10 classes, show it: "The deeper network has higher training error, and thus test error." The authors say this is not caused by overfitting, which means low training error but high test error. Here the deeper model is worse even on its training data, which is not what overfitting looks like.

Their fix rests on one observation. If the best a block can do is to pass its input through unchanged (an identity mapping), it is easier to make its change zero than to learn that pass-through with a stack of nonlinear layers, which can bend the signal in complicated ways. A shortcut makes doing nothing the default, so the block only has to learn a correction.

Tip

A careful point for the interview: the ResNet paper says vanishing gradients were already largely handled by better starting weights and normalisation layers. So residual connections were aimed at the degradation problem first.

Why does the shortcut help the gradient?

Training sends the error backwards through every layer, and each layer scales the gradient on its way. In a plain stack the factors can multiply down to almost nothing by the time they reach the early layers, so those layers barely learn.

Where the learning signal goes

Error at the output

the gap between guess and answer

Plain stack

40 plain layers

each one can shrink the signal

Residual stack

40 residual blocks

a shortcut carries the signal

Early layers barely move

learning stalls near the input

Early layers get signal

the error reaches every block

  1. 1The error is sent back into the plain stack.
  2. 2The same error is sent back into the residual stack.
  3. 3Each layer can shrink it, so little reaches the start.
  4. 4The shortcut carries it back almost unchanged.
Both stacks get the same error from the output. In the plain stack, each layer can shrink it, so the early layers may barely learn. The shortcut carries the error back almost unchanged, so the early blocks get a usable learning signal.

The 2016 identity-mapping paper describes this direct route. With identity shortcuts, the gradient of a layer "does not vanish even when the weights are arbitrarily small", so the error keeps a clear path back.

  • “the forward and backward signals can be directly propagated from one block to any other block”

    Identity mappings paper, 2016

Here is a small program with the same idea and made-up numbers. It is a 40-block ranker for a legal search tool, boiled down to one number per document. The plain block scales its signal by w. The residual block keeps the signal and adds w times it.

Python
# A simplified 40-block ranker for a legal search tool, boiled down to one number per document.
# w is the factor each layer applies to the signal (made up here, and small on purpose).
BLOCKS = 40
w = 0.01

def plain_block(x):
    return w * x          # no shortcut: the layer scales what it gets

def residual_block(x):
    return x + w * x      # the shortcut keeps x; the layer adds its change

def run(block, x):
    for _ in range(BLOCKS):
        x = block(x)
    return x

print(f"plain stack, factor left after 40 blocks:    {run(plain_block, 1.0):.2e}")
print(f"residual stack, factor left after 40 blocks: {run(residual_block, 1.0):.3f}")

Output

plain stack, factor left after 40 blocks:    1.00e-80
residual stack, factor left after 40 blocks: 1.489

In a straight chain like this, the factor each block applies is also the gradient factor, so the printed numbers show what reaches the first block after 40 steps. With w at 0.01, the plain stack's signal is about 1e-80, effectively zero. The residual stack's signal grows to about 1.49 instead, because each block adds 1% of its input.

Tip

A clean way to put it: the shortcut gives the error a short, direct route back. Say that the 2016 result holds for its identity setup, because the claim depends on that setup.

How would you debug a deeper model that trains worse?

A team adds 12 blocks to a document-ranking model, and the training error goes up. Here is how I would sort it out.

  1. 1

    Read the training error first

    Higher training error points to degradation or a training fault. Overfitting shows low training error with high test error.

  2. 2

    Check the wiring

    Confirm each block adds its input back, and that the two outputs are the same size at the add. A size mismatch is a bug to fix first, before any tuning.

  3. 3

    Look at gradients per block

    Measure gradient size in the first and last blocks. Tiny values near the input mean the learning signal is fading.

  4. 4

    Compare with the shallow model

    If the shallow model wins on training data too, the extra blocks are not earning their place.

  5. 5

    Change one thing at a time

    Try normalisation, careful starting weights and the residual add. Re-measure after each change.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: the layer adds its input back and learns only the change.
  • Why it mattered: deeper plain networks had higher training error.
  • The gradient point: the error gets a short, direct route back.
  • The shortcut adds no weights, and transformers use it around each sub-layer.
  • Honest limits: it is a strong help, not a complete guarantee on training.

Common traps

  • Trap"Residual connections are there to make the network deeper."

    BetterResidual connections make a deep stack trainable. They add no weights.

  • Trap"Residual connections fully solve vanishing gradients."

    BetterThey help a lot, and the 2016 result holds for its identity setup. Starting weights and normalisation matter too.

  • Trap"The shortcut adds parameters, so it is expensive."

    BetterThe shortcut is a plain copy with no weights, so it adds no parameters and little compute.

Can you spot the residual connection?

Spot the residual connection

A code review on a contract-search ranker flags one line. Which line keeps a residual connection?

Quick check

A 40-block model trains worse than its 20-block version, and the training error is higher too. Which reading fits the ResNet paper best?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q052What is layer norm; pre-norm vs post-norm?11 min
  2. Q054What does the feed-forward block do?10 min
  3. Q426Vanishing and exploding gradients?Coming soon
  4. Q418What is backpropagation?11 min
  5. Q413Overfitting vs underfitting?10 min
  6. Q064Roughly how many parameters are in one transformer layer?Coming soon

Learn it in depth

Last updated on 26 November 2026

Building a deep model that trains worse as you add layers?

I design and build AI products and agents, including the UI and the system behind them. Book a short call and say what you need.