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.

Key takeaways
  • The Bellman equation expresses Vπ(s)V^\pi(s) recursively: current value equals expected immediate reward plus discounted value of the next state.
  • It follows directly from the definition of the return GtG_t using the identity Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}.
  • There are matching equations for VπV^\pi (state-value) and QπQ^\pi (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 core insight

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 π\pi, the state-value function is defined as the expected return starting from state ss and following π\pi thereafter:

Vπ(s)=Eπ[Gt∣St=s],Gt=Rt+1+γRt+2+γ2Rt+3+⋯V^\pi(s) = \mathbb{E}_\pi\left[ G_t \mid S_t = s \right], \qquad G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots

The return GtG_t satisfies an immediate recursive identity purely from its definition as an infinite sum:

Gt=Rt+1+γGt+1.G_t = R_{t+1} + \gamma G_{t+1}.

Substituting this into the definition of VπV^\pi, and using the Markov Decision Process property that transitions depend only on the current state and action, gives the Bellman equation for VπV^\pi:

Vπ(s)=∑aπ(a∣s)∑s′,rp(s′,r∣s,a)[r+γVπ(s′)].V^\pi(s) = \sum_{a} \pi(a\mid s) \sum_{s', r} p(s', r \mid s, a) \Big[ r + \gamma V^\pi(s') \Big].

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 Vπ(s)V^\pi(s) to Vπ(s′)V^\pi(s') for states s′s' reachable in a single transition, rather than to the entire future trajectory. The same idea gives the Bellman equation for the action-value function Qπ(s,a)=Eπ[Gt∣St=s,At=a]Q^\pi(s,a) = \mathbb{E}_\pi[G_t \mid S_t=s, A_t=a]:

Qπ(s,a)=∑s′,rp(s′,r∣s,a)[r+γ∑a′π(a′∣s′)Qπ(s′,a′)].Q^\pi(s,a) = \sum_{s', r} p(s', r \mid s, a)\left[ r + \gamma \sum_{a'} \pi(a' \mid s') Q^\pi(s', a') \right].

The two functions are mutual expectations of one another: Vπ(s)=∑aπ(a∣s) Qπ(s,a)V^\pi(s) = \sum_a \pi(a\mid s)\, Q^\pi(s,a), and Qπ(s,a)=E[Rt+1+γVπ(St+1)∣St=s,At=a]Q^\pi(s,a) = \mathbb{E}[R_{t+1} + \gamma V^\pi(S_{t+1}) \mid S_t=s, A_t=a]. 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 VπV^\pi 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 Vπ(s)V^\pi(s) and unroll one step of the expectation using the law of total expectation, conditioning first on the action AtA_t chosen by π\pi, then on the resulting next state St+1S_{t+1} and reward Rt+1R_{t+1} given by the environment's dynamics p(s′,r∣s,a)p(s', r \mid s, a). Because Gt+1G_{t+1}'s expectation given St+1=s′S_{t+1}=s' (and future policy behavior) is exactly Vπ(s′)V^\pi(s') by definition, this substitution closes the recursion — no term involving the raw return remains.

Solving it exactly (finite MDPs). For a finite MDP with nn states, write the Bellman equation in matrix form. Define the policy-induced reward vector rπ∈Rn\mathbf{r}^\pi \in \mathbb{R}^n with entries rπ(s)=∑aπ(a∣s)∑s′,rp(s′,r∣s,a) rr^\pi(s) = \sum_a \pi(a\mid s)\sum_{s',r} p(s',r\mid s,a)\, r, and the policy-induced transition matrix Pπ∈Rn×nP^\pi \in \mathbb{R}^{n\times n} with entries Pπ(s,s′)=∑aπ(a∣s)∑rp(s′,r∣s,a)P^\pi(s,s') = \sum_a \pi(a\mid s) \sum_r p(s',r\mid s,a). Then:

Vπ=rπ+γPπVπ⟹Vπ=(I−γPπ)−1rπ.\mathbf{V}^\pi = \mathbf{r}^\pi + \gamma P^\pi \mathbf{V}^\pi \quad\Longrightarrow\quad \mathbf{V}^\pi = (I - \gamma P^\pi)^{-1} \mathbf{r}^\pi.

This closed form is exact, but inverting an n×nn \times n matrix costs O(n3)O(n^3) — 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 TπT^\pi acting on value functions:

(TπV)(s)=∑aπ(a∣s)∑s′,rp(s′,r∣s,a)[r+γV(s′)].(T^\pi V)(s) = \sum_a \pi(a\mid s) \sum_{s',r} p(s',r\mid s,a)\left[r + \gamma V(s')\right].

VπV^\pi is the unique fixed point: TπVπ=VπT^\pi V^\pi = V^\pi. Repeatedly applying TπT^\pi to any starting guess converges to VπV^\pi — 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 VV, π\pi, and the model.

Figure
One Bellman backup: state s looks one step ahead through actions, transitions, and rewards
s a₁ a₂ a₃ π(a₁|s) π(a₂|s) π(a₃|s) s'₁ s'₂ s'₃ s'₄ p(s',r|s,a) r + γV(s'₁) r + γV(s'₂) r + γV(s'₃) r + γV(s'₄) V(s) = weighted average of all shaded boxes over actions and transitions

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 (s′,r)(s', r) pairs. If there are ∣A∣|A| actions and at most ∣S∣|S| possible successor states, one backup costs O(∣A∣⋅∣S∣)O(|A|\cdot|S|). Doing this for every state costs O(∣S∣2∣A∣)O(|S|^2 |A|) 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 Vπ=(I−γPπ)−1rπ\mathbf{V}^\pi = (I - \gamma P^\pi)^{-1}\mathbf{r}^\pi directly requires forming and inverting an ∣S∣×∣S∣|S|\times|S| matrix, costing O(∣S∣3)O(|S|^3) 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 VπV^\pi. 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 Vπ(s)=Eπ[Gt∣St=s]V^\pi(s) = \mathbb{E}_\pi[G_t \mid S_t=s] using only the recursive structure of the return and the Markov property. So VπV^\pi 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 TπT^\pi as above, acting on the space of bounded value functions with the supremum norm ∥V∥∞=max⁡s∣V(s)∣\|V\|_\infty = \max_s |V(s)|. For any two value functions U,VU, V:

∥TπU−TπV∥∞=γmax⁡s∣∑aπ(a∣s)∑s′Pπ(s,s′)(U(s′)−V(s′))∣≤γ∥U−V∥∞,\|T^\pi U - T^\pi V\|_\infty = \gamma \max_s \left| \sum_a \pi(a\mid s) \sum_{s'} P^\pi(s,s')\big(U(s') - V(s')\big) \right| \le \gamma \|U - V\|_\infty,

using that ∑aπ(a∣s)∑s′Pπ(s,s′)=1\sum_a \pi(a\mid s)\sum_{s'} P^\pi(s,s') = 1 (a proper probability distribution) so the inner expression is a convex combination, bounded by max⁡s′∣U(s′)−V(s′)∣\max_{s'}|U(s')-V(s')|. Since γ<1\gamma < 1, TπT^\pi is a contraction mapping with modulus γ\gamma. By the Banach fixed-point theorem, TπT^\pi has a unique fixed point, and iterating TπT^\pi from any starting V0V_0 converges to it geometrically fast:

∥Vk−Vπ∥∞≤γk∥V0−Vπ∥∞.\|V_k - V^\pi\|_\infty \le \gamma^k \|V_0 - V^\pi\|_\infty.

This is the mathematical guarantee underlying iterative policy evaluation, and it confirms that the Bellman equation pins down VπV^\pi uniquely (assuming γ<1\gamma < 1, or γ=1\gamma = 1 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 p(s′,r∣s,a)p(s',r\mid s,a). 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 γ=0.9\gamma = 0.9. The agent follows a fixed policy π\pi: from Study, it takes action "continue" with probability 0.7 (reward +2+2, stays in Study) and "rest" with probability 0.3 (reward +0+0, moves to Break). From Break, it always takes "resume" (reward −1-1, 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:

Vπ(Study)=0.7[2+0.9 Vπ(Study)]+0.3[0+0.9 Vπ(Break)]V^\pi(\text{Study}) = 0.7\big[2 + 0.9\, V^\pi(\text{Study})\big] + 0.3\big[0 + 0.9\, V^\pi(\text{Break})\big]
Vπ(Break)=1.0[−1+0.9 Vπ(Study)]V^\pi(\text{Break}) = 1.0\big[-1 + 0.9\, V^\pi(\text{Study})\big]

Let x=Vπ(Study)x = V^\pi(\text{Study}), y=Vπ(Break)y = V^\pi(\text{Break}). Expanding:

x=1.4+0.63x+0.27y⇒0.37x−0.27y=1.4x = 1.4 + 0.63x + 0.27y \quad\Rightarrow\quad 0.37x - 0.27y = 1.4
y=−1+0.9xy = -1 + 0.9x

Substitute the second into the first:

0.37x−0.27(−1+0.9x)=1.4  ⇒  0.37x+0.27−0.243x=1.4  ⇒  0.127x=1.13  ⇒  x≈8.8980.37x - 0.27(-1 + 0.9x) = 1.4 \;\Rightarrow\; 0.37x + 0.27 - 0.243x = 1.4 \;\Rightarrow\; 0.127x = 1.13 \;\Rightarrow\; x \approx 8.898

Then y=−1+0.9(8.898)≈7.008y = -1 + 0.9(8.898) \approx 7.008. Check by plugging back into the original equation for Study:

0.7[2+0.9(8.898)]+0.3[0+0.9(7.008)]=0.7(10.008)+0.3(6.307)=7.006+1.892=8.898.✓0.7[2 + 0.9(8.898)] + 0.3[0 + 0.9(7.008)] = 0.7(10.008) + 0.3(6.307) = 7.006 + 1.892 = 8.898. \checkmark

The equation is self-consistent, as required. The table below traces a few iterations of the Bellman backup starting from V0=(0,0)V_0 = (0,0), illustrating the contraction toward this exact solution:

Iteration kkVk(Study)V_k(\text{Study})Vk(Break)V_k(\text{Break})∥Vk−Vπ∥∞\lVert V_k - V^\pi \rVert_\infty
00.0000.0008.898
11.400-1.0007.498
22.415-0.7406.483
33.156-0.1745.742
43.7350.3405.163
⋯\cdots⋯\cdots⋯\cdots⋯\cdots
→∞\to\infty8.8987.0080

Each row is one call to `BELLMAN_BACKUP`; the error shrinks geometrically at rate approximately γ=0.9\gamma = 0.9 per full sweep here (the effective contraction on this particular chain), matching the theoretical bound.

Common pitfalls & traps

PitfallWhy it happensFix
Confusing the Bellman equation with the Bellman optimality equationBoth look similar; one averages over π\pi, the other maximizes over actionsAlways check whether the equation has ∑aπ(a∣s)(⋅)\sum_a \pi(a\mid s)(\cdot) or max⁡a(⋅)\max_a(\cdot)
Forgetting the discount factor in the recursive termEasy to drop γ\gamma when writing V(s′)V(s')Always write r+γV(s′)r + \gamma V(s'), never r+V(s′)r + V(s'), unless γ=1\gamma=1 is explicitly justified (episodic)
Treating the equation as an update rule without realizing it needs the true VπV^\pi on the rightThe equation is a fixed-point condition, not automatically satisfied by an arbitrary guessUse it iteratively (apply TπT^\pi repeatedly) or solve the linear system exactly
Assuming convergence for γ=1\gamma = 1 in a non-terminating (continuing) taskThe contraction argument requires γ<1\gamma < 1 or guaranteed episode terminationVerify episodic termination or use γ<1\gamma < 1
Applying the tabular linear-system solution to large or continuous state spacesO(∣S∣3)O(|S|^3) matrix inversion is infeasible beyond small ∣S∣|S|Use iterative policy evaluation or sampling-based (TD) methods instead

Pioneers & history

Origins · 1 minRichard E. Bellman and how this was discovered
RE
Richard E. Bellman
1920–1984 · RAND Corporation, USA, mid-20th century

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.

History
1953
— Bellman formalizes dynamic programming and the principle of optimality at RAND.
1957
— Bellman publishes Dynamic Programming, establishing the recursive equations for multistage decision processes.
1960
— Ronald Howard formalizes policy iteration for Markov Decision Processes, relying on solving Bellman equations exactly.
1988
— Sutton introduces Temporal-Difference learning, an algorithm that estimates solutions to the Bellman equation from sampled experience rather than a known model.
1989
— Watkins introduces Q-learning, directly targeting the action-value Bellman optimality equation via samples.

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 VπV^\pi satisfies. It does not, by itself, specify a procedure for computing VπV^\pi. 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 γ<1\gamma < 1.

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 TπT^\pi 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, γ=1\gamma=1 is often still fine because the sum defining the return is finite in expectation. In continuing (non-terminating) tasks, however, γ=1\gamma=1 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 π\pi: it averages over the policy's action probabilities and is a linear equation in VπV^\pi. The Bellman optimality equation instead characterizes the value of the best possible policy, replacing the expectation over actions with a maximum over actions: V∗(s)=max⁡a∑s′,rp(s′,r∣s,a)[r+γV∗(s′)]V^*(s) = \max_a \sum_{s',r} p(s',r\mid s,a)[r + \gamma V^*(s')]. 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 p(s′,r∣s,a)p(s',r\mid s,a). 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 VπV^\pi Bellman equation and a QπQ^\pi Bellman equation?

They express the same underlying consistency but are useful in different contexts. Vπ(s)V^\pi(s) is convenient when the policy is known and fixed, since evaluating a state doesn't require also specifying which action was taken. Qπ(s,a)Q^\pi(s,a) is more directly useful for improving a policy, since comparing Qπ(s,a)Q^\pi(s,a) 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 p(s′,r∣s,a)p(s', r \mid s, a), 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 (s′,r)(s', r) pair for each (s,a)(s,a), 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 γ<1\gamma < 1 (or termination is guaranteed).

Before this

Where this leads