Skip to content
beginner

Deriving Discounted Return: How Future Rewards Become an Objective

You already know the feeling: a reward now beats the same reward later. This article turns that feeling into a formula you can defend, compute, and…

Published 2026-10-02Updated 2026-10-0412 min read
Adults playing chess outdoors in Ado Ekiti, Nigeria, showcasing strategy and leisure.
Adults playing chess outdoors in Ado Ekiti, Nigeria, showcasing strategy and leisure. Photo by Kold Shots on Pexels.

You already know the feeling: a reward now beats the same reward later. This article turns that feeling into a formula you can defend, compute, and eventually optimize.

From a Reward Sequence to a Single Number

Here is the setup. An agent acts, the environment responds, and a reward arrives. Then it happens again. And again. What you get is a sequence:

r0,r1,r2,r3,…r_0, r_1, r_2, r_3, \dots

Each rtr_t is the reward received at time step tt. That sequence is the raw material. But a sequence is not an objective. You cannot rank two policies by comparing two lists of numbers of different lengths, with different timings, and different totals. To choose between policies, you need one number per trajectory — a scalar you can compare, average, and maximize.

That number is the return, written GtG_t. The return is the cumulative reward the agent collects starting from time step tt. If you have read the intuition-level treatment of rewards and discounting, you already know the shape of this idea. What we are doing here is different: we are going to build the formula term by term, so that every power of γ\gamma appears for a reason instead of arriving as a memorized pattern.

Before we write anything down, let me fix the notation, because sloppy notation is where most of the confusion starts:

  • tt — the time index. A counter that ticks forward one step at a time.
  • rtr_t — the reward received at step tt.
  • γ\gamma — the discount factor, a constant in the interval [0,1)[0, 1). It is fixed for the whole task, not something the agent learns.
  • GtG_t — the return from step tt onward.

That last symbol is the one we are deriving. Everything else is scaffolding.

Why Undiscounted Sums Break Down

The naive objective is the plain sum: add up every reward the agent ever receives. It sounds right. It fails for two separate reasons, and it is worth keeping them apart.

The first reason is convergence. In a continuing task — one that never ends — the sum runs forever. If the agent keeps collecting any positive reward, the total keeps growing without bound. There is no finite number to maximize. You cannot optimize a quantity that never settles.

The second reason is preference. Even when the sum is finite, a plain sum treats a reward a thousand steps away as exactly as valuable as a reward right now. For most tasks, that is the wrong priority. If you are steering a car, a crash in ten seconds matters more than a crash in ten minutes, and not only because the episode might end first.

Discounting fixes both problems with one mechanism. Each reward is multiplied by a weight that shrinks as the reward moves further into the future. The weight on a reward tt steps away is γt\gamma^t. Because γ\gamma is less than one, those weights get smaller and smaller, which both keeps the infinite sum finite and encodes the preference for earlier reward.

Note: Discounting is a modeling choice, not a law of nature. You are deciding how much the future should count. That decision has consequences, and we will come back to them.

Deriving the Discounted Return Step by Step

A horizontal timeline marks offsets 0, 1, 2, and 3 with rewards r_t through r_{t+3}. Beneath them, weights 1, gamma, gamma squared, and gamma cubed shrink from left to right when gamma is below one.
The exponent counts steps into the future: later rewards receive progressively smaller weights when gamma is below one.

Let us build the formula from the first term outward.

Start at time step tt. The reward you receive right now is rtr_t. How much weight should it carry? None of it is in the future, so it is not discounted at all. Its weight is γ0=1\gamma^0 = 1.

Gt=rt+…G_t = r_t + \dots

One step later, the reward is rt+1r_{t+1}. It is one step into the future, so it gets one factor of γ\gamma.

Gt=rt+γrt+1+…G_t = r_t + \gamma r_{t+1} + \dots

Two steps later, the reward is rt+2r_{t+2}, two steps into the future, so it gets two factors of γ\gamma.

Gt=rt+γrt+1+γ2rt+2+…G_t = r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \dots

The pattern is now visible. A reward received kk steps after tt carries weight γk\gamma^k. Writing the full sum:

Gt=rt+γrt+1+γ2rt+2+γ3rt+3+⋯=∑k=0∞γkrt+kG_t = r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \gamma^3 r_{t+3} + \dots = \sum_{k=0}^{\infty} \gamma^k r_{t+k}

Read that sum slowly. The index kk is the time offset from the present, not the absolute time. The exponent on γ\gamma is always the offset. That is the whole trick: the further a reward sits from now, the more times you multiply it by a number smaller than one.

The Recursive Form

There is a second way to write the same thing, and it matters more than it looks. Pull the first term out of the sum:

Gt=rt+γ(rt+1+γrt+2+γ2rt+3+… )G_t = r_t + \gamma \left( r_{t+1} + \gamma r_{t+2} + \gamma^2 r_{t+3} + \dots \right)

