Welcome back! In our last lesson, we explored the general backpropagation algorithm, understanding it as an efficient, recursive process for computing gradients on a computation graph. We saw how the chain rule allows us to determine the sensitivity of the final loss to any intermediate node in the graph.
Today, we will apply that general machinery to the fundamental building block of a neural network: a single neuron. Our goal is to derive, by hand, the precise mathematical rules for updating a neuron's weights and bias. This process is the heart of learning in neural networks, translating a high-level error signal into concrete adjustments for individual parameters. By the end of this lesson, you will understand exactly how a neuron uses the gradient to learn from its mistakes.
From a Linear Model to a Neuron
To build up our intuition, let's start with the simplest possible case, which you may recognize from linear regression. Imagine a "neuron" with no activation function. Its output is just a linear combination of its inputs: . If we use a Mean Squared Error (MSE) loss function, , how do we find the gradient of the loss with respect to a single weight, say ?
This involves a chain of functions: the weight influences the prediction , which in turn influences the error, which finally determines the loss . To find , we must apply the chain rule through these stages.
The following resource provides an excellent, step-by-step derivation for this exact scenario.
How neural networks learn: deep dive into backpropagation and gradient descent
This article breaks down the gradient calculation for a simple linear model, which serves as a perfect warm-up for a full neuron. It masterfully connects the mathematical steps to the underlying concepts.
Please read the section titled "Computing backpropagation." Start with the subsection The chain rule to refresh your memory on how derivatives of composed functions are calculated. Then, carefully follow the derivation that begins just after, where the loss is expressed as a chain of three functions: f_1 (prediction), f_2 (error), and f_3 (squared error). Trace how the author computes the derivative of each part and then multiplies them together using the chain rule to arrive at the final gradient for a weight, dw, and the bias, db. Pay close attention to how the input value x naturally appears in the gradient for the weight, but not for the bias.
As you saw in the reading, for a single data point, the gradient of the squared error loss with respect to a weight is:
This result is highly intuitive: the update signal for a weight is proportional to the overall error and the corresponding input signal.
Adding the Activation Function
Now, let's make our model a true neuron by adding a non-linear activation function, , such as the sigmoid function. The computation now has an extra step:
- Compute the pre-activation value (the weighted sum):
- Apply the activation function:
- Compute the loss:
This adds one more link to our chain rule. To find the gradient with respect to a weight , we now have:
This decomposition is visualized perfectly in the following diagram.

Let's analyze each of the three components in this chain. The 3Blue1Brown video on backpropagation provides one of the clearest conceptual explanations of this process.
Backpropagation calculus | Deep Learning Chapter 4
This video from 3Blue1Brown's series on neural networks elegantly derives the gradient for a single weight and bias, focusing on the intuition behind each term in the chain rule.
Watch the first segment from the start of the derivation. The narrator breaks down the gradient \frac{\partial C}{\partial w^{(L)}} into the same three parts we identified. Pay special attention to the intuitive explanations for each term: \frac{\partial C}{\partial a^{(L)}} is proportional to the error a^{(L)} - y. \frac{\partial a^{(L)}}{\partial z^{(L)}} is the derivative of the activation function, \sigma'(z^{(L)}). \frac{\partial z^{(L)}}{\partial w^{(L)}} is the activation of the previous neuron, a^{(L-1)}. This captures the "fire together, wire together" principle. After that, briefly watch the derivation for the bias from the sensitivity to the bias, and notice how similar it is, with the only difference being the final term in the chain.
Let's assemble the pieces from the video. For a single training example with loss :
-
Weight gradient:
Here, is the input corresponding to weight , which 3Blue1Brown refers to as the activation of the previous layer, .
-
Bias gradient:
The gradient for each weight is a product of three terms: the final error signal, the local sensitivity of the activation function, and the input signal that passed through that weight.
The Full Update Rule in Action
Once we have these gradients, we use them in the gradient descent algorithm to update the parameters. For a learning rate :
StatQuest provides a great numerical walkthrough of this process, deriving and then applying these update rules.
Backpropagation Details Pt. 1: Optimizing 3 parameters simultaneously.
In this StatQuest video, Josh Starmer provides a detailed numerical example of calculating the gradients for the weights of the final neuron and using them in gradient descent.
First, watch the derivation of the derivatives for weights w_sub_3 and w_sub_4 from calculating the derivatives. This section applies the same chain rule logic we've just discussed, showing how the activation from the previous layer (y_sub_1,i or y_sub_2,i in his notation) becomes a key part of the weight's gradient. Then, watch the segment from plugging into gradient descent, where he takes the calculated derivative values and plugs them into the gradient descent update formulas to get the new, improved weights.
Your Turn: A Practice Problem
Now it's time to solidify your understanding by deriving these gradients yourself. The following exercise from Stanford's CS230 course asks you to do exactly what we've covered in this lesson: perform backpropagation for a single neuron.
[PDF] Section 3: Gradient Descent & Backpropagation Practice Problems
This problem set provides a direct, hands-on application of the concepts we've learned.
In the PDF, find Problem 2, "Computation Graphs on Steroids" on page 1. The problem gives you a computation graph for a single neuron with a sigmoid activation function \sigma(z). It provides numerical values for the inputs and weights, and the upstream gradient \frac{\partial L}{\partial \alpha}. Your task is to compute the symbolic gradients for the inputs and weights, specifically: \frac{\partial \alpha}{\partial x_0}, \frac{\partial \alpha}{\partial w_0} \frac{\partial \alpha}{\partial x_1}, \frac{\partial \alpha}{\partial w_1} \frac{\partial \alpha}{\partial w_2} (which corresponds to the bias term) You will need the derivative of the sigmoid function, which is \sigma'(z) = \sigma(z)(1-\sigma(z)). Use the chain rule as we've discussed. Once you have your answers, you can check them against the Solutions for Problem 2 on page 6 of the same document.
Working through this problem will confirm that you can move from the conceptual understanding of the chain rule to its practical application in calculating the exact update rules for a neuron's parameters.
Conclusion
In this lesson, we moved from the general theory of backpropagation to the concrete application of deriving the learning rules for a single neuron. By applying the chain rule, we uncovered an elegant and intuitive result: the update for a given weight is proportional to the final error, the local gradient of the activation function, and the magnitude of the input that flowed through that weight.
Key Takeaways:
- The gradient of the loss with respect to a neuron's weight can be decomposed via the chain rule: .
- This simplifies to: .
- The gradient for the bias, , is similar but lacks the input term : .
- These gradients directly inform the gradient descent update, telling the algorithm precisely how to adjust each parameter to minimize the loss.
So far, we have considered a single output neuron. But what happens in a multi-layer network? To calculate the gradient for a weight in a hidden layer, the chain of derivatives must pass through all subsequent layers. In our next lesson, we will explore this, discovering how gradients are summed over multiple paths and encountering the famous vanishing and exploding gradient problems.