The Bellman Equations
Imagine a robot navigating a warehouse, choosing actions that yield rewards now but change what is possible later. To evaluate a policy for such a robot, we need to know the long-run value of every state it might visit. Computing that value by simulating every possible future seems hopeless. The number of trajectories explodes exponentially with the horizon. Yet there is a shortcut hiding in the structure of the problem itself. The Bellman equations exploit a simple observation. The value of a state decomposes into the immediate reward plus the (discounted) value of wherever you end up next. This recursive relationship turns an infinite sum over trajectories into a finite, local condition. Every state's value must satisfy this self-consistency condition simultaneously. It is the mathematical backbone of nearly all of reinforcement learning. This spans from tabular dynamic programming to deep Q-networks. This idea is due to Richard Bellman's work on dynamic programming in the 1950s. It is not specific to reinforcement learning. It appears in control theory, operations research, and economics. In RL it takes a particular form because of the Markov Decision Process structure. The next state and reward depend only on the current state and action, never on the full history. That memorylessness is exactly what makes the recursion clean. This article develops the Bellman equations for both the state-value function and the action-value function, under a fixed policy. It shows how they arise from the definition of return. It gives the linear-algebra view of the equations as a system to be solved exactly. It also previews how they seed both dynamic programming and the optimality equations covered next.
- The Bellman equation expresses recursively: current value equals expected immediate reward plus discounted value of the next state.
- It follows directly from the definition of the return using the identity .
- There are matching equations for (state-value) and (action-value), and each can be written in terms of the other.
- For a fixed policy in a finite MDP, the Bellman equations form a linear system solvable exactly by matrix inversion.
- The Bellman equation is a consistency condition, not by itself a search procedure — but it is the equation every DP and TD algorithm is built to satisfy.
- It generalizes to the Bellman optimality equation by replacing the policy's expectation with a max over actions.
The value of a state equals the expected immediate reward plus the discounted expected value of whatever state comes next — a recursive identity, not an assumption, that follows from how returns are defined.
The idea
Recall that for a policy , the state-value function is defined as the expected return starting from state and following thereafter:
The return satisfies an immediate recursive identity purely from its definition as an infinite sum:
Substituting this into the definition of , and using the Markov Decision Process property that transitions depend only on the current state and action, gives the Bellman equation for :
In words: to evaluate a state, average over the policy's action choice, then average over the environment's stochastic transition, the sum of the immediate reward and the discounted value of the successor state. This is a one-step lookahead identity — it relates to for states reachable in a single transition, rather than to the entire future trajectory. The same idea gives the Bellman equation for the action-value function :
The two functions are mutual expectations of one another: , and . Substituting one definition into the other reproduces both Bellman equations above — they are two views of the same recursive consistency requirement, connected via State-Value and Action-Value Functions. Crucially, the Bellman equation is not an algorithm. It is a system of equations — one equation per state — that the true value function is guaranteed to satisfy. Whether we solve that system by matrix algebra, by iterative sweeps (Iterative Policy Evaluation), or by sampling (temporal-difference learning), is a separate question addressed elsewhere. Here the goal is to understand why the equation is true and what structure it reveals.
How it works
Deriving the equation. Start from the definition of and unroll one step of the expectation using the law of total expectation, conditioning first on the action chosen by , then on the resulting next state and reward given by the environment's dynamics . Because 's expectation given (and future policy behavior) is exactly by definition, this substitution closes the recursion — no term involving the raw return remains.
Solving it exactly (finite MDPs). For a finite MDP with states, write the Bellman equation in matrix form. Define the policy-induced reward vector with entries , and the policy-induced transition matrix with entries . Then:
This closed form is exact, but inverting an matrix costs — often impractical for large state spaces, which is precisely why iterative methods dominate practice.
Iterative view. Treat the Bellman equation as a fixed-point condition for an operator acting on value functions:
is the unique fixed point: . Repeatedly applying to any starting guess converges to — this is the basis of iterative policy evaluation, foreshadowed here and developed as its own topic. ```
# Computing one application of the Bellman operator T^pi
# Inputs: policy pi, dynamics p(s', r | s, a), discount gamma, current estimate V
# Output: updated value estimate V_new (one Bellman "backup" per state) function BELLMAN_BACKUP(pi, p, gamma, V): V_new = array of size |S|, initialized to 0 for each state s in S: total = 0 for each action a with pi(a | s) > 0: action_value = 0 for each (s_next, r) with p(s_next, r | s, a) > 0: action_value += p(s_next, r | s, a) (r + gamma V[s_next]) total += pi(a | s) * action_value V_new[s] = total return V_new
# Checking the Bellman equation holds (a consistency test, not a solver) function CHECK_CONSISTENCY(V, pi, p, gamma, tolerance): V_updated = BELLMAN_BACKUP(pi, p, gamma, V) return max over s of |V_updated[s] - V[s]| < tolerance ``` The pseudocode above is deliberately not an optimization loop — it computes a single right-hand side evaluation of the Bellman equation for every state. Running it repeatedly to convergence is the subject of iterative policy evaluation; here it illustrates that the Bellman equation's right-hand side is a well-defined, computable quantity given , , and the model.
Complexity & correctness
Cost of one backup. For a single state, the backup sums over all actions with nonzero policy probability, and for each action over all possible pairs. If there are actions and at most possible successor states, one backup costs . Doing this for every state costs per full sweep — this is the per-iteration cost inherited by iterative policy evaluation, and it is why the Bellman equation itself, while exact, is expensive to evaluate exhaustively on large state spaces.
Cost of exact solution. Solving directly requires forming and inverting an matrix, costing via Gaussian elimination. This is exact and non-iterative but scales poorly; it is rarely used beyond small MDPs or as a ground-truth check for iterative methods.
Correctness: existence and uniqueness of . Why does the Bellman equation have a solution, and why is it exactly the true value function? Two arguments: 1. Derivation argument. The equation is derived directly from the definition of using only the recursive structure of the return and the Markov property. So trivially satisfies its own Bellman equation — existence of a solution is immediate because we constructed the equation from a function we already know exists. 2. Uniqueness via contraction. Define the Bellman operator as above, acting on the space of bounded value functions with the supremum norm . For any two value functions :
using that (a proper probability distribution) so the inner expression is a convex combination, bounded by . Since , is a contraction mapping with modulus . By the Banach fixed-point theorem, has a unique fixed point, and iterating from any starting converges to it geometrically fast:
This is the mathematical guarantee underlying iterative policy evaluation, and it confirms that the Bellman equation pins down uniquely (assuming , or with guaranteed termination in episodic tasks).
Honest tradeoffs. The linear-algebra solution is exact but cubic in state count and requires full knowledge of the model . The Bellman equation itself says nothing about how to find an optimal policy — that requires the closely related but distinct Bellman Optimality Equation, which replaces the policy average with a max over actions and is nonlinear. Also, everything here assumes a known, tabular model; when the model is unknown or the state space is continuous, the Bellman equation still holds in principle but must be estimated from samples (temporal-difference methods) or approximated with function approximators — introducing bias and variance tradeoffs not present in the exact tabular case.
Worked example
Consider a tiny 3-state MDP: Study, Break, Done (terminal), with . The agent follows a fixed policy : from Study, it takes action "continue" with probability 0.7 (reward , stays in Study) and "rest" with probability 0.3 (reward , moves to Break). From Break, it always takes "resume" (reward , moves back to Study) — for simplicity assume no path to Done to keep the example a clean two-state recursion (a self-loop system), which still exercises the full Bellman machinery. The Bellman equations for this policy are:
Let , . Expanding:
Substitute the second into the first:
Then . Check by plugging back into the original equation for Study:
The equation is self-consistent, as required. The table below traces a few iterations of the Bellman backup starting from , illustrating the contraction toward this exact solution:
| Iteration | |||
|---|---|---|---|
| 0 | 0.000 | 0.000 | 8.898 |
| 1 | 1.400 | -1.000 | 7.498 |
| 2 | 2.415 | -0.740 | 6.483 |
| 3 | 3.156 | -0.174 | 5.742 |
| 4 | 3.735 | 0.340 | 5.163 |
| 8.898 | 7.008 | 0 |
Each row is one call to `BELLMAN_BACKUP`; the error shrinks geometrically at rate approximately per full sweep here (the effective contraction on this particular chain), matching the theoretical bound.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Confusing the Bellman equation with the Bellman optimality equation | Both look similar; one averages over , the other maximizes over actions | Always check whether the equation has or |
| Forgetting the discount factor in the recursive term | Easy to drop when writing | Always write , never , unless is explicitly justified (episodic) |
| Treating the equation as an update rule without realizing it needs the true on the right | The equation is a fixed-point condition, not automatically satisfied by an arbitrary guess | Use it iteratively (apply repeatedly) or solve the linear system exactly |
| Assuming convergence for in a non-terminating (continuing) task | The contraction argument requires or guaranteed episode termination | Verify episodic termination or use |
| Applying the tabular linear-system solution to large or continuous state spaces | matrix inversion is infeasible beyond small | Use iterative policy evaluation or sampling-based (TD) methods instead |
Pioneers & history
Origins · 1 minRichard E. Bellman and how this was discovered
Bellman developed the theory of dynamic programming to solve multistage decision problems, introducing the principle of optimality: an optimal policy has the property that, whatever the initial decision, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision. This principle is precisely what licenses the recursive decomposition of value into "immediate reward plus value of what follows," the mathematical seed of everything in this article and of the field of reinforcement learning built atop it.
Where this matters
The Bellman equation is the theoretical foundation beneath essentially every value-based reinforcement learning method used in practice. Dynamic programming methods — policy evaluation and policy iteration — directly implement its fixed-point structure on tabular MDPs, and remain the standard teaching tool and a component of planning modules in model-based systems. Temporal-difference learning methods (TD(0), SARSA, Q-learning) are best understood as sampling-based approximations to the Bellman backup, replacing the exact expectation over the model with a single observed transition — this is the bridge to model-free RL. Deep reinforcement learning systems, including Deep Q-Networks used in Atari-playing agents and value-based components of modern policy-gradient methods, train neural networks to approximately satisfy a Bellman equation via a squared "Bellman error" loss, minimizing the discrepancy between a network's current prediction and a bootstrapped target built from the same recursive identity. Large-scale industrial recommender systems and resource-allocation controllers that use RL for sequential decisions — ad placement, inventory control, robotic control — all rely on some approximate solution to a Bellman equation, whether solved exactly, iteratively, or via sampled gradient updates. The concept also underlies model-predictive control and classical operations-research techniques for inventory and scheduling problems that predate modern RL by decades, showing the equation's reach well beyond machine learning.
Ask the tutor: How does replacing the policy-weighted average with a max over actions transform this into the Bellman optimality equation, and why does that change break the linearity of the system?
Is the Bellman equation itself an algorithm I can run?
No. The Bellman equation is a mathematical identity — a consistency condition that the true value function satisfies. It does not, by itself, specify a procedure for computing . What turns it into an algorithm is choosing a method to solve or approximately satisfy that equation: exact linear algebra (matrix inversion), iterative sweeps that repeatedly apply the Bellman operator (iterative policy evaluation), or sampling-based updates from observed transitions (temporal-difference learning). Think of the equation as the specification and these methods as different implementations that all converge toward the same unique solution under standard assumptions like .
Why does the Bellman equation only look one step ahead instead of the whole future?
Because of the Markov property, the entire future depends on the present only through the current state — not through how you got there. This means the expected return from any state can be decomposed exactly into the immediate reward plus the expected return from wherever you land next, with no information lost by truncating the recursion at one step. The full future is still accounted for, just implicitly, through the value of the successor state, which itself encodes everything that would happen afterward. This is what makes the equation both exact and computationally tractable.
What happens to the Bellman equation if the discount factor equals 1?
The equation itself is still valid, but the contraction-mapping argument for uniqueness of the fixed point breaks down, because the operator is no longer guaranteed to shrink distances between value functions. In episodic tasks that are guaranteed to terminate in a finite expected number of steps, is often still fine because the sum defining the return is finite in expectation. In continuing (non-terminating) tasks, however, can make the return, and hence the Bellman equation, undefined or unbounded, which is why discounting strictly less than 1 is standard for continuing problems.
How is the Bellman equation related to the Bellman optimality equation?
The Bellman equation described here evaluates a fixed policy : it averages over the policy's action probabilities and is a linear equation in . The Bellman optimality equation instead characterizes the value of the best possible policy, replacing the expectation over actions with a maximum over actions: . This maximum makes the optimality equation nonlinear, so it cannot be solved by simple matrix inversion, and it requires different algorithms such as value iteration. The equation in this article is the necessary stepping stone to understanding that one.
Can the Bellman equation be solved without knowing the environment's transition probabilities?
Not directly in its exact form, since it requires computing an expectation over . However, the equation still holds as a statement about the true value function even when the model is unknown, and this is exploited by model-free methods. Temporal-difference learning replaces the full expectation with a single sampled transition and updates the value estimate toward a "bootstrapped" target, effectively performing a stochastic approximation to the Bellman backup. Over many samples, this converges to the same value function the exact Bellman equation would give, under appropriate step-size and exploration conditions.
Why do we need both a Bellman equation and a Bellman equation?
They express the same underlying consistency but are useful in different contexts. is convenient when the policy is known and fixed, since evaluating a state doesn't require also specifying which action was taken. is more directly useful for improving a policy, since comparing across actions tells you which action is best without needing a model to simulate one step ahead — this is essential for methods like Q-learning and SARSA that select actions using estimated action values. The two are related by simple expectation identities, so knowing one lets you recover the other given the policy.
Does the Bellman equation assume the environment is deterministic?
No. The equation is written generally in terms of , a probability distribution over next states and rewards, which allows for fully stochastic environments. Deterministic environments are simply a special case where this distribution places all probability mass on a single pair for each , collapsing the sum into a single term. The recursive structure and the correctness argument via the contraction mapping hold identically in both stochastic and deterministic settings, as long as rewards are bounded and (or termination is guaranteed).