Skip to article
Insights / Artificial Intelligence
Artificial Intelligence

Backpropagation Explained: A Worked Neural Network Example with House Prices

Backpropagation is the calculation that turns a neural network's mistakes into learning. This worked example follows three house-price predictions from the forward pass through MSE, gradients and a real weight update.

READUNDERSTANDAPPLY
INSIGHT / Artificial Intelligence Read the evidence. Understand the service. Apply the thinking.
11 MIN READ 4 Sep 2026
Share Insight Share this article
Share on LinkedIn Facebook X Email

Backpropagation can sound like one of the most intimidating parts of artificial intelligence. In practice, the idea is much simpler: a neural network makes a prediction, measures how wrong it was, calculates which weights contributed to that error, and adjusts those weights slightly. This worked example follows that entire process using three house-price predictions and two hidden neurons.

Backpropagation in One Sentence

A neural network learns by repeatedly answering three questions: What did I predict? How wrong was I? Which numbers inside the network should change?

01 Input Read the house features
02 Forward Pass Make a price prediction
03 Loss Measure the error
04 Backpropagation Calculate the gradients
05 Learning Update the weights

The maths below is deliberately small enough to calculate by hand. Real neural networks can contain millions or billions of parameters, but the principle is the same.

The Worked Example: Three Houses and Two Hidden Neurons

Imagine a tiny neural network trying to predict house prices. Each house has three input features: the number of bedrooms, the floor area in square feet and a simplified location score.

House 1 [2, 800, 5]

Two bedrooms, 800 square feet and a location score of 5.

House 2 [3, 1200, 8]

Three bedrooms, 1,200 square feet and a location score of 8.

House 3 [1, 500, 3]

One bedroom, 500 square feet and a location score of 3.

Target Prices £220k / £375k / £135k

These are the real prices the network is trying to learn.

Input Matrix 3 houses × 3 features
X = [[2, 800, 5], [3, 1200, 8], [1, 500, 3]]

Each row is one house. Each column is one feature. This is the data the network receives.

The first layer weights and biases

The first hidden layer contains two neurons. Each neuron has a weight for every input feature. The weights decide how strongly each input contributes to that neuron’s calculation.

Hidden Layer Parameters W₁ and b₁
W₁ = [[5,000, 10,000], [200, 150], [10,000, 20,000]]
b₁ = [1,000, 2,000]

The bias is an extra adjustable starting value. It allows a neuron to shift its output independently of the input values.

The output layer

The two hidden-neuron outputs are then combined into one final house-price prediction.

Output Layer Parameters W₂ and b₂
W₂ = [0.5, 0.5]ᵀ
b₂ = 5,000

A Quick Cheat Sheet Before We Calculate Anything

XThe input data: our houses and their features.
WThe weights: how strongly the network responds to each input.
bThe bias: an adjustable base value added to a neuron.
ZThe raw weighted total before an activation function is applied.
aThe activated neuron output after filtering.
ŷThe network’s predicted value.
yThe real target value.
LThe loss: a numerical measure of how wrong the prediction is.
nThe number of examples in the batch. Here, n = 3.
∂L/∂WThe gradient: how the loss changes when a weight changes.

Step 1: The Forward Pass

The forward pass is simply the network using its current weights to make predictions. No learning happens yet. We are only moving information from the inputs towards the output.

Calculate the hidden-layer totals

Hidden Layer Linear calculation
Z₁ = X × W₁ + b₁

Multiply every feature by its corresponding weight, add those products together, then add the neuron’s bias.

House 1, neuron 1:

(2 × 5,000) + (800 × 200) + (5 × 10,000) + 1,000 = 10,000 + 160,000 + 50,000 + 1,000 = 221,000.

House 1, neuron 2:

(2 × 10,000) + (800 × 150) + (5 × 20,000) + 2,000 = 20,000 + 120,000 + 100,000 + 2,000 = 242,000.

Repeating the same process for the other two houses gives:

Raw Hidden Outputs Z₁
Z₁ = [[221,000, 242,000], [336,000, 372,000], [136,000, 147,000]]

Apply the ReLU activation function

We now apply ReLU. ReLU is one of the simplest activation functions: negative values become zero; positive values remain unchanged.

Activation Rectified Linear Unit
ReLU(z) = max(0, z)

Every value in our hidden layer is already positive, so nothing changes:

Activated Hidden Outputs a₁
a₁ = [[221,000, 242,000], [336,000, 372,000], [136,000, 147,000]]
Plain English

The hidden neurons have converted the original house features into two new learned numerical representations. In this toy example those values are very large, but they are simply the intermediate information passed to the output layer.

Calculate the predicted house prices

Output Prediction Final linear layer
ŷ = a₁ × W₂ + b₂