The part in parentheses is exactly Gt+1G_{t+1} — the return starting one step later. So:

Gt=rt+γGt+1G_t = r_t + \gamma G_{t+1}

This is the recursive form of the return. The return from here equals the reward I get now, plus the discounted return from wherever I land next. That self-reference is not a curiosity. It is the seed of every Bellman-style equation you will meet later, because it lets you express the value of a state in terms of the values of the states that follow it.

Knowledge check

Check your understanding

Answer this question before you continue.

Which recursive equation is equivalent to the discounted-return sum starting at time t?
Single Choice

Focus: Translate the discounted-return sum into its equivalent one-step recursive form.

Why the Infinite Sum Converges

The sum ∑k=0∞γkrt+k\sum_{k=0}^{\infty} \gamma^k r_{t+k} is only useful if it lands on a finite number. Two conditions get us there.

First, rewards must be bounded. There is some maximum absolute reward Rmax⁡R_{\max} that the environment can hand out. This is true in essentially every practical task — rewards are numbers produced by a reward function, and reward functions do not return infinity.

Second, γ<1\gamma < 1. With both conditions, the sum is squeezed by a geometric series:

∣Gt∣≤∑k=0∞γkRmax⁡=Rmax⁡1−γ|G_t| \le \sum_{k=0}^{\infty} \gamma^k R_{\max} = \frac{R_{\max}}{1 - \gamma}

That right-hand side is finite whenever γ<1\gamma < 1. The return cannot run away, no matter how long the task continues.

Warning: If γ=1\gamma = 1 in a continuing task, the bound becomes Rmax⁡/0R_{\max} / 0 — meaningless. There is no convergence guarantee, and the objective may not exist. Setting γ=1\gamma = 1 is only safe when the task provably ends.

Knowledge check

Check your understanding

Answer this question before you continue.

Starting at time step t, what weight does the discounted-return formula assign to reward r_(t+3)?
Question 1 of 2Single Choice

Focus: Determine the discount exponent for a reward from a specified number of steps in the future.

For a continuing task, which conditions support the article's finite bound on the discounted return?
Question 2 of 2Misconception Check

Focus: Identify the conditions the article uses to bound an infinite discounted return.

From One Trajectory to the Objective a Policy Maximizes

So far we have a number for a single trajectory. But the agent does not get to pick one trajectory and keep it. It picks a policy, and the policy generates trajectories. Different runs produce different reward sequences, because transitions and sometimes actions are random.

That is why the objective is not G0G_0 itself. The objective is the expected return — the average of G0G_0 over all the trajectories the policy could produce:

max⁡π  Eπ[G0]\max_{\pi} \; \mathbb{E}_{\pi}\left[ G_0 \right]

Read the pieces. π\pi is the policy, the agent's rule for choosing actions. The expectation Eπ\mathbb{E}_{\pi} averages over the randomness in the environment and in the policy's own choices. G0G_0 is the discounted return from the start. The agent is not trying to make one lucky run look good; it is trying to make the average run good.

This distinction matters the moment you start reading algorithms. A single GtG_t is a sample. The expected return is the thing being optimized. Value functions are the bridge between them: V(s)V(s) and Q(s,a)Q(s, a) estimate the expected return you would collect starting from a state or a state-action pair, which is exactly the quantity the policy is trying to push upward.

Common mistake: Confusing a high return on one episode with a good policy. A policy is judged by its expected return across many episodes, not by its best single run.

Worked Example: Discounting a Short Reward Sequence

Numbers make this concrete. Suppose the agent receives rewards r0=1r_0 = 1, r1=2r_1 = 2, r2=3r_2 = 3, and then the episode ends. Take γ=0.9\gamma = 0.9.

Write each term with its weight:

G0=γ0(1)+γ1(2)+γ2(3)G_0 = \gamma^0 (1) + \gamma^1 (2) + \gamma^2 (3)

Compute the weights: γ0=1\gamma^0 = 1, γ1=0.9\gamma^1 = 0.9, γ2=0.81\gamma^2 = 0.81. Now the arithmetic:

G0=1+0.9(2)+0.81(3)=1+1.8+2.43=5.23G_0 = 1 + 0.9(2) + 0.81(3) = 1 + 1.8 + 2.43 = 5.23

Now the same rewards with γ=0.5\gamma = 0.5. The weights become 11, 0.50.5, and 0.250.25:

G0=1+0.5(2)+0.25(3)=1+1.0+0.75=2.75G_0 = 1 + 0.5(2) + 0.25(3) = 1 + 1.0 + 0.75 = 2.75

Same rewards. Same order. Different objective. The lower discount factor shrinks the later contributions hard: the third reward drops from 2.432.43 to 0.750.75, while the first reward is untouched in both cases.

γ\gammaWeight on r0r_0Weight on r1r_1Weight on r2r_2Return
0.91.000.900.815.23
0.51.000.500.252.75

