Rewards and Returns
Imagine training a robot to walk. Every millisecond it must decide how much torque to apply to each joint. It only finds out much later whether those choices led to a graceful stride or a faceplant. Somehow, all of that delayed, scattered feedback has to be compressed into a single number. That number tells the robot "how well am I doing?" That number, and how it accumulates over time, is the subject of this article. In reinforcement learning, the environment communicates with the agent through a scalar signal called the reward. This single channel is deceptively powerful. Entire fields of behavior — cooperation, tool use, deception, curiosity — have emerged in artificial agents. Their only instruction was to maximize a sum of numbers. Understanding precisely what that sum is, how it is computed, and why it must be finite and well-behaved is a prerequisite for everything that follows. This includes Markov Decision Processes, value functions, and policy-gradient methods. This article builds the bridge between the informal agent-environment loop and the formal objects used throughout reinforcement learning theory. We introduce the reward hypothesis, the working assumption that all goals can be represented as maximizing expected cumulative reward. We then define the return — the quantity an agent actually tries to maximize. We treat the two canonical settings: episodic tasks that terminate and continuing tasks that run forever. We show why discounting is the mathematical device that makes both settings tractable, comparable, and well-defined. By the end, you will be able to write down the return for any interaction sequence. You will be able to explain why an undiscounted infinite return can be undefined. You will see exactly where the discount factor enters the recursive structure. Later chapters exploit this structure to build efficient algorithms like value iteration and Q-learning.
- The reward signal is a scalar emitted by the environment at each time step; the agent's job is to maximize cumulative reward, not immediate reward.
- The reward hypothesis states that all goals can be represented as maximizing the expected value of cumulative received reward.
- The return formalizes "cumulative future reward from time onward" and is the actual optimization target of every RL agent.
- Episodic tasks have a natural end (terminal state) and use a finite, undiscounted or discounted sum; continuing tasks never terminate and require discounting to keep the return finite.
- The discount factor trades off immediate versus future reward and guarantees convergence of infinite sums under bounded rewards.
- The return satisfies a recursive identity, , which is the seed of the Bellman equations used throughout dynamic programming and value-based RL.
An RL agent does not maximize the reward it receives right now — it maximizes the discounted sum of all rewards it expects to receive, forever into the future.
The idea
At each discrete time step , the environment sends the agent a reward , a single real number, immediately after the agent takes action in state and the environment transitions to state . (The subscript convention , rather than , is standard: it emphasizes that the reward is a consequence of the transition out of , jointly determined by the state, the action, and the next state.) The reward is the only evaluative feedback the agent receives — there is no separate channel that says "that was a good idea" versus "that was efficient" versus "that was safe." Every objective the designer cares about must be folded into this one number. This design choice is elevated to a guiding principle called the reward hypothesis: > All of what we mean by goals and purposes can be well thought of as the maximization of the expected value of the cumulative sum of a received scalar signal (reward). The reward hypothesis is not a theorem — it is an empirical and design commitment. It says that instead of hand-crafting complex, multi-objective goal specifications, we can (and should) try to compress everything the designer cares about into a scalar reward function, and let the agent discover the behavior that maximizes its long-run accumulation. This is what makes reinforcement learning a general framework: chess (reward for winning, for losing, otherwise), robotics (reward for forward velocity minus energy cost), and dialogue systems (reward for user satisfaction) are all instances of the same mathematical object. Because the agent cares about the future, not just the present reward, we need a way to aggregate an entire trajectory of rewards into one number the agent can compare across actions. That aggregate is the return, denoted , and it is formally the quantity the agent seeks to maximize in expectation. The rest of this article is devoted to defining correctly in the two settings you will encounter throughout RL: tasks that end, and tasks that don't.
How it works
Episodic tasks: the natural sum
An episodic task has a well-defined endpoint: a special terminal state, after which the interaction resets to a fresh, independent episode. Board games, single trials of a maze, one attempt at parking a car — these are episodic. Let the episode run for steps, ending at time . The undiscounted return at time is simply the sum of all rewards received from up to the end of the episode:
Because is finite (with probability 1, in any reasonable episodic task), this sum is a finite sum of finite numbers, so it is always well-defined — no convergence worries.
Continuing tasks: the problem with infinite sums
A continuing task has no terminal state: a thermostat regulating temperature forever, a stock-trading agent, a server load balancer. Here , and the naive analogue of the sum above,
is an infinite series. If the agent receives, say, a constant reward of at every step forever, this sum diverges to . Two policies that both "succeed forever" would both score , and the agent would have no way to prefer one over the other — the objective becomes useless for comparison and optimization.
Discounting: the fix
The standard resolution is to introduce a discount factor and define the discounted return:
The discount factor determines the present value of future rewards: a reward received steps from now is worth only of what it would be worth if received immediately.
- If , the agent is myopic: it only cares about the very next reward, .
- As , the agent becomes far-sighted, weighting distant rewards almost as heavily as immediate ones.
- For and rewards bounded by some constant , the series is a geometric series and is guaranteed to converge:
This single inequality is why discounting is not merely a "trick to make numbers smaller" — it is the mathematical condition that makes the return a well-defined, finite real number that the agent can meaningfully compare across different action choices, even in a task that never ends.
The recursive structure of the return
The definition above expands the return as an infinite sum, but there is an equivalent, and far more useful, recursive definition. Peel off the first term:
This identity,
says that "the return from now" equals "the immediate reward" plus "the discounted return from one step later." It holds for both episodic tasks (with the convention that at the terminal step, since there is nothing left to accumulate) and continuing tasks (with ). This recursion is the seed from which the Bellman equation — the central recursive relationship satisfied by value functions — is built; every dynamic-programming and value-based algorithm you will encounter later exploits exactly this one-step unrolling.
A unified notation
To treat episodic and continuing tasks with one formula, it is common to allow for episodic tasks (finite sum, no convergence issue) and for continuing tasks, and to write the return uniformly as
where may be . Some formulations unify the two cases further by introducing an absorbing terminal state that transitions to itself forever with reward ; then an episodic task can formally be treated as a continuing task whose tail contributes nothing to the sum, and a single works uniformly.
Algorithmic view: computing returns from a trajectory
Although the return is a definition, not an algorithm, computing it from a recorded trajectory (as is done constantly in Monte Carlo methods, described in later articles) is a simple backward pass that directly exploits the recursion above. ```
# Compute the return G_t for every time step t = 0, ..., T-1
# given a finite reward sequence R[1..T] and discount factor gamma. function COMPUTE_RETURNS(R[1..T], gamma): G = array of length T+1 G[T] = 0 # terminal boundary condition for t = T-1 downto 0: G[t] = R[t+1] + gamma * G[t+1] return G[0..T-1] ``` This runs in a single backward pass over the trajectory. It is correct precisely because it implements the recursion derived above, with the base case encoding "no more rewards after the episode ends." For continuing tasks, one cannot literally sum to ; in practice the return is either (a) estimated by truncating the sum after enough terms that the discarded tail is provably negligible, or (b) replaced by bootstrapped estimates from a learned value function, a topic developed once value functions are introduced.
Complexity & correctness
Space and time to compute returns from a trajectory. Given a recorded finite trajectory of length , the backward-pass algorithm above visits each reward exactly once, doing work per step (one multiply, one add), so it runs in time and, if all returns are retained, space (or extra space if only the current is needed on the fly, streaming backward). This is optimal: any correct algorithm must read every one of the rewards at least once, so time is a lower bound, matching the upper bound.
Why the backward recursion is correct. This follows from a simple inductive argument on the recursion , with base case . Base case: at the terminal step , there are no more rewards to accumulate, so by definition — this matches the convention used to unify episodic and continuing notation. Inductive step: suppose has been correctly computed as . Then
which is exactly the closed-form definition of . By induction, the recursion computes the correct return at every , and computing it backward from down to correctly uses only already-finalized values.
Why discounting guarantees finiteness (the convergence argument). For a continuing task with for all (a mild boundedness assumption satisfied by essentially every practical reward function), the discounted return's absolute value is bounded by a geometric series:
The equality holds whenever , by the standard geometric series formula; the partial sums converge to as because . This is precisely why the constraint (not ) is required for continuing tasks: it is the exact condition under which the infinite return is guaranteed to be a finite, well-defined real number regardless of how the reward sequence unfolds.
Tradeoffs in choosing . There is no universally "correct" discount factor — it encodes a modeling choice, not a derived quantity:
- Small (e.g., ) makes the return depend mostly on near-term rewards. Estimation of returns from sampled data has lower variance (fewer terms contribute meaningfully), and value functions are easier to learn, but the resulting policy may be myopic and ignore consequences far in the future.
- Large (e.g., ) makes the agent plan over long horizons — important for tasks with long-delayed consequences — but the effective horizon grows, increasing the variance of return estimates and often slowing convergence of learning algorithms.
- is sometimes used for episodic tasks with a guaranteed, finite horizon, where the convergence issue never arises; using on a continuing task is unsafe unless one switches to a different objective (such as the average reward per step) precisely because the sum can diverge.
Worked example
Consider a small episodic task: a robot navigating a corridor toward a goal, receiving reward per step until it reaches the goal, at which point the episode ends. Suppose one episode produces the reward sequence
so . Let's compute the return at every time step with two different discount factors, (undiscounted) and , using the backward recursion , .
Undiscounted ():
| computation | ||
|---|---|---|
| 5 | base case | |
| 4 | ||
| 3 | ||
| 2 | ||
| 1 | ||
| 0 |
Sanity check by direct summation: . Matches.
Discounted ():
| computation | ||
|---|---|---|
| 5 | base case | |
| 4 | ||
| 3 | ||
| 2 | ||
| 1 | ||
| 0 |
Direct-sum check: . Matches, confirming both the recursion and the closed-form expansion agree. Notice the qualitative lesson: with , the goal reward is worth exactly no matter how far away it is; with , the same reward, four steps away from , is discounted down to of its face value by the time it is "seen" from . This is exactly why an agent with smaller will prefer a shorter path to the goal even if a longer path eventually yields the same terminal reward — the discounting itself creates an implicit preference for speed, on top of whatever the raw reward function specifies. Now contrast with a continuing task: a server that gets reward every single step forever if it stays online. With , for every and every policy that keeps the server alive — utterly useless for comparing an occasionally-crashing policy against a perfectly reliable one, since both could plausibly diverge. With , a policy that is online every step earns , while a policy that crashes and receives reward on 10% of steps earns strictly less than — a finite, comparable number that correctly ranks policies by long-run reliability.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Using on a continuing (non-terminating) task | The return sum has infinitely many nonzero terms; it can diverge, making all policies "equally infinite" | Use , or switch to the average-reward formulation designed for continuing tasks |
| Off-by-one indexing: writing | Confusing "reward received at " with "reward received as a result of the action taken at " | Remember is the reward for the transition out of ; starts at , never |
| Forgetting the terminal boundary condition | Treating episodic and continuing recursions identically without handling episode end | Explicitly set (or use an absorbing zero-reward terminal state) before running the backward recursion |
| Choosing too close to for a long-horizon task and expecting fast learning | Effective horizon grows very large, increasing variance of Monte Carlo return estimates | Start with a moderate (e.g., 0.95–0.99) and increase gradually, or use bootstrapped value estimates to reduce variance |
| Conflating "reward" with "return" in casual explanation | Both are scalars describing "goodness," easy to blur informally | Reward is a per-step signal from the environment; return is the cumulative, agent-side quantity being optimized |
| Assuming reward shaping can encode any goal without changing agent behavior | Adding auxiliary rewards to speed up learning can inadvertently shift the argmax policy | Design shaping terms (e.g., potential-based shaping) that provably preserve the optimal policy under the true objective |
Pioneers & history
The formalization of reward and return as the objective of adaptive behavior draws on ideas from optimal control, animal learning theory, and stochastic approximation, synthesized into the modern RL formalism largely through the work of Richard Sutton and Andrew Barto, who crystallized the reward hypothesis and the discounted-return formalism into the standard textbook framework used throughout the field.
Origins · 1 minRichard S. Sutton and how this was discovered
Where this matters
The discounted return is not an abstract nicety — it is the literal training objective baked into essentially every reinforcement learning system deployed in practice. Deep Q-Networks and their successors, used in game-playing agents from Atari to StarCraft II, learn to estimate (via value functions built on the recursion above) directly from pixels. Policy-gradient methods such as REINFORCE, PPO, and actor-critic algorithms explicitly weight the gradient of the policy by sampled or estimated returns. In robotics, the choice of directly determines whether a learned controller optimizes for quick, jerky task completion or smoother, longer-horizon stability. In recommendation systems and RLHF-tuned large language models, the "reward model" that scores an output, combined with a discount factor over a multi-turn conversation, defines the entire optimization target that shapes deployed model behavior. Financial trading agents, HVAC control systems, and data-center cooling optimizers are all, at bottom, engines for maximizing a discounted return under an environment with genuinely never-ending dynamics — the continuing-task setting this article makes precise. Every one of these systems inherits its correctness (and its failure modes, like reward hacking) directly from how carefully the reward and return were specified, which is why this foundational definition anchors the rest of the field, including Markov Decision Processes and Policies and Value Functions.
Ask the tutor: How does the discounted return connect to the Bellman equation and value functions in a full Markov Decision Process?
Why is the reward defined as rather than ?
The indexing reflects causality: the reward is the consequence of the transition that occurs after the agent takes action in state . The environment must first process the action and move to a new state before it can determine what reward that transition deserves. Writing the reward as keeps the timeline consistent: at time the agent observes , chooses , and only then, as part of the step into , receives alongside . This convention, while occasionally reversed in older or non-standard texts, is the one used throughout Sutton-Barto-style formalism and avoids ambiguity about whether a reward "belongs" to the state it was received in or the state that caused it.
Can the discount factor change over time or across states?
In the basic formalism, is a fixed constant applied uniformly at every step, chosen once as part of the problem specification. More advanced formulations allow state-dependent or time-varying discounting, useful for example when an episode may terminate stochastically (in which case a state-dependent "continuation probability" plays a role mathematically identical to ) or when different parts of a task have different natural time scales. These generalizations preserve the core convergence argument as long as the effective discounting stays uniformly bounded below 1, which keeps the infinite sum finite by the same geometric-series bound derived for constant .
What happens if rewards are unbounded — does the return still converge with ?
Not necessarily. The convergence guarantee explicitly assumes rewards are bounded by some finite constant . If rewards can grow without bound over time — for instance, growing linearly or exponentially with — a discount factor less than 1 may or may not be enough to force convergence, depending on how fast the rewards grow relative to how fast shrinks. In virtually all practical RL benchmarks and applications, rewards are clipped or naturally bounded (e.g., , or bounded physical quantities), which is precisely what makes the standard discounting argument apply cleanly.
Is the return the same thing as the value function?
No, and this distinction matters a great deal. The return is a random variable defined along a single realized trajectory — it depends on which actions were actually taken and which states and rewards actually occurred, including any stochasticity in the environment. The value function, introduced in later articles, is the expected return, taken over all the randomness in the policy and environment dynamics, starting from a given state (or state-action pair). Value functions are what algorithms typically try to estimate or represent explicitly, precisely because they average over the noise present in any single sampled return.
Why not just maximize the immediate reward at every step, and skip returns entirely?
Maximizing immediate reward greedily is myopic and often catastrophic: an agent might grab a small reward now that forecloses a much larger reward later, or walk into a trap that looks locally appealing. A chess-playing agent that greedily maximized "reward this move" would sacrifice its queen for a pawn if the pawn capture happened to be the only reward-bearing move available immediately. The return exists precisely so that the agent's objective accounts for the entire future consequence of a decision, not just its instantaneous payoff — this is what allows RL agents to learn delayed-gratification behaviors like sacrificing material for positional advantage, or investing early effort for a much larger payoff later.
How does discounting relate to interest rates or economic "time preference"?
The analogy is close and useful: plays exactly the role that a discount rate plays in finance, where a dollar received next year is worth less than a dollar today because of inflation, risk, and opportunity cost. Just as discounts a future cash flow at interest rate , discounts a future reward. Setting makes the two formalisms numerically identical. This is not a coincidence — both formalisms exist to solve the same underlying problem: comparing payoffs that arrive at different points in time using a single, consistent numeraire.
Does a higher discount factor always lead to "better" behavior?
Not automatically — it depends on what "better" means for the task and on practical learning constraints. A higher lets the agent value long-term consequences more accurately, which is essential when good behavior only pays off after a long delay (e.g., saving for retirement, or planning several moves ahead in chess). However, higher also increases the effective planning horizon , which typically increases the variance of sampled returns and can slow down or destabilize learning algorithms that estimate the return from limited experience. In practice, is tuned as a hyperparameter balancing horizon length against learnability.