AI
What Is Reinforcement Learning? Simple Examples
Reinforcement learning in simple words: how agents learn from rewards, real examples from games to ChatGPT, a Q-learning example and RL vs supervised.
Reinforcement learning (RL) is a type of machine learning where an agent learns by trial and error: it takes actions in an environment, receives rewards or penalties, and gradually learns which actions lead to the most reward over time. Nobody gives it the right answers in advance. It's how computers learned to beat world champions at Go, how robots learn to walk in simulation, and a key step in training ChatGPT, Claude and today's reasoning models.
This guide explains what reinforcement learning is in simple words, how it works, real reinforcement learning examples, a worked Q-learning example with numbers, how RL compares with supervised learning, and its newest use in training large language models.
What Is Reinforcement Learning in Simple Words?
What is reinforcement learning, in one picture? Think of training a dog. You don't explain the rules of "sit". The dog tries things, and when it sits, it gets a treat. Over many tries it learns that sitting when you say "sit" leads to treats. Reinforcement learning works the same way, with a computer program in place of the dog and a number in place of the treat.
The ingredients are always the same:
| Term | Meaning | Dog example | Game example |
|---|---|---|---|
| Agent | The learner that makes decisions | The dog | The game-playing program |
| Environment | The world the agent acts in | Your living room | The game |
| State | What the situation looks like now | You just said "sit" | The current board position |
| Action | A choice the agent can make | Sit, lie down, jump | Move a piece |
| Reward | A score for the result of an action | A treat, or nothing | +1 for a win, -1 for a loss |
| Policy | The agent's strategy: which action to take in each state | Its learned habits | Its learned way of playing |
The agent's goal isn't to get the biggest reward right now. It's to maximize the total reward over time, which is why RL can learn long-term strategies, like sacrificing a piece in chess to win later.
How Reinforcement Learning Works
Reinforcement learning runs as a loop:
- The agent observes the current state.
- It chooses an action using its current policy.
- The environment changes and returns a reward and the new state.
- The agent updates its policy so that actions leading to more reward become more likely.
- Repeat, often millions of times.
Exploration vs exploitation
Every RL agent faces the same dilemma. Should it exploit what it already knows works, or explore something new that might be better? A restaurant analogy makes it clear: always ordering your favourite dish is safe, but you'll never find a better one unless you sometimes try something else. RL algorithms balance the two, for example by taking a random action a small fraction of the time and gradually doing so less as they learn.
Delayed rewards
Many rewards arrive late. In a game, you only learn whether you won at the end, so the agent has to work out which of its many earlier moves deserve credit. Solving this "credit assignment" problem is a big part of what RL algorithms do, usually by estimating the value of each state: how much total reward the agent can expect from there.
Reinforcement Learning Examples
Here are reinforcement learning examples from research and real life:
- Board games. DeepMind's AlphaGo beat world champion Lee Sedol 4–1 in 2016, combining learning from human games with reinforcement learning through self-play. AlphaZero later learned chess, shogi and Go purely by playing against itself.
- Video games. DeepMind's DQN learned to play dozens of Atari games from the raw screen pixels and the score.
- Robotics. Robots learn to walk, grasp and balance, often in simulation first and then on real hardware.
- Recommendations and ads. Systems choose what to show next and learn from clicks, watch time or purchases. The simplest version is a "multi-armed bandit" that tests options and shifts traffic toward the winners.
- Resource control. RL has been used to tune cooling in data centres, schedule jobs and manage traffic lights.
- Large language models. ChatGPT, Claude and similar assistants are refined with reinforcement learning from human feedback, and reasoning models are trained with reinforcement learning on problems with checkable answers.
A reinforcement learning example in real life
Picture a robot vacuum learning the best cleaning route. Each move costs a little battery (a small negative reward), each newly cleaned patch earns a positive reward, and bumping into furniture or getting stuck costs a larger penalty. At first it wanders randomly. Over many runs, routes that clean more floor with fewer bumps get reinforced, and it learns an efficient pattern for your home without anyone programming the route.
A Worked Example: Q-Learning With Numbers
Q-learning is one of the classic RL algorithms, and it shows the core idea clearly. The agent keeps a table of Q-values: for each state and action, an estimate of the total future reward it will get if it takes that action and then plays well.
After each step it updates one entry with this rule:
New Q = Old Q + learning rate × (reward + discount × best Q of next state − Old Q)
Let's run it once. A robot in a small grid world is in state A and moves right into state B.
| Value | Number | Meaning |
|---|---|---|
| Old Q(A, right) | 0 | It hasn't learned anything about this move yet |
| Reward for the move | -1 | Each step costs a little, to encourage short paths |
| Best Q-value available from B | 10 | B is next to the goal, which it already learned about |
| Learning rate | 0.5 | How much each new experience changes the estimate |
| Discount factor | 0.9 | Future rewards count slightly less than immediate ones |
New Q(A, right) = 0 + 0.5 × (−1 + 0.9 × 10 − 0) = 0.5 × 8 = 4.
Moving right from A now looks good, because it leads toward the goal. Repeat this across thousands of steps and the table converges on the best action for every square. Modern deep RL replaces the table with a neural network, because real problems have far too many states to list, but the idea is the same. Our guide to what a neural network is explains that part.
Reinforcement Learning vs Q-Learning
Reinforcement learning vs Q-learning isn't a choice between two things: Q-learning is one algorithm inside reinforcement learning. RL is the overall approach of learning from rewards; Q-learning is a specific method that learns a value for every action in every state, as in the example above. Other RL algorithms, such as policy gradient methods and PPO, learn the agent's strategy directly instead of a table of action values. Deep Q-Networks (DQN) are Q-learning with a neural network in place of the table.
Types of Reinforcement Learning
- Model-free vs model-based. Model-free methods (such as Q-learning) learn what to do directly from experience. Model-based methods also learn how the environment works and plan ahead with that model.
- Value-based vs policy-based. Value-based methods learn how good each action is and pick the best one. Policy-based methods learn the strategy directly. Actor-critic methods, such as the widely used PPO, combine both.
- Online vs offline. Online RL learns by acting in the environment. Offline RL learns from a fixed log of past experience, useful when real-world trial and error is too costly or dangerous.
- Deep reinforcement learning uses neural networks inside any of these approaches, which is what made learning from raw pixels possible.
Reinforcement Learning vs Supervised Learning
The reinforcement learning vs supervised learning difference comes down to where the learning signal comes from.
| Supervised learning | Unsupervised learning | Reinforcement learning | |
|---|---|---|---|
| Learns from | Labeled examples with correct answers | Unlabeled data | Rewards from its own actions |
| Feedback | The right answer for every example | None | A score, often delayed |
| Goal | Predict the label for new inputs | Find structure or groups | Maximize total reward over time |
| Example | Classify emails as spam | Group customers by behaviour | Learn to play a game or control a robot |
| Data | A fixed dataset | A fixed dataset | Generated by the agent as it acts |
Supervised learning is like studying with an answer key. Reinforcement learning is like learning a sport by playing it and seeing the score. For more on how these fit together, see our guide to AI vs machine learning.
Reinforcement learning vs deep learning
These aren't alternatives. Deep learning is a technique (neural networks with many layers) and reinforcement learning is a way of learning from rewards. Deep reinforcement learning uses deep neural networks to represent the agent's policy or value estimates.
Reinforcement Learning vs Machine Learning
Reinforcement learning is one of the three main branches of machine learning, alongside supervised and unsupervised learning, so the comparison is between a part and the whole. What sets RL apart within machine learning:
- It creates its own data. Most machine learning learns from a fixed dataset; an RL agent generates experience by acting.
- It optimizes for the long run. The goal is total future reward, not the accuracy of one prediction.
- It learns decisions, not just predictions. The output is a policy: what to do next.
In practice, many systems combine them. A self-driving stack might use supervised learning to recognize objects and reinforcement learning to plan manoeuvres in simulation; a chatbot uses self-supervised pre-training, supervised fine-tuning and then reinforcement learning.
Reinforcement Learning in Large Language Models
Reinforcement learning became a central part of training AI assistants in two waves.
RLHF: learning from human preferences
After a language model is pre-trained on text, it's fine-tuned to be helpful and safe. In reinforcement learning from human feedback (RLHF), people compare pairs of answers, a reward model learns to predict which answers people prefer, and the language model is then trained with RL to produce answers that score well. Our RLHF guide explains each step and newer alternatives such as DPO.
Reinforcement learning with verifiable rewards
Reinforcement learning with verifiable rewards (RLVR) skips the human judges for tasks where the answer can be checked automatically: a maths problem with a known answer, code that must pass unit tests, a puzzle with a clear solution. The reward is simply whether the answer is right.
This is how today's reasoning models learned to think step by step. OpenAI described training its o1 models with large-scale reinforcement learning, and DeepSeek's R1 paper in January 2025 showed that RL with rule-based rewards for correct answers and proper format could teach a model long chains of reasoning. Because answers are checked by code, RLVR can scale to millions of problems without human labelling.
Challenges of Reinforcement Learning
- Reward hacking. The agent maximizes the reward you defined, not the goal you meant. OpenAI showed a boat-racing agent that learned to spin in circles collecting points instead of finishing the race. Designing good rewards is hard.
- Sample inefficiency. RL often needs huge amounts of trial and error, which is why so much training happens in simulation.
- Sim-to-real gap. Behaviour learned in simulation may fail in the messier real world.
- Safety. Trial and error is unacceptable in many real systems, such as healthcare or driving, without strong safeguards or offline learning.
- Instability. Training can be sensitive to settings and hard to reproduce.
How to Get Started With Reinforcement Learning
- Learn the basics from Sutton and Barto's textbook Reinforcement Learning: An Introduction, the standard reference. Richard Sutton and Andrew Barto received the 2024 ACM Turing Award for their foundational work on RL.
- Play with simple environments using Gymnasium, the maintained successor to OpenAI Gym, which provides classic tasks like CartPole and grid worlds.
- Use a tested library such as Stable-Baselines3 to try standard algorithms like DQN and PPO before writing your own.
- Start with a bandit or grid world, then move to harder control tasks.
FAQ
What is reinforcement learning with an example?
Reinforcement learning is machine learning by trial and error with rewards. A simple example is a program learning a video game: it tries moves, gets points for good outcomes and loses points for bad ones, and over many games learns a strategy that scores highly.
What is the difference between reinforcement learning and supervised learning?
Supervised learning learns from examples that come with correct answers. Reinforcement learning has no answer key; it learns from rewards for its own actions, which are often delayed, and aims to maximize total reward over time.
Is ChatGPT trained with reinforcement learning?
Yes, in part. ChatGPT is first pre-trained on large amounts of text, then refined with reinforcement learning from human feedback. Newer reasoning models also use reinforcement learning on problems with automatically checkable answers.
What is reinforcement learning with verifiable rewards?
It's reinforcement learning where the reward comes from an automatic check, such as whether a maths answer is correct or code passes its tests, instead of from human ratings. It's widely used to train reasoning models.
What is Q-learning?
Q-learning is a classic reinforcement learning algorithm that learns a value for every action in every state, updating each value from the reward received plus the best value of the next state. The agent then picks the action with the highest value.