Backprop From Scratch
The chain rule becomes a machine for learning.

The lesson
Backpropagation starts from a simple idea: treat a model as a computational graph, where each node is a small mathematical operation and the whole network is just one larger expression. Karpathy emphasizes that this is not specific to neural networks; a neural net is still just a mathematical expression, so the same differentiation machinery applies to it as to any other composed function12. This framing matters because it turns training from mysterious "AI" behavior into ordinary calculus on a graph of additions, multiplications, and nonlinearities.
The key mechanism is the chain rule applied locally. Each operation knows how its output changes with respect to its inputs, and during the backward pass those local derivatives are combined with the gradient coming from above; when gradients flow through a path, the correct operation is multiplication3. That is why backprop can scale: you do not symbolically differentiate the entire expression at once, you let each small gate contribute its piece, such as tanh using its own local backward rule4.
Autograd is the system that automates this bookkeeping. Karpathy describes micrograd as a tiny autograd engine that implements backpropagation, storing enough information during the forward pass so the backward pass can traverse the graph and accumulate gradients efficiently52. Once those gradients tell you how each parameter affects the loss, learning becomes a repeated loop of running the model, propagating gradients backward, and nudging parameters to reduce the loss62.
This also explains why neural networks can fail to learn well if the signals inside the graph are unhealthy. If the model starts with outputs that are far too extreme, it can be confidently wrong at initialization instead of behaving like a near-uniform predictor, which makes optimization harder78. And because nonlinearities shape gradient flow, saturated activations can shrink useful learning signals, so inspecting activations and gradients is part of understanding whether backprop is giving the network a chance to improve74.
Once you see training as gradients flowing through a graph, the parameter update step becomes intuitive. A gradient tells you which direction increases the loss, so you move parameters in the opposite direction, repeating this many times; learning rate choices then control how large those nudges are, and can be reduced over time for finer adjustments69. Karpathy's larger point is that modern deep learning works because we can efficiently compute exact gradients through large expressions and use them to iteratively improve parameters2.
5 principles from Andrej Karpathy
See a neural network as a computation graph
Treat every model as a composition of small operations instead of a monolithic black box. This makes differentiation and debugging concrete, because each piece has a clear forward computation and a clear local effect on the output.
“Even neural networks are just a mathematical expression.”
Apply the chain rule locally
Backprop works by letting each operation contribute its local derivative and combining it with the incoming gradient. In practice, this means gradients are propagated step by step through the graph rather than by deriving one huge formula.
“…the correct thing to do is to multiply them…”
Use autograd to automate gradient bookkeeping
An autograd engine records enough structure during the forward pass to run a backward pass later. This lets you focus on defining the computation while the system computes parameter gradients needed for learning.
“…micrograd is basically an autograd engine.”
Diagnose learning by inspecting outputs and gradients
If a network starts off overly certain, it may be confidently wrong and harder to optimize. Check whether initial predictions look reasonable and whether nonlinearities are allowing gradients to pass instead of crushing them.
“…the network is very confidently wrong…”
Train by repeated small parameter nudges
The training loop is a rhythm: compute predictions, backpropagate gradients, then update parameters. Learning rate controls the size of each step, and shrinking it over time can help with fine-tuning later in training.
“…forward, backward, update; forward, backward, update.”
In his own words
The quotes behind the lesson, word for word from the transcripts. Numbers match the lesson above.
“Even neural networks are just a mathematical expression.”
“Micrograd is basically an autograd engine. Autograd is short for automatic gradient, and really what it does is it implements backpropagation. Now, backpropagation is this algorithm that allows you to efficiently evaluate the gradient of some kind of a loss function with respect to the weights of a neural network, and what that allows us to do then is we can iteratively tune the weights of that neural network to minimize the loss function and therefore improve the accuracy of the network. So backpropagation would be at the mathematical core of any modern deep neural network library, like say PyTorch or JAX. So the functionality of micrograd is, I think, best illustrated by an example, so…”
“…the correct thing to do is to multiply them…”
“…the backward pass for tanh is one minus t squared…”
“…micrograd is basically an autograd engine.”
“…forward, backward, update; forward, backward, update.”
“…the network is very confidently wrong…”
“At initialization, we have no reason to believe any characters to be much more likely than others, and so we'd expect that the probability distribution that comes out initially is a uniform distribution assigning about equal probability to all the 27 characters. So basically, what we'd like is the probability for any character would be roughly 1 over 27. That is the probability we should record, and then the loss is the negative log probability. So let's wrap this in a tensor and then we can take the log of it, and then the negative log probability is the loss we would expect, which is 3.29, much, much lower than 27.”
“You'll notice that in the update here, the learning rate is scaled as a function of number of iterations, and it shrinks. This is something called learning rate decay. So, in the beginning, you have a high learning rate, and as the network sort of stabilizes near the end, you bring down the learning rate to get some of the fine details in the end. And in the end, we see the decision surface of the neural net, and we see that it learns to separate out the red and the blue area based on the data points.”
Reflect
- Pick a simple function with a few operations, like a weighted sum followed by tanh. Can you describe the forward pass and then explain, node by node, how the gradient would move backward?
- Think of a model or system you have worked with that felt like a black box. How would representing it as a computation graph change the way you debug or improve it?
- When you initialize a model or start a project, what would count as a healthy baseline behavior before optimization begins?
Check your understanding
Go deeper
Andrej Karpathy on Backpropagation: Computational Graphs and Gradients2016 · 80 min · full transcript
Andrej Karpathy on Neural Networks: Building Micrograd2021 · 146 min · full transcript
Andrej Karpathy on Activations & Gradients: BatchNorm2021 · 116 min · full transcript
- What is micrograd and why did Andrej Karpathy build it?
- Why does Andrej Karpathy say neural networks are arranged in layers?
- What initialization loss did Andrej Karpathy expect for a character-level language model?
- How does Andrej Karpathy use learning rate decay in training neural networks?
- What did Andrej Karpathy say about overfitting and hyperparameter tuning?