Temporal-Difference Learning: TD(0)

Imagine an agent driving home from work, trying to predict how long the whole trip will take. Ten minutes in, it hits unexpected traffic and immediately revises its estimate. It does not wait until arriving home to learn something useful. This simple instinct — updating a prediction using a later prediction rather than waiting for the final outcome — is the essence of temporal-difference (TD) learning. TD(0) is its purest form. TD(0) matters because most real-world sequential decision problems are far too long for an agent to wait. Some never actually terminate, so it cannot wait until an episode ends before learning. Monte Carlo Prediction must wait for a full return before updating a value estimate. TD(0) updates after every single transition. This one change — bootstrapping off your own current estimate instead of the true final return — is what makes reinforcement learning practical at scale. It powers everything from game-playing agents to recommendation systems that must learn continuously from streaming interaction data. The big picture is this: TD(0) sits at the intersection of dynamic programming and Monte Carlo methods. Like dynamic programming, it bootstraps — it uses an existing estimate to update another estimate. Like Monte Carlo, it learns directly from raw experience. It needs no model of the environment's transition probabilities or reward function. This hybrid nature is why Sutton called TD learning "the central and novel idea in reinforcement learning." This article gives a precise, self-contained treatment of TD(0) prediction. It covers the update rule, the TD error, and a careful pseudocode implementation. It also includes a full complexity and convergence analysis, a worked numerical trace, and the historical context that led to its discovery. It sets up the ideas that generalize to control algorithms and multi-step methods later.

Key takeaways
  • TD(0) estimates the state-value function vπv_\pi from experience, updating after every single transition rather than at the end of an episode.
  • The core mechanism is the TD target Rt+1+γV(St+1)R_{t+1} + \gamma V(S_{t+1}), compared against the current estimate V(St)V(S_t) via the TD error δt\delta_t.
  • TD(0) combines Monte Carlo's model-free sampling with dynamic programming's bootstrapping, giving it lower variance than Monte Carlo but some bias.
  • It converges to vπv_\pi under standard stochastic approximation conditions on the step size, for a fixed policy π\pi.
  • Update cost is O(1)O(1) per transition and O(∣S∣)O(|\mathcal{S}|) space for a tabular value function, making it usable in continuing (non-episodic) tasks.
  • TD(0) is the foundation for SARSA, Q-learning, and n-step / TD(λ\lambda) methods used throughout modern reinforcement learning.
The core insight

TD(0) updates a value estimate toward a target built from one real reward plus its own current guess of the future, learning online without waiting for episodes to end.

The idea

Temporal-difference learning is a method for estimating a value function from experience generated by interacting with an environment, without requiring a model of that environment. Recall that the state-value function under a fixed policy π\pi is defined as the expected discounted return from a state:

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

Monte Carlo Prediction estimates vπ(s)v_\pi(s) by averaging complete sampled returns GtG_t following visits to ss. This requires waiting until an episode terminates before any return is known, and the resulting estimates have high variance because a single return depends on every reward and every random transition for the rest of the episode. TD(0) makes one conceptual substitution: instead of using the full return GtG_t, it uses a one-step lookahead estimate called the TD target:

GtTD=Rt+1+γV(St+1)G_t^{\text{TD}} = R_{t+1} + \gamma V(S_{t+1})

Here VV is the current estimate of the value function — the same object being updated. The agent replaces "the true remaining return from St+1S_{t+1} onward" with "my current best guess of it," namely V(St+1)V(S_{t+1}). This is called bootstrapping: building an estimate partly from another estimate, a hallmark shared with dynamic programming, foreshadowed further in Bootstrapping in TD Learning. The discrepancy between the TD target and the current value estimate is the TD error:

δt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

TD(0) nudges V(St)V(S_t) toward the TD target by a step-size α∈(0,1]\alpha \in (0, 1]:

V(St)←V(St)+α δtV(S_t) \leftarrow V(S_t) + \alpha\, \delta_t

This single line is the entire learning rule. It can be applied after every transition — the agent observes St,Rt+1,St+1S_t, R_{t+1}, S_{t+1}, computes δt\delta_t, and immediately updates V(St)V(S_t). No episode needs to finish; TD(0) works identically in continuing tasks with no terminal state, and it works in episodic tasks by simply treating a terminal state's value as fixed at zero.

