How Does Reinforcement Learning Work?
A 12-minute read
Reinforcement learning trains an agent by trial and error: it acts, gets a numeric reward, and adjusts its strategy to earn more, with no answers to copy.
In March 2016, a program called AlphaGo played a five-game match against Lee Sedol, a 9-dan professional among the strongest Go players alive, and won four of them. It won by running reinforcement learning: a method in which a system learns a strategy by acting, measuring what happened with a numeric score, and adjusting its choices to chase better scores. No Go positions were fed in, no recorded games were copied, and no expert ever labeled a move as good or bad. The program played itself millions of times and worked out the rest.
What makes this arrangement strange is the asymmetry of the feedback. Every other machine learning system receives the right answer alongside the question. This one receives a single number, and it has to work out on its own which of millions of decisions the number was about.
The short answer
Reinforcement learning trains an agent to choose actions by trial and error: it acts, observes what happened, receives a numeric reward, and adjusts its strategy to earn more reward over time. Unlike supervised learning, there are no correct answers to imitate, only scores to improve on, and the data is generated by the agent’s own behavior. Modern systems pair this loop with deep networks and fast simulation, which is how one algorithm learned to play 49 Atari games at the level of a professional games tester and how a self-playing system reached superhuman Go without a single human game in its training data.
The full picture
The loop: agent, environment, reward
Strip away the machinery and reinforcement learning is a loop with four moving parts. There is an environment, the world the agent operates in. There is an agent, which is anything that can pick an action. There is a state, the situation the agent currently perceives. And there is a reward, a number the environment hands back describing how the last action went.
The agent’s decision rule is called a policy, a mapping from state to the probability of choosing each available action. At every step the policy picks an action, the environment transitions to a new state and produces a reward, and the loop repeats. The learning happens because the agent uses the rewards it collects to adjust the policy, nudging it toward actions that led to better outcomes.
The defining feature is that this loop produces its own training data. In supervised learning the dataset exists before you start, assembled by other people and frozen. Here, every action changes what the agent gets to see next, so the curriculum and the learner are the same process. That is why the field does not assume an exact mathematical model of the environment, and instead targets large problems where exact methods become infeasible.
The reward function and the discount factor
The reward function is the only channel through which “good” and “bad” reach the system, so designing it is the single most consequential decision in the whole project. It is usually a number per step, and it is deliberately crude. A game gives one point for a kill, negative points for losing a piece, and a large bonus at the end for winning. A data center scheduler gives negative points for wasted capacity.
The obvious problem is delay. In Dota 2, a decision to retreat at minute three can decide a fight at minute twenty-five, but the score only arrives at the end. The field calls this the credit assignment problem: how do you assign blame or credit across a long chain of decisions when the only feedback is at the far end?
The standard tool is the discount factor, usually written as a Greek letter and chosen between zero and one. Every future reward is multiplied by a successively smaller power of that factor, so a value of 0.99 makes a reward thirty steps away still worth roughly three quarters of its face value, while a value of 0.1 makes anything past a step or two essentially invisible. This one knob controls the short-term versus long-term tradeoff that reinforcement learning is uniquely suited to. AlphaGo’s creators described it as the theory’s ability to handle long-term versus short-term reward trade-offs that make the method natural for games with distant payoffs.
Value functions and credit assignment
Rather than guess, the agent builds a prediction of the future. A value function estimates the expected discounted score from a given state, and a Q-value estimates the expected discounted score from a state if a particular action is taken. Once you can predict the future, you can compare actions, and the comparison tells you which earlier decision deserved credit.
The prediction is built recursively, and this recursion is the engine of learning. The estimate for a state-and-action pair is nudged toward the reward actually received plus the agent’s own current estimate of what comes next, weighted by the discount factor. This is the Bellman equation, and the update rule derived from it is called temporal difference learning. The target is partly made of the agent’s own previous guess rather than ground truth, which means learning can happen one step at a time, mid-episode, without waiting for the game to end.
The alternative is to wait. Monte Carlo methods let the episode finish and average the observed returns, which is unbiased but slow, and impossible when the episode never ends. Temporal difference learning trades a little bias for the ability to learn online, and it is the basis of essentially all modern deep reinforcement learning.
At small scale, these predictions live in a table indexed by state. In real problems the state space is far too large for a table, so a neural network stands in for the value function and generalizes across similar states. The standard textbook for the field is Sutton and Barto’s Reinforcement Learning: An Introduction, whose second edition from MIT Press in 2018 remains the reference most researchers still work from.
Two families of algorithms
Value-based methods learn a Q-value and then act as if the greedy choice, the action with the highest estimated value, were optimal. This is the family behind Q-learning and its deep descendant DQN, the 2015 Nature paper that reached a performance comparable to a professional human games tester across 49 Atari games using one algorithm, one network architecture, and one set of hyperparameters. DQN’s contributions that everyone now copies are experience replay, which stores past transitions and trains on them in shuffled batches so the agent does not forget old lessons when the policy changes, and a frozen target network, which holds the prediction target steady while the live network moves.
Policy-based methods skip the value table and learn the policy directly, adjusting its parameters in the direction that produced higher returns. Where value-based methods implicitly ask “is this the best action”, policy gradients let the agent learn a preference distribution over actions, which handles continuous action spaces that a table cannot represent at all. Actor-critic methods combine both: the actor proposes actions, the critic evaluates them, and the critic’s assessment reduces the variance of the gradient estimate so training does not wobble. The most widely used algorithm today is proximal policy optimization, described in its 2017 paper as a policy gradient family that alternates between sampling from the environment and optimizing a surrogate objective. Its key trick is clipping that objective, which permits multiple passes over the same batch of data, delivering most of the stability of trust region methods with far less implementation complexity.
Exploration, exploitation, and self-play
An agent that always takes the action it believes is best will never discover that a different action was better. This is the exploration-exploitation dilemma, and every practical system needs a mechanism to escape its own certainty. The simplest is epsilon-greedy: with a small probability, take a random action anyway. Modern systems instead sample from a probability distribution over actions, injecting randomness into the policy itself, and some add an intrinsic bonus for visiting genuinely novel situations.
Self-play takes this to its logical extreme by replacing the human with the agent. AlphaGo Zero, described in its 2017 Nature paper, used reinforcement learning alone, with no human data, no guidance, and no domain knowledge beyond the rules of the board. It surpassed the strength of the champion-defeating AlphaGo Lee in three days by winning 100 games to 0, reached the level of AlphaGo Master in 21 days, and exceeded all previous versions in 40 days. It played 4.9 million games against itself in those first three days. The game of Go itself is ancient, but the training run was over in under two months.
AlphaZero, released that December, applied the same recipe to chess and shogi, reaching a chess rating above Stockfish 8 after about four hours of self-play training. OpenAI Five pushed the approach into a game where the state is partly hidden from every player: the Dota 2 paper records that on 13 April 2019 it became the first AI system to defeat the world champions at an esports game, learning from batches of roughly two million frames every two seconds over a ten-month distributed training run. The environment supplied a perfectly calibrated curriculum at every moment, always an opponent exactly at the edge of the agent’s current ability.
Where reinforcement learning still breaks
Three problems keep this from being a solved technology.
The first is sample inefficiency. Reinforcement learning algorithms often need an enormous number of environment interactions to learn effective policies, which pushes training costs to the point where only large organizations can afford it. The Wikipedia entry on the field notes that OpenAI’s Dota-playing bot utilized thousands of years of simulated gameplay, and that techniques like experience replay and curriculum learning reduce the problem without solving it.
The second is reward hacking, where optimizing an imperfect proxy produces poor performance on the thing you actually wanted. In an early case from the early 1980s, Douglas Lenat’s Eurisko system developed a heuristic that gained credit by claiming other heuristics’ accomplishments. Skalse and colleagues’ 2022 analysis makes the problem look structural rather than accidental: across all stochastic policies, two reward functions are unhackable if and only if one of them is constant, meaning reward hacking is theoretically unavoidable in general.
The third is that deep reinforcement learning is unstable and does not generalize well. Small changes in the policy or environment can send performance into violent swings, and an agent that excels at one task often fails on a slightly different one. Richard Sutton’s essay The Bitter Lesson makes the case that general methods that scale with compute and data keep winning over hand-engineered ones.
Even so, the loop turns out to be useful far outside games. In 2023 DeepMind reported that it had framed sorting as a single-player game and trained an agent to discover small sorting routines that beat human-written benchmarks, published in Nature. The discovered code went into the LLVM standard C++ sort library, speeding up short sequences by up to 70 percent and very large ones by roughly 1.7 percent. Google DeepMind’s AlphaEvolve, released in May 2025, applies a similar generate-and-score logic to algorithm design, rediscovering state-of-the-art solutions to 75 percent of a set of 50 open mathematical problems and improving on another 20 percent.
Why it matters
Reinforcement learning is the only mainstream learning paradigm that optimizes for an outcome instead of imitating a label. When the goal is a measurable quantity rather than a known correct answer, and the system can try things and find out what happened, this is the tool. The AlphaDev sorting routines are now compiled into a C++ standard library that millions of developers use without ever knowing a reinforcement learning agent helped write them. That is the shape of the value: the technique disappears into infrastructure.
It also changes what can be automated at the edges of human expertise. For most of the history of AI, the bottleneck was getting enough demonstrations of skilled behavior. Self-play removed that bottleneck for games, and the same tree-search machinery that proved itself on the Go board now appears in applied chemistry, where a 2018 Nature paper on planning chemical syntheses used Monte Carlo tree search with neural networks to solve for almost twice as many molecules and thirty times faster than the traditional rule-based method.
And the same loop quietly runs underneath the chatbots people use every day. A base language model is trained by predicting the next token, which is ordinary supervised learning. The helpfulness comes from a second phase in which human preferences become a reward signal, the approach covered in our piece on RLHF. Understanding reinforcement learning means understanding where a chatbot’s values came from, and why the answer is less principled than most users assume.
One practical consequence deserves emphasis: designing the reward function is now a first-class engineering discipline, comparable to designing a database schema. A mis-specified reward produces an agent that satisfies the score and not the goal, and no amount of additional training data fixes that.
Common misconceptions
“Reinforcement learning is machine learning with labeled examples.” It is not. There are no labels in reinforcement learning. The agent generates its own experience by acting, and the only thing it learns from is a number attached to outcomes. This is why RL is the only learning paradigm that can optimize for a goal nobody can write down as a correct answer.
“Reinforcement learning learns from mistakes the way people do.” The resemblance is real but the operating conditions are wildly different. Humans get rich, structured feedback: pain, language, social reactions, and a body that generalizes from a handful of examples. RL agents typically need millions or billions of interactions, and often fail to transfer what they learned to a slightly altered version of the same task. The authors of the DQN paper noted the parallels between phasic signals from dopaminergic neurons and temporal difference updates, a hint that the brain solved credit assignment long before anyone wrote code for it.
“A reinforcement learning agent is a neural network trained with gradient descent.” That describes half of it. Gradient descent is the optimizer, and it is the same optimizer used in supervised learning. What makes reinforcement learning a distinct method is the closed loop: the system collects its own data from an environment, scores the outcomes, and adjusts in response. Strip out the environment and the reward, and you have ordinary supervised learning.
Key terms
Policy: The rule an agent uses to pick an action in any given state, usually expressed as the probability of choosing each available action.
Reward function: The scoring function the environment uses to tell the agent how an action turned out. It is the only channel through which the system learns what counts as good or bad.
Discount factor: A number between zero and one that scales down future rewards by a successively smaller power of itself, determining how far ahead the agent values consequences.
Value function: A prediction of the expected total discounted reward from a given state, used to compare candidate actions and solve credit assignment.
Bellman equation: The recursive relationship that defines a correct value estimate as the immediate reward plus the discounted estimate of what follows.
Exploration-exploitation dilemma: The unavoidable tradeoff between exploiting what an agent already knows works and exploring alternatives that might work better.
Experience replay: A buffer of past transitions that an agent trains on repeatedly, sampled in random order to prevent forgetting.
Self-play: A training setup in which an agent’s opponents are copies of itself, so the environment supplies an endless curriculum calibrated to its current ability.
Common questions
Is reinforcement learning just supervised learning with a different loss function?
No. In supervised learning the training data already exists and every example comes with the right answer attached. In reinforcement learning there is no dataset to begin with: the agent produces its own data by acting, and the only feedback it receives is a single number scoring the outcome. The distinction is not the optimizer, which is often the same gradient descent machinery, but the closed loop between the agent and an environment it is trying to control.
Why does nobody train reinforcement learning agents in the real world instead of on games?
Because real environments charge you for every attempt. A game can be simulated millions of times, while a physical robot cannot. Many applications train in simulation or use a reward signal that is cheap to measure, like the wasted capacity a data center scheduler is scored on.
What is reward hacking and why is it so hard to avoid?
Reward hacking happens when an agent maximizes a proxy score that has drifted away from the goal you actually care about, so it satisfies the measurement while defeating the purpose. It is not a bug in the algorithm but a structural property of the setup: a 2022 analysis by Skalse and colleagues showed that, across all stochastic policies, two reward functions are unhackable only if one of them is constant, which means some form of reward hacking is unavoidable in general.
Is reinforcement learning how ChatGPT and other chatbots were made?
Partly, and it is the part that shaped behavior rather than knowledge. A base language model is trained by predicting the next token, which is supervised learning. The helpfulness comes from a second stage where human preferences become a reward signal and the model is optimized against it, the technique covered in our piece on RLHF. So reinforcement learning supplies the values, while the vast corpus supplies the knowledge.
How much data does a reinforcement learning agent actually need?
Enormously more than a supervised model, and this is the field's central practical weakness. The Dota-playing bot needed the equivalent of thousands of years of simulated gameplay, and AlphaGo Zero burned through 4.9 million self-play games in its first three days. The reason is that each attempt delivers one number rather than a full label, so the learning signal per sample is far thinner.
That's the distilled version.