House 1: (221,000 × 0.5) + (242,000 × 0.5) + 5,000 = 236,500.

House 2: (336,000 × 0.5) + (372,000 × 0.5) + 5,000 = 359,000.

House 3: (136,000 × 0.5) + (147,000 × 0.5) + 5,000 = 146,500.

House 1 Prediction vs Actual £236,500 vs £220,000

The network over-predicts by £16,500.

House 2 Prediction vs Actual £359,000 vs £375,000

The network under-predicts by £16,000.

House 3 Prediction vs Actual £146,500 vs £135,000

The network over-predicts by £11,500.

Next Learning Signal Turn errors into gradients

Backpropagation tells us which weights should move and in which direction.

Step 2: Measure the Error with Mean Squared Error

A training algorithm needs one number that represents how well or badly the network performed. For this example we use Mean Squared Error, usually shortened to MSE.

Loss Function Mean Squared Error
MSE = (1 / n) × Σ(ŷᵢ − yᵢ)²

Subtract the real value from each prediction, square each difference so negative and positive errors cannot cancel each other out, add them together, then divide by the number of examples.

The squared errors are:

  • House 1: (236,500 − 220,000)² = 272,250,000
  • House 2: (359,000 − 375,000)² = 256,000,000
  • House 3: (146,500 − 135,000)² = 132,250,000
Batch Loss n = 3
MSE = (272,250,000 + 256,000,000 + 132,250,000) / 3
MSE = 220,166,666.67

That number looks enormous because house prices are large values and MSE squares the errors. What matters during training is whether the loss moves down over repeated updates.

Step 3: Backpropagation — Work Backwards from the Error

We now know the network is wrong. Backpropagation asks a more useful question: how much did each adjustable parameter contribute to that error?

Calculus answers that using derivatives. A derivative measures how sensitive one quantity is to a small change in another. In neural networks, we call these derivatives gradients.

Plain English

A gradient is a direction sign. Positive means increasing that parameter would increase the loss locally. Negative means increasing it would decrease the loss locally. Gradient descent then moves in the opposite direction.

First calculate the raw prediction errors

Error Vector Prediction minus target
ŷ − y = [16,500, −16,000, 11,500]ᵀ

The factor-of-two trap in MSE

This is one of the easiest places to make a mistake when learning backpropagation. If our loss is exactly:

Standard MSE The loss used in this article
L = (1 / n) × Σ(ŷᵢ − yᵢ)²

then differentiating the square produces a factor of 2:

MSE Gradient Derivative with respect to predictions
∂L / ∂ŷ = (2 / n) × (ŷ − y)

Because n = 3, the error vector is multiplied by 2/3.

Some textbooks deliberately define the loss as (1 / 2n) × Σ(ŷ − y)². In that version the 2 cancels during differentiation, leaving (1/n) × (ŷ − y). Both conventions are valid, but the loss definition and the gradient formula must match.

Critical Distinction

If you write MSE as 1/n times the squared error, its derivative contains 2/n. If you want a 1/n gradient, define the loss as half-MSE: 1/(2n) times the squared error.

Calculate the gradient flowing out of the loss

Prediction Gradient 2/3 × the error vector
∂L / ∂ŷ = [11,000, −10,666.67, 7,666.67]ᵀ

Step 4: Calculate the Gradient for the Output Weights

Each output weight multiplied one of the hidden activations. Therefore the gradient for W₂ depends on both the prediction-error gradient and the values in a₁.

Chain Rule Output weight gradient
∂L / ∂W₂ = a₁ᵀ × (∂L / ∂ŷ)

Transposing a₁ turns its two hidden-neuron columns into rows so the matrix dimensions line up with the three-house error vector.

Hidden Activations Transposed a₁ᵀ
a₁ᵀ = [[221,000, 336,000, 136,000], [242,000, 372,000, 147,000]]

Multiplying that matrix by the prediction gradient gives:

Output Weight Gradient ∂L / ∂W₂
∂L / ∂W₂ = [−110,333,333.33, −179,000,000]ᵀ

The gradient for the output bias is simpler because the bias contributes directly to every prediction:

Output Bias Gradient ∂L / ∂b₂
∂L / ∂b₂ = 11,000 − 10,666.67 + 7,666.67 = 8,000

What Do Negative Gradients Actually Mean?

Both output-weight gradients are negative. That does not mean the weights themselves should become negative. It means that, at the current point in the loss landscape, increasing those weights slightly would reduce the loss.

Gradient descent uses the following rule:

Gradient Descent Parameter update
W(new) = W(old) − η × (∂L / ∂W)
WThe parameter we are updating.
ηThe learning rate: how large a step we take.
∂L/∂WThe gradient telling us which direction increases the loss.
We move in the opposite direction to reduce the loss.