How it works

TD(0) is used for prediction: given a fixed policy π\pi, estimate vπv_\pi. The agent does not choose actions to optimize reward here — it simply follows π\pi and learns to evaluate it. (Choosing actions to improve the policy is control, covered in SARSA: On-Policy TD Control.) The algorithm maintains a table V(s)V(s) for every state, typically initialized arbitrarily (often to zero), with any terminal state fixed at V(terminal)=0V(\text{terminal}) = 0. Each episode (or, in a continuing task, each fixed-length chunk of interaction) proceeds by taking an action dictated by π\pi, observing the reward and next state, and updating immediately. ``` Algorithm: TD(0) Prediction for estimating v_π Input: policy π to be evaluated, step-size α ∈ (0, 1], discount γ ∈ [0, 1] Initialize: V(s) ← arbitrary, for all non-terminal s V(terminal) ← 0 Repeat (for each episode): S ← initial state of episode Repeat (for each step of episode), until S is terminal: A ← action given by π for S Take action A; observe reward R and next state S' δ ← R + γ V(S') - V(S) # TD error V(S) ← V(S) + α δ # TD(0) update S ← S' ``` Two implementation subtleties matter for correctness. First, V(S′)V(S') must be the value stored before any update happens in that step — the update uses the pre-update estimate as its bootstrap target. Second, terminal states must always evaluate to exactly 00, since by definition no reward accrues after termination; forgetting this is a common source of silent bugs (see pitfalls below). The diagram below shows the information flow of a single TD(0) update: one real transition supplies the reward Rt+1R_{t+1}, and the stored value of the next state supplies the rest of the target, in contrast to Monte Carlo, which would need the entire rest of the trajectory.

Figure
One TD(0) backup: a single real step plus a bootstrapped estimate
Sₜ Sₜ₊₁ rest of episode real reward Rₜ₊₁ (actual environment step) used by Monte Carlo, skipped by TD(0) estimate V(Sₜ₊₁) TD target = Rₜ₊₁ + γ·V(Sₜ₊₁) δₜ = target − V(Sₜ)

Complexity & correctness

Time complexity. Each TD(0) update touches exactly one table entry, computes one reward, one lookup of V(S′)V(S'), and one arithmetic combination: O(1)O(1) per transition. An episode of length TT costs O(T)O(T) total, and TT never needs to be finite — the algorithm applies unchanged to continuing tasks. This is the key practical advantage over Monte Carlo, whose per-episode update also costs O(T)O(T) but which cannot produce any update until the episode ends; TD(0) produces TT incremental updates spread across the episode's duration, enabling learning in real time and in tasks without a natural end.

Space complexity. A tabular implementation stores V(s)V(s) for each state: O(∣S∣)O(|\mathcal{S}|) space. No model of transition probabilities or rewards is stored, distinguishing TD(0) from dynamic-programming methods that require the full O(∣S∣2∣A∣)O(|\mathcal{S}|^2 |\mathcal{A}|) transition model.

Correctness — bias/variance tradeoff. The Monte Carlo target GtG_t is an unbiased estimate of vπ(St)v_\pi(S_t) by definition of vπv_\pi as an expectation, but it has high variance because it is a function of many random rewards and transitions across an entire trajectory. The TD target Rt+1+γV(St+1)R_{t+1} + \gamma V(S_{t+1}) has much lower variance — it depends on only one random reward and one random next state — but it is biased whenever V≠vπV \neq v_\pi, since it bootstraps from a possibly-wrong estimate. As VV converges toward vπv_\pi during learning, this bias vanishes. This is the fundamental tradeoff TD(0) makes: it accepts transient bias in exchange for a large variance reduction, which in practice usually yields faster and more stable learning.

Convergence proof sketch (tabular case). Fix a policy π\pi generating an ergodic Markov chain over states. Consider TD(0)'s expected update at state ss:

E[δt∣St=s]=Eπ[Rt+1+γV(St+1)∣St=s]−V(s)=(TπV)(s)−V(s)\mathbb{E}[\delta_t \mid S_t = s] = \mathbb{E}_\pi[R_{t+1} + \gamma V(S_{t+1}) \mid S_t = s] - V(s) = (T^\pi V)(s) - V(s)

where TπT^\pi is the Bellman expectation operator for π\pi:

(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]

The operator TπT^\pi is a γ\gamma-contraction in the max norm (for γ<1\gamma < 1): ∥TπV1−TπV2∥∞≤γ∥V1−V2∥∞\|T^\pi V_1 - T^\pi V_2\|_\infty \le \gamma \|V_1 - V_2\|_\infty, and its unique fixed point is exactly vπv_\pi, i.e. Tπvπ=vπT^\pi v_\pi = v_\pi (the Bellman equation). TD(0)'s expected update thus pushes VV toward this fixed point in expectation, sampling a stochastic approximation of the operator TπT^\pi rather than computing it exactly (which would require the full model, as in policy evaluation via Value functions). Formally, TD(0) is an instance of stochastic approximation for finding the root of TπV−V=0T^\pi V - V = 0. Under the classical Robbins–Monro step-size conditions —

∑tαt(s)=∞,∑tαt(s)2<∞\sum_{t} \alpha_t(s) = \infty, \qquad \sum_t \alpha_t(s)^2 < \infty

for every state ss (each state visited infinitely often) — standard stochastic approximation theory guarantees V(s)→vπ(s)V(s) \to v_\pi(s) with probability 1. Intuitively: the sum-to-infinity condition ensures the step size never shrinks so fast that learning stalls before reaching the fixed point, while the square-summable condition ensures the noise from single-sample updates eventually averages out rather than causing permanent oscillation. In practice a small constant α\alpha is often used instead, which does not satisfy these conditions exactly and yields convergence to a neighborhood of vπv_\pi rather than exact convergence — a standard, deliberate tradeoff favoring adaptability in nonstationary settings.

Honest tradeoffs. TD(0) requires γ<1\gamma < 1 or a properly terminating task for the contraction argument to apply cleanly; with function approximation instead of a table, this convergence guarantee weakens substantially (bootstrapping combined with off-policy sampling and function approximation can even diverge — the so-called "deadly triad," a topic beyond this article). TD(0) also introduces a hyperparameter, α\alpha, whose tuning affects both speed and final estimation error, whereas tabular Monte Carlo's only real hyperparameter is how counts are used to average returns.

Worked example

Consider Sutton and Barto's classic random-walk chain: five non-terminal states A,B,C,D,EA, B, C, D, E arranged in a line, with terminal states on both ends. From any state, the agent moves left or right with probability 12\tfrac12 each. Reaching the right terminal yields reward +1+1; reaching the left terminal yields reward 00; all other rewards are 00. Under this fully random policy, the true values are known analytically: vπ(A,B,C,D,E)=(1/6,2/6,3/6,4/6,5/6)v_\pi(A,B,C,D,E) = (1/6, 2/6, 3/6, 4/6, 5/6). Initialize all V(s)=0.5V(s) = 0.5 for s∈{A,B,C,D,E}s \in \{A,B,C,D,E\}, with α=0.1\alpha = 0.1, γ=1\gamma = 1. Suppose one episode produces the trajectory:

C→D→E→(terminal, right, reward +1)C \to D \to E \to \text{(terminal, right, reward } +1)

Trace the TD(0) updates step by step (all values start at 0.50.5):

stepStS_tRt+1R_{t+1}St+1S_{t+1}V(St+1)V(S_{t+1}) before updateδt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1}+\gamma V(S_{t+1})-V(S_t)new V(St)V(S_t)
1C0D0.50+0.5−0.5=0.00 + 0.5 - 0.5 = 0.00.5+0.1(0.0)=0.5000.5 + 0.1(0.0) = 0.500
2D0E0.50+0.5−0.5=0.00 + 0.5 - 0.5 = 0.00.5+0.1(0.0)=0.5000.5 + 0.1(0.0) = 0.500
3E1terminal0.01+0−0.5=0.51 + 0 - 0.5 = 0.50.5+0.1(0.5)=0.5500.5 + 0.1(0.5) = 0.550

After this single episode, only V(E)V(E) changed, moving from 0.50.5 to 0.550.55 — a step toward its true value of 5/6≈0.8335/6 \approx 0.833. Notice V(C)V(C) and V(D)V(D) did not change on this episode even though they lay on the path to the reward, because their bootstrap targets exactly matched their current values (both neighbors were still at 0.50.5). This is a genuinely instructive contrast with Monte Carlo: a Monte Carlo update on this same episode would immediately push V(C)V(C) and V(D)V(D) toward the observed return of 11 as well, since Monte Carlo uses the actual final outcome for every visited state in the episode. TD(0) instead only "notices" the surprise (δt≠0\delta_t \ne 0) exactly at the boundary where the current value table disagrees with reality — namely at EE, adjacent to the terminal reward. Over many more episodes, this asymmetry corrects itself: as V(E)V(E) rises above 0.50.5, the next time D→ED \to E occurs, δt\delta_t at DD becomes nonzero too, and the correction propagates backward one state per episode, like a wave. This staged, local propagation of information — updating only where a genuine discrepancy in one-step prediction was observed — is precisely what makes TD(0) computationally cheap and is also why it can take many episodes for information to travel far from a reward source, a limitation partially addressed by multi-step methods in n-Step Bootstrapping Methods.

Common pitfalls & traps

PitfallWhy it happensConsequence
Using post-update V(S′)V(S') in the targetUpdating V(S)V(S) and then reading V(S′)V(S') from a table already touched this step, in an implementation that processes states out of orderIntroduces subtle order-dependent bias; correctness relies on using the pre-update estimate
Forgetting V(terminal)=0V(\text{terminal}) = 0Terminal states are sometimes left at their initialized value or never explicitly createdSilently inflates or deflates every TD target near episode ends, corrupting learning everywhere
Step size α\alpha too largeTreating α\alpha as a free tuning knob without careEstimates oscillate or diverge instead of converging, especially with stochastic rewards
Step size α\alpha constant but expecting exact convergenceRobbins–Monro conditions require αt→0\alpha_t \to 0 appropriatelyValue estimates converge only to a noisy neighborhood of vπv_\pi, not to it exactly
Confusing prediction with controlApplying TD(0)'s state-value update while trying to improve the policyTD(0) as described only evaluates a fixed policy; policy improvement needs action values, e.g. SARSA
Insufficient state visitationSome rare states are almost never reached under π\piTheir value estimates barely update and remain near initialization for a long time

Pioneers & history

TD(0) prediction is inseparable from the broader story of temporal-difference learning, developed principally by Richard Sutton in the early 1980s while exploring how animals and machines might learn predictions incrementally from experience, inspired partly by psychological theories of classical conditioning.

Origins · 1 minRichard S. Sutton and how this was discovered
RS
Richard S. Sutton
born 1957 · University of Alberta / DeepMind

Sutton formalized temporal-difference learning as a distinct family of algorithms, introducing the TD error as the central learning signal and later co-authoring, with Andrew Barto, the standard reference text that established reinforcement learning as a coherent field. His work connected trial-and-error learning, dynamic programming, and Monte Carlo estimation into one unified framework, and TD(0) is the simplest member of that family.

History
1959
— Arthur Samuel's checkers program uses an early bootstrapping idea, adjusting evaluations based on later evaluations, prefiguring TD learning.
1972
— Ian Witten proposes an early version of a TD-like prediction rule for adaptive controllers.
1988
— Sutton formally introduces TD(λ\lambda) and TD(0) as instances, proving convergence results and coining "temporal-difference learning."
1992
— Gerald Tesauro's TD-Gammon uses TD learning with neural network function approximation to reach expert-level backgammon play.
1998
— Sutton and Barto publish Reinforcement Learning: An Introduction, cementing TD methods as core reinforcement learning machinery.

Where this matters

TD(0) prediction underlies value estimation in nearly every modern reinforcement learning system, even when the surface algorithm looks quite different. Deep Q-Networks estimate action-values using a TD-style target built from a bootstrapped next-state estimate, extending the same δt\delta_t signal to neural function approximators. Actor-critic architectures, used across robotics and simulated control, train their critic network with a TD(0)-like loss, often literally (δt)2(\delta_t)^2, to provide a low-variance baseline for policy gradient updates. TD-Gammon demonstrated decades ago that a TD-trained value function alone could reach expert-level performance in backgammon, foreshadowing the value networks later used in AlphaGo and its successors. Beyond games, TD-style bootstrapping appears in recommendation systems that continuously update estimates of long-term user engagement from streaming click data, in industrial process control where feedback must be incorporated online rather than after an artificial "episode" ends, and in financial and operations models that treat ongoing decision processes as continuing tasks with no terminal state. Any system that must learn a long-horizon prediction from an unbounded or very long stream of experience, without waiting for a final outcome, is a natural candidate for TD-style prediction — which is precisely why it remains foundational to control methods such as SARSA: On-Policy TD Control and multi-step generalizations in n-Step Bootstrapping Methods.

Ask the tutor: How does TD(0)'s bias-variance tradeoff change as you move to n-step TD or TD(λ) methods?

Is TD(0) an on-policy or off-policy method?

TD(0) as presented here is a prediction method, not a control method, so the on-policy/off-policy distinction applies once you specify how actions are chosen and how the target is constructed. In the pure prediction setting, the agent follows a single fixed policy π\pi to generate the transitions used for learning, and it estimates vπv_\pi, the value function for that same policy — this makes it on-policy prediction. Off-policy variants exist, such as TD(0) with importance sampling, where transitions are generated by a different behavior policy while still estimating the value of a target policy, but that extension is not part of the basic TD(0) rule.

How does TD(0) differ from full dynamic programming policy evaluation?

Dynamic programming policy evaluation also bootstraps, updating V(s)V(s) using the Bellman expectation equation, but it requires a complete model: the transition probabilities p(s′,r∣s,a)p(s', r \mid s, a) and reward function must be known, and the update sums over all possible next states weighted by their true probabilities. TD(0) replaces that full expectation with a single sampled transition drawn from actual experience, requiring no model at all. This is why TD(0) is classified as model-free, while dynamic programming is model-based, even though both rely on the same underlying Bellman fixed-point structure.

Why is TD(0) called a bootstrapping method?

Bootstrapping in this context means updating an estimate using another estimate of the same kind, rather than using only ground-truth outcomes. TD(0)'s target Rt+1+γV(St+1)R_{t+1} + \gamma V(S_{t+1}) contains V(St+1)V(S_{t+1}), which is itself just the algorithm's current guess, not a verified true value. Dynamic programming methods bootstrap in the same sense, since Bellman-equation updates use VV of successor states. Monte Carlo methods do not bootstrap, since a full return GtG_t is composed only of actual observed rewards, never another value estimate.

Can TD(0) be used in tasks that never terminate?

Yes, and this is one of its major practical advantages over Monte Carlo. Because the TD(0) update only needs one transition (St,Rt+1,St+1)(S_t, R_{t+1}, S_{t+1}) at a time, it applies unchanged to continuing tasks with no terminal state, as long as γ<1\gamma < 1 keeps returns finite in expectation. Monte Carlo methods, by contrast, require a complete return computed from an entire episode, so they cannot directly handle tasks lacking a natural endpoint without additional machinery such as truncation.

What happens to TD(0) convergence guarantees when using a neural network instead of a table?

The clean stochastic-approximation convergence argument relies on each state having its own independently updated table entry, so updating V(s)V(s) never changes V(s′)V(s') for s′≠ss' \ne s. With function approximation, a single gradient step can change the values of many states simultaneously, including states not visited on that step, because parameters are shared. This breaks the simple contraction argument, and combined with bootstrapping and off-policy data, can in principle cause divergence — a phenomenon known as the deadly triad. In practice, techniques like target networks and careful step sizes are used to stabilize learning, but the tabular convergence proof does not transfer directly.

How does the TD error δₜ relate to reward prediction error in neuroscience?

Researchers studying dopamine neuron firing found that its patterns closely resemble the TD error signal from reinforcement learning models, firing more when an outcome is better than predicted and less when it is worse, matching the sign and rough magnitude of δt\delta_t. This correspondence, discovered in the late 1990s, gave TD learning substantial credibility as a plausible model of biological reward learning, beyond its role as an engineering algorithm, and remains a widely cited connection between reinforcement learning theory and computational neuroscience.

Does a larger step size α always make TD(0) learn faster?

Not reliably. A larger α\alpha does make each individual update larger, which can speed early learning, but it also makes the value estimates more sensitive to the randomness in any single transition's reward and next state. This increases variance in the running estimate and can cause oscillation or failure to settle near vπv_\pi, especially in stochastic environments. Practical use typically anneals α\alpha downward over time, satisfying something close to the Robbins–Monro conditions, or uses a small constant α\alpha chosen to balance adaptability against stability.

Before this

Where this leads