Q-Learning

Q-learning is a reinforcement learning algorithm that learns, purely from trial and error, how good each action is in each situation, storing that estimate as a value Q(state, action) for the total future reward expected if the agent takes that action now and behaves well afterwards. The "Q" stands for the quality of a state-action pair. Once these values are learned, acting well is easy: in any state, pick the action with the highest Q. Christopher Watkins introduced the method in his 1989 Cambridge PhD thesis, and Watkins and Dayan's 1992 paper "Q-learning" in the journal Machine Learning proved that, under suitable conditions, the estimates converge to the optimal values.

The learning rule is a Bellman update, which says in prose that the value of an action should equal the immediate reward plus the discounted value of the best action available from the state it leads to. After the agent takes an action, receives a reward and lands in a new state, it nudges its old estimate a fraction of the way toward a fresh target: new estimate = old estimate + learning rate × (reward + discount factor × best Q-value in the next state − old estimate). The bracketed difference is the temporal-difference error, the gap between what was predicted and what the one-step experience suggests. The discount factor (a number between 0 and 1, often 0.9 to 0.99) makes distant rewards count for less, and the learning rate controls how fast old beliefs are overwritten. Because the target uses the agent's own current estimate of the next state, the method bootstraps, improving guesses using other guesses, a defining property of temporal difference learning as described by Sutton and Barto.

State s
grid cell next to a cliff edge
Choose action a
epsilon-greedy: usually the best Q, sometimes a random try
Observe reward r and next state s'
for example reward −1 per step, −100 for falling off
Bellman update of the table entry Q(s, a)
Target
r + γ × max over a' of Q(s', a')
Error
target − current Q(s, a)
Update
Q(s, a) moves by α × error toward the target
Repeat for many episodes
Q-values converge; policy = pick the highest Q in each state

Q-learning is model-free and off-policy, two properties that explain both its popularity and its reach. Model-free means the agent never needs to know the rules of the environment (the transition probabilities or reward function); it learns only from sampled experience. Off-policy means it learns the value of the greedy, best-possible policy even while following a more exploratory one, because its target uses the maximum over next actions rather than the action actually taken. This is the difference from SARSA, whose update uses the next action the agent really takes and therefore learns the value of its own, exploring behavior; on the classic cliff-walking example in Sutton and Barto's textbook, Q-learning learns the shortest path hugging the cliff edge while SARSA learns a safer, longer route. Exploration is usually handled by epsilon-greedy action selection, taking a random action with small probability epsilon, often reduced over time.

A table of Q-values works for small problems but collapses when states are numerous or continuous, which is the problem that deep Q-networks (DQN) solved. The 2013 arXiv paper "Playing Atari with Deep Reinforcement Learning" and the 2015 Nature paper "Human-level control through deep reinforcement learning" (Mnih and colleagues at DeepMind) replaced the table with a convolutional neural network that takes raw screen pixels and outputs a Q-value for each joystick action, then trained a single architecture across 49 Atari 2600 games, reaching human-level or better performance on many. Two stabilizing ideas were essential: experience replay, storing past transitions and training on random mini-batches to break the correlation between consecutive frames, and a target network, a slowly updated frozen copy of the network used to compute the bootstrapped target so that the goalposts do not move on every step. Refinements followed, including Double DQN (van Hasselt, Guez and Silver, 2015), prioritized replay, dueling networks and the Rainbow combination (Hessel and colleagues, 2017).

The most common pitfalls come from instability and from the maximum operator. Taking a max over noisy estimates is biased upward, so Q-learning tends to overestimate action values, the issue Double Q-learning (van Hasselt, 2010) and Double DQN were designed to reduce. Combining function approximation, bootstrapping and off-policy learning, which Sutton and Barto call the deadly triad, can make learning diverge, which is why DQN needed its replay and target tricks. Tabular Q-learning also needs the agent to visit every state-action pair often enough, so convergence guarantees are asymptotic and say nothing about speed; reward design matters, since agents exploit whatever the reward actually pays for; and standard Q-learning handles discrete actions, so continuous control such as robot arms usually uses actor-critic methods (DDPG, SAC) that borrow Q-functions but add a separate policy.

Q-learning's place in the modern landscape is as the foundation of value-based reinforcement learning, in contrast to policy-gradient methods such as REINFORCE (Williams, 1992) and PPO. Value-based methods learn what each action is worth and derive behavior from it; policy-gradient methods learn the behavior directly; and actor-critic methods blend both. It is a standard first algorithm because it fits in a dozen lines of code and runs on small environments such as gridworlds and the toy-text tasks in the Gymnasium library, and its descendants are used in games, resource allocation and recommendation. Reinforcement learning from human feedback for language models, by contrast, mostly relies on policy-gradient methods rather than Q-learning.

Read Q-learning as a table of learned "how good is this move here" scores, updated after every experience by pulling each score toward the reward just received plus the best score available next, so that value flows backward from rewards, and deep Q-networks extend the same update to problems too large for any table.

Take Q-learning further

Ask the copilot about this term, or have our engineers assess it against your process.