Because the gradients are negative, subtracting them increases the two output weights.

Step 5: Update the Weights with a Learning Rate

Our gradients are extremely large because the example uses raw square-foot values, large first-layer weights and hidden activations in the hundreds of thousands. We therefore need a very small learning rate for this hand-worked example.

Suppose we use:

Learning Rate Toy example
η = 0.000000000001 = 10⁻¹²

The first output weight becomes:

Weight 1 Update Gradient descent
0.5 − (10⁻¹² × −110,333,333.33) = 0.5001103333

The second becomes:

Weight 2 Update Gradient descent
0.5 − (10⁻¹² × −179,000,000) = 0.500179

The bias changes by only a tiny amount at this learning rate:

Bias Update Gradient descent
5,000 − (10⁻¹² × 8,000) ≈ 5,000

Did the network actually improve?

Yes — slightly. Using only this one tiny output-layer update, the predictions become approximately:

  • House 1: £236,567.70
  • House 2: £359,103.66
  • House 3: £146,541.32

The new MSE is approximately 220,128,130.93, down from 220,166,666.67.

What Just Happened?

The network made a prediction, converted the errors into gradients, nudged its weights in the direction that should reduce the loss, and produced a slightly lower error on the next forward pass. That cycle is the core of neural-network training.

Why Are the Gradients So Huge?

This worked example is intentionally easy to calculate by hand, but it also demonstrates an important practical issue: scale matters.

Square footage is measured in hundreds or thousands. The first-layer weights are also large. That produces hidden activations above 100,000. When those large activations are multiplied by prediction errors during backpropagation, the resulting gradients become enormous.

Raw Inputs Scale Problem 800, 1200, 500

Floor-area values are much larger than bedroom counts or small location scores.

Large Weights Amplification 5,000 to 20,000

The first layer magnifies already unbalanced input scales.

Large Activations Backpropagation 136k to 372k

These values feed directly into the output-weight gradient.

Real Practice More Stable Training Normalise the data

Modern ML pipelines commonly standardise or normalise features before training.

Feature scaling does not change the fundamental idea of backpropagation. It simply makes the optimisation problem easier to manage numerically.

Where the First Layer Fits In

So far we have calculated gradients only for the output layer. A full training step continues backwards.

The output error is propagated through W₂, then through the derivative of ReLU, and finally into the gradients for W₁ and b₁. Because all of the hidden values in this example are positive, the ReLU derivative is 1 for every hidden unit.

01 Loss ∂L / ∂ŷ
02 Output Layer ∂L / ∂W₂
03 Hidden Signal ∂L / ∂a₁
04 Activation ReLU derivative
05 First Layer ∂L / ∂W₁

That is why the method is called backpropagation: the learning signal moves backwards through the same computational path used during the forward pass.

The Bigger Lesson: Neural Networks Learn by Credit Assignment

The most useful way to think about backpropagation is not as a collection of formulas. It is a system for credit assignment.

When the network makes a bad prediction, many different parameters may have contributed. Backpropagation calculates how sensitive the final loss is to each one. Gradient descent then uses those sensitivities to decide how to move the parameters.

01 Prediction What did the model do?

The forward pass produces an output from the current parameters.

02 Measurement How wrong was it?

The loss function turns prediction quality into a numerical training signal.

03 Learning What should change?

Gradients distribute responsibility through the network so its parameters can be updated.

Key Takeaways

  • A forward pass uses the current weights to produce predictions.
  • MSE measures the average squared difference between predictions and real values.
  • If MSE is defined as (1/n) × Σ(ŷ − y)², its prediction gradient contains the factor 2/n.
  • The 1/n gradient commonly seen in examples corresponds to half-MSE: (1/2n) × Σ(ŷ − y)².
  • Backpropagation applies the chain rule to determine how each parameter affected the loss.
  • Gradient descent updates parameters in the opposite direction to the gradient.
  • Large raw feature scales can create large gradients, which is one reason feature scaling matters in practical machine learning.
The Core Idea

Neural-network learning is not magic. It is repeated measurement and adjustment: predict, measure the error, calculate responsibility, update the parameters, and try again.

What Comes Next?

The next natural step is to continue the same calculation through the first layer: propagate the output error through W₂, apply the ReLU derivative, calculate the gradients for W₁ and b₁, and then update the entire network.

Once that process is clear, the same logic scales from this two-neuron example to much larger architectures. Deep learning simply repeats the same chain-rule logic through many more layers.

Share Insight Share this article
Share on LinkedIn Facebook X Email
Put the thinking into practice DIGIFIXIT / INSIGHTS

Have a complex service challenge worth understanding properly?

Tell us what is not working, what is changing or what your organisation needs to understand. We can start with the evidence.

Explore AI Governance
Scroll to Top