How does an LLM actually work?
Underneath every AI chatbot is one surprisingly simple idea: predicting the next word, over and over. This guide explains how a large language model turns your prompt into an answer, and why that makes it fluent yet fallible.
A large language model works by predicting one token, a word or part of a word, at a time. It reads all the text so far, works out which token is most likely to come next, picks one, adds it, and repeats. Everything it does, answering, writing, or coding, is that single loop run at remarkable speed.
That idea sounds almost too simple for something that can draft an essay or explain your tax return. Yet next-token prediction really is the engine underneath. Once it clicks, a lot of AI’s strengths and quirks stop being mysterious.
It all comes down to predicting the next token
When you send a message, the model first breaks the text into tokens, which are word-sized chunks. It then does one thing: for the text so far, it produces a probability for every token that could come next. Some are very likely, most are near zero.
The model picks one of the likely tokens, adds it to the end of the text, and then runs the whole process again on the slightly longer text. Word by word, an answer takes shape, each new token shaped by everything before it, which includes your prompt and whatever the model has written so far.
Where the “intelligence” comes from
If the model is only predicting the next token, where does its apparent knowledge come from? The answer is in two separate phases.
The first is training. The large language model is shown an enormous amount of text and gradually adjusts millions or billions of internal settings until it becomes very good at predicting what comes next. This is slow, expensive, and done once. Our guide on how AI models are trained covers this in more depth.
The second phase is when you actually use it, which is called inference. Here, no learning happens. The model applies the patterns it already absorbed to predict tokens for your particular text. It is not looking anything up in a database. It is drawing on a statistical sense of language, baked in during training.
Why it is so fluent, yet sometimes confidently wrong
This is the single most important thing to understand about these tools. Because the model is trained to produce likely, natural text, its writing flows beautifully. Fluency is exactly what it optimises for.
The catch is that likely and true are not the same thing. If a smooth, plausible sentence happens to be false, the model may produce it with total confidence. This is called a hallucination. The model is not lying, because it has no concept of true or false. It only has a sense of what reads as likely, which is why anything that matters is worth checking.
Why the same prompt can give different answers
You may have noticed that asking the same thing twice gives different wording each time. That is because the model does not always pick the single most likely token. It adds a small amount of controlled randomness when it chooses, so each run can take a slightly different path.
Turn that randomness up and answers get more varied and creative. Turn it down and they get more predictable and repetitive. It is a deliberate dial, not a fault, and it is why AI feels more like a fresh draft each time than a fixed lookup.
What the model can actually see
A model has no memory of you between separate chats, and even within one chat it can only work from the text currently in front of it. That window of visible text, your prompt plus the recent back-and-forth, has a size limit called the context window.
Everything inside the window shapes the next token. Anything that falls outside it, such as the start of a very long conversation, is gone from the model’s view. This is why long chats sometimes seem to forget earlier details.
Try it yourself
You can watch next-token prediction in action. Paste this into any chatbot:
Complete this sentence, then in brackets list three other words that
could plausibly have come next instead: "The best thing about
mornings is ___"
The model will finish the sentence and show you the alternatives it was, in effect, choosing between. That short list is a glimpse of the probabilities in the diagram above, made visible.
Next steps
Now that you know how a model turns your prompt into an answer, the natural next question is how it learned to do that in the first place. Our guide on how AI models are trained picks up the story, and what embeddings are explains how AI represents meaning as numbers.
Frequently asked questions
- Does an LLM understand what it is saying?
- Not in the way a person does. It has no beliefs, intentions, or grasp of meaning. It works out which word is statistically likely to come next, based on patterns learned from huge amounts of text. The results can feel like understanding, but underneath it is very sophisticated pattern-matching, not comprehension.
- Is an LLM only a fancy autocomplete?
- That is a fair starting analogy: both predict the next word. The difference is scale and depth. An LLM has learned far richer patterns across billions of examples, so it can follow instructions, hold a thread, and adapt its tone. It is autocomplete taken so far that it becomes genuinely useful.
- Why does an LLM make things up?
- Because it predicts plausible text, not verified facts. If a confident-sounding but untrue sentence is statistically likely, the model may produce it. This is called a hallucination. The model has no built-in sense of true or false, which is why you should check anything that matters against a trusted source.
- Why do I get a different answer each time I ask?
- An LLM does not always pick the single most likely next word. It adds a little controlled randomness when choosing, so the same prompt can take a different path each time. More randomness gives more varied, creative answers; less gives more predictable ones. It is a deliberate setting, not a glitch.