A sanity check you can run on any return: it always sits between the undiscounted sum and the first reward alone. Here the undiscounted sum is 66, and the first reward is 11. Both 5.235.23 and 2.752.75 fall inside that range, as they must.

Knowledge check

Check your understanding

Answer this question before you continue.

For rewards r₀ = 1, r₁ = 2, and r₂ = 3, what is G₀ when γ = 0.5?
Output Prediction

Focus: Calculate discounted return for a short reward sequence using the stated discount factor.

How Task Structure Changes the Objective

The formula is the same. What it means depends on whether the task ends.

In an episodic task, the interaction runs until a terminal state, then resets. The horizon is finite, so the sum has a natural stopping point. Because the sum is finite, γ=1\gamma = 1 is mathematically available — the undiscounted return will not diverge. But available is not the same as appropriate. Discounting still encodes a preference for earlier reward, and whether you want that preference depends on the task, not on whether episodes happen to end. If every reward through termination should count equally, γ=1\gamma = 1 matches your intent. If a reward ten steps before the end should matter less than one now, keep γ<1\gamma < 1 even though the episode is finite.

In a continuing task, there is no terminal state. The agent runs forever. Here discounting is what keeps the objective well-defined. An alternative is an average-reward formulation, which measures reward per step rather than a total, but the discounted return is the standard practical objective and the one most value methods assume.

Task typeHorizonIs γ<1\gamma < 1 required?What the return represents
EpisodicFinite, ends at terminal stateNo, but still a modeling choiceTotal reward until the episode ends
Continuing, discountedInfiniteYesWeighted total, with future rewards shrunk
Continuing, average-rewardInfiniteNot applicableReward per step, in the long run

The decision rule I use: first ask what the task actually values. If all rewards through termination should count equally, an undiscounted episodic return is defensible. If earlier rewards should matter more, discount — even in an episodic task. If the task runs forever, discounting is the default, because without it you have no finite number to maximize.

One practical blur worth knowing about. Algorithms frequently optimize one formulation while estimating values with another — for example, optimizing the undiscounted return but using a discount factor inside the value function. This is common enough that you should read the objective in the code, not assume it from the paper's framing.

What the Derivation Buys You

The return is not an abstraction that lives only in this article. It is the quantity that value functions estimate. V(s)V(s) and Q(s,a)Q(s, a) are expectations of GtG_t — the average return you would collect starting from a state or a state-action pair. Every value method you meet next is, at bottom, trying to predict the number we just derived.

Discounting also shapes behavior in ways you can see. A low γ\gamma produces a myopic agent that grabs nearby reward and ignores distant consequences. A high γ\gamma produces a far-sighted agent that will accept short-term pain for long-term gain. Change γ\gamma, and the policy changes with it.

Common mistake: Treating γ\gamma as a hyperparameter to tune until the numbers look good. It is a statement about how much the future should count. Tune it, yes — but know what you are claiming when you do.

Common mistake: Assuming a larger γ\gamma always means a better agent. A high discount factor can also mean slower, noisier learning, because the agent is now responsible for a longer and less certain chain of consequences.

Where This Leads Next

Before you write or read any RL objective, do two things. First, identify whether the task is episodic or continuing. Second, choose γ\gamma deliberately, because that choice defines what the agent is actually optimizing. Everything downstream inherits it.

The recursive form Gt=rt+γGt+1G_t = r_t + \gamma G_{t+1} is your next tool. It is the step that turns a definition of return into Bellman-style value targets, where the value of a state is written in terms of the values of the states that follow.

Here is a small exercise that will teach you more than rereading this article. Recompute the worked example with γ=0.99\gamma = 0.99 and again with γ=0.1\gamma = 0.1. Before you run the arithmetic, predict which reward dominates in each case, and what kind of policy each discount factor would produce. Then check your prediction against the numbers. When your prediction and the arithmetic agree, you own the concept.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

Two policies each produce some unusually high-return episodes, but their results vary across runs. What quantity should be compared to judge which policy the article's objective favors?
Question 1 of 2Comparison Reasoning

Focus: Distinguish a trajectory's sampled return from the objective optimized by a policy.

An agent's discount factor is lowered while its reward sequence is unchanged. Which behavioral shift is consistent with the article's explanation of discounting?
Question 2 of 2Scenario Interpretation

Focus: Predict how a lower discount factor changes the relative influence of near-term and distant rewards.

References

  1. Reinforcement Learning (DQN) Tutorial — PyTorch Tutorials 2.14.0+cu130 documentationdocs.pytorch.org
  2. Part 1: Key Concepts in RL — Spinning Up documentationspinningup.openai.com
Practical resource

Build a stronger RL mental model

Use structured resources to connect equations, algorithms, and observable agent behavior.

Browse resources
Related sites

Continue across related AI foundations

Use LearnPyFast for Python foundations and LearnLLMFast for practical language-model and agent application concepts.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related reinforcement learning tutorials

Continue with nearby RL concepts, algorithms, and experiments that build on the same decision process.