AI chatbots work by predicting text one small piece at a time. Your message is split into tokens, wrapped with hidden instructions and the conversation so far, and passed to a model that guesses the next piece over and over until the reply is done. Here is each step in order, with no maths.
You type "why won't my sourdough rise" into a chatbot, press enter, and a tidy paragraph starts appearing word by word. Between those two moments a lot happens, and none of it involves the chatbot finding your question in a book of stored answers. This page follows one message through each step, in the order it happens, with what you see on screen at each point.
How do AI chatbots work, in one paragraph
AI chatbots work by predicting text. Your message is cut into small pieces called tokens, joined to some hidden instructions and the conversation so far, and passed to a large language model. The model has learned, from a vast amount of text, which piece tends to come next. It picks one, adds it to the end, and repeats until the reply is finished. Everything below is detail on those steps.
Step one: your words become tokens
The first thing that happens to your message is that it stops being words. A tokeniser chops it into tokens: often whole short words, sometimes parts of longer ones, sometimes punctuation. "Sourdough" might become two or three pieces. Each token is then turned into a list of numbers the model can work with.
What you see: nothing yet. Why it matters: tokens are the unit everything is counted in. Usage limits, how long a conversation the model can hold, and the bill a developer pays are measured in tokens, not words. Our guide to tokens and costs goes further.
Step two: hidden text joins your message
Your question never travels alone. Before it reaches the model, the chatbot wraps it in other text:
- A system prompt. Instructions from the company that runs the chatbot: its tone, what to refuse, which tools it may use. You usually can't see them.
- Your custom instructions or memory, if you've set any.
- The conversation so far. The model doesn't hold your earlier messages between turns. The app sends them again every time.
- Anything you attached, turned into tokens as well.
All of that has to fit in the context window, the most text the model can consider at once. In a very long chat, the oldest material can drop out of view or be squashed into a summary. That's why a chatbot sometimes forgets a detail you gave it an hour ago.
Step three: the model scores every possible next token
Now the model does its one trick. It looks at every token in the window and works out how likely each possible next token is. It doesn't consult a list of facts. What it has is a huge set of numbers, called weights, adjusted during training until its predictions matched the patterns in its training text.
Training happened long before you opened the app, in two broad stages. Pretraining on general text taught it language and a great deal about the world. Further training on examples of helpful replies, and on people's ratings of replies, shaped it into something that answers like an assistant rather than just carrying on your sentence.
Two consequences follow. Its knowledge has an end date, the knowledge cutoff, and it knows nothing after that unless something fetches newer information. And it has no separate sense of whether a sentence is true; a wrong date can score as highly as a right one.
Step four: one token is picked, and the loop goes round
The model hands back likelihoods, not a word. The chatbot then picks one token, usually from among the likely ones, with a little randomness allowed in. A setting called temperature controls how much. The chosen token is added to the end, and the whole lot goes round again to predict the token after it.
What you see: the reply appearing piece by piece. That streaming isn't decoration; the rest of the answer genuinely doesn't exist yet when the first words show. The randomness is also why answers differ each time you ask.
| Step | What happens | What you see |
|---|
| 1 | Your message is split into tokens | Nothing yet |
| 2 | System prompt, history and attachments are added | Nothing yet |
| 3 | The model scores every possible next token | A brief pause |
| 4 | One token is picked and added, then repeat | Words streaming in |
| 5 | Sometimes a search or tool runs mid-answer | "Searching", or a list of sources |
| 6 | Safety checks and formatting | The finished reply |
Step five: sometimes it fetches something first
Many chatbots can now step outside the model. When a question needs fresh information, the model can produce a request instead of an answer: search the web, read a file, run a calculation. The chatbot carries that out, puts the results into the context window, and the model carries on predicting with those results in view. Answers with source links are usually built this way.
The prediction step hasn't changed, though. A chatbot can cite a real page and still summarise it wrongly. Search-led tools say as much about themselves. Perplexity's strength, as its fact sheet puts it: Web answers with clickable sources✓. Its caution: Cited answers can still be wrong: open the sources✓.
Step six: what happens to your words afterwards
The reply arrives, but your message may not be finished with. Depending on the tool, the type of account and your settings, conversations can be kept and used to improve later models. For ChatGPT: Consumer chats can be used to improve models unless you turn it off in Data Controls; Business, Enterprise and Edu are excluded✓. That isn't part of how the answer was made, but it is part of what happens when you type. Check the settings on whichever tool you use, and keep private details out of a personal account.
Odd chatbot behaviour, explained by the steps
Once you know the sequence, the strange moments stop looking mysterious.
- A confident wrong answer comes from step three: likely-sounding text isn't always true text.
- An out-of-date fact is the knowledge cutoff, when no search ran in step five.
- Forgetting what you said earlier is a full context window in step two.
- A different answer to the same question is the randomness in step four.
- Agreeing with you too readily comes from training that rewarded replies people liked.
Seeing the steps for yourself in a lesson
Reading about tokens only gets you so far. In Teach me AI's lessons, ideas such as tokens, training and context windows come with step-through interactive explainers: you move through each stage yourself rather than reading a paragraph about it. Diagrams are made to read on a phone and are described in words for screen readers.
The ideas sit mainly in What AI actually is and How machines learn, at level I, and How large language models work, at level III, for anyone who wants the mechanics properly. You can open a complete sample lesson with no account to see how it feels, and interactive explainers shows what the step-throughs cover. The free placement works out where you'd start, and an honest beginner finishes it fastest.
Who this won't suit: if you want the maths, attention written out as equations, or code to train a model of your own, a beginner walkthrough isn't the right page. A university course or a technical textbook will serve you better.
Five minutes to watch it happen
Open any chatbot you can use and try this:
Explain in three short sentences what a knowledge cutoff is. Then tell me your own knowledge cutoff, and how confident you are about it.
Then, in the same tool:
- Ask the same question in a new chat and compare the wording.
- Ask about something from this week and see whether it searches.
- Deep into a long chat, ask what your first message said.