> ## Content Index
> Fetch the complete content index at: https://madewithlove.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# How LLMs actually work (explained like I'm 5)
- URL: https://madewithlove.com/blog/how-llms-actually-work-explained-like-im-5/
- Published: 2026-10-27T09:22:00.000Z
- Updated: 2026-10-27T09:22:00.000Z
- Description: An LLM does one thing: it predicts the next token. Training nudges that guess towards the right answer billions of times, attention lets it look back at the tokens that matter, and chaining guesses together turns a prediction into an essay.
- Author: Oluwaseyi Samuel Adeogun
- Tags: AI, LLMs, Machine learning, Tutorials, AI development, AI Agents, Claude, Engineering

This series explains how LLMs (large language models, the AI behind tools like ChatGPT) work, in plain language. Each part covers one idea at a time, without heavy maths or jargon, so you can build understanding step by step.

## The friend analogy

Imagine a friend who has read a huge amount of text. Fiction, textbooks, recipes, news articles, everything.

Now you ask them: "What comes after 'peanut'?"

They don't think. They just say "butter" because they've seen "peanut butter" millions of times.

You ask: "What comes after 'The sky is'?"

They say "blue" because that phrase appears everywhere.

You ask: "What comes after 'What a time to be'?"

They say "alive" because they heard it from your colleague Alex.

**That's the core of what an LLM does: it predicts what comes next based on what it has seen before.**

One detail before we go on. LLMs predict tokens. A token is a word or a chunk of a word: a short, common word is usually one token, and a long or rare word gets split into several.

## How training actually works

How did your friend learn all this? They practised. They read millions of examples until patterns stuck in their brain.

An LLM learns in a similar way. It's shown billions of pieces of text with the next token hidden and asked: "What comes next?" It guesses.

The guess is compared with the next real token, and the model's internal numbers (its weights) are nudged slightly toward the correct answer. Then it moves on to the next example. After billions of these nudges, the patterns stick.

Your phone keyboard does a small version of this. You type "I'm feeling" and it suggests "lucky" or "good" because in the text it learned from, those words often came next. The technology inside a keyboard is usually much simpler than an LLM, but the idea is the same: predict what comes next from what came before.

This step is called self-supervised learning. Each example still has a right answer, the hidden token, but the text supplies it. Nobody has to write those answers by hand, the way people sort emails into spam and not spam.

Later, chatbots get extra training to behave like assistants. First they learn from example conversations (this is called supervised fine-tuning). Then many also learn from people's ratings: people score answers, and the model learns to prefer the better ones (this is called reinforcement learning from human feedback, or RLHF).

## An essay is just predicting the next token, over and over

When you ask an LLM to write an essay, it:

1. Reads your prompt
2. Predicts the first token it should write
3. Adds that token to what it's writing
4. Predicts the next token
5. Adds that one too
6. Repeats until it's done

After a few hundred tokens, you have an essay.

Nobody gave it an essay template. **Chain together hundreds of predictions that each follow "what usually comes next" and the result reads like an essay.**

One more detail: the model doesn't give just one token. It gives every possible next token a score for [how likely](https://madewithlove.com/blog/ai-needs-more-uncertainty/) it is to come next, and the software running the model picks one. It could always take the most likely one, but that tends to produce flat, repetitive text.

So chat tools usually add a bit of randomness on purpose, still favouring likely tokens. A setting called temperature controls how much. **That's why the same prompt can give you a different answer each time.**

## The problem: long texts forget

In a long text, the token that matters might be hundreds of tokens back.

Think of a long novel. On page 3, a side character called Alice loses her job. On page 50 you read "Alice was finally happy." By then you've forgotten who she is.

Older AI models had the same problem. They read text one token at a time and carried a running memory of what they'd seen. Over long stretches, that memory faded, and important details from earlier got lost.

## The fix: attention

Modern LLMs solve this with attention. **Before predicting the next token, the model looks back at the earlier tokens and decides how much each one matters right now.** It sees all of them, but it doesn't weigh them equally.

To finish "Alice was finally \_\_\_", the tokens about Alice losing her job count for a lot. A line about the weather on page 12 counts for almost nothing.

It's like reading, thinking "wait, who is Alice?" and flipping back to the right page instead of rereading the whole book.

There is a limit. A model can only look back over a fixed number of tokens, called its [context window](https://madewithlove.com/blog/your-claude-code-is-burning-through-tokens-heres-how-to-fix-it/). **Anything past that limit, such as the start of a very long chat, drops out, and the model can't see it at all.**

Attention already existed as an add-on to older models. The transformer, introduced in 2017, was built on attention alone, and that brought a second benefit: since it no longer had to read one token at a time, it could take in all the tokens in a passage at once during training. That made it practical to train on far more text than before.

Those two things together, looking back at the earlier tokens that matter and much faster training, are what made modern LLMs possible.

## Why many chat LLMs don't need to "read" and "write" separately

The original transformer was designed for translation. It had two parts:

- An encoder that reads the English and writes notes on what it means
- A decoder that reads those notes and writes the French

Picture two people at the United Nations. One listens to the English speech and writes notes on what it means. The other reads the notes and writes the French.

Tools like ChatGPT don't need two people. Your question and its answer are a single long line of tokens, and the job is the same as before: guess the next token based on the ones before it. So they keep only the writer, the decoder. It's like one person who reads the speech and writes the reply themselves.

That's why they're called decoder-only.

## The full picture

1. Build the model as a transformer, so it can look back at the earlier tokens that matter, within its context window
2. Show it huge amounts of text and have it guess the next token billions of times (training)
3. Train it some more on example conversations and people's ratings so it acts like a helpful assistant
4. To write essays, answers or code, have it guess one token at a time and chain the guesses together

That's the core of modern LLMs, including the models behind ChatGPT, [Claude and Gemini](https://madewithlove.com/blog/exploring-llm-options-proprietary-vs-open-source/).