How Large Language Models Actually Work
A plain-English tour of tokens, training, context and hallucination — what a language model is really doing when it answers you.
Most explanations of large language models fall into one of two traps. Either they wave at the machine and call it magic, or they bury the reader in matrix algebra. The truth sits in between, and it is genuinely understandable without a maths degree. A language model is a statistical system that has read an enormous amount of text and learned, in extraordinary detail, which pieces of text tend to follow which other pieces. Everything else — the fluency, the apparent reasoning, the occasional confident nonsense — follows from that one idea and the scale at which it is applied.
This piece walks through the four concepts you need to reason about these systems sensibly: tokens, training, context, and hallucination. If you understand those, you can evaluate almost any claim you hear about AI tools.
Text becomes tokens first
A model does not see letters or words. Before anything happens, your text is chopped into tokens: chunks that are usually somewhere between a character and a word. Common words are often a single token. Rarer words get split into fragments. Punctuation, spaces and line breaks are tokens too.
This sounds like a technical footnote, but it explains several behaviours people find puzzling:
- Models are historically weak at counting letters in a word, because they never see the letters as separate units.
- Text in languages with less representation in the training data often costs more tokens to express the same meaning, which makes it slower and more expensive to process.
- Unusual names, code identifiers and long numbers fragment into many tokens, and models handle fragmented things less reliably.
Each token is converted into a list of numbers — an embedding — that positions it in a high-dimensional space where related meanings sit near each other. From there on, the model is doing arithmetic on numbers, not manipulating words.
Training: prediction at enormous scale
The core training task is almost comically simple. Show the model a stretch of real text with the next token hidden, ask it to guess, and nudge its internal parameters slightly toward the correct answer. Repeat across a very large body of text. That is pretraining.
What makes this powerful is that predicting the next token well requires learning a great deal about the world. To finish the sentence “the capital of Japan is” you need a fact. To finish “she opened the umbrella because it had started to” you need a causal model of weather. To complete a half-written function you need syntax and intent. None of this is taught explicitly; it is absorbed as a side effect of getting good at prediction.
The stages after pretraining
A raw pretrained model is a talented text continuer but a poor assistant. It might answer a question by inventing ten more questions, because that is what documents often look like. Two further stages usually follow:
- Instruction tuning: further training on examples of requests paired with good responses, so the model learns the shape of being helpful rather than merely plausible.
- Preference tuning: humans (and increasingly other models) compare candidate responses, and the model is adjusted toward the preferred ones. This is where tone, refusal behaviour, formatting habits and much of what people call “personality” come from.
Two important consequences. First, the model's knowledge is frozen at the point its training data ends; anything after that is unknown to it unless supplied at the time you ask. Second, style and safety behaviour are largely a product of these later stages, which is why models built on similar foundations can feel very different to use.
Context: the model's working memory
When you send a message, the model does not consult a database of your past conversations. It reads a block of text — the context window — containing the system instructions, any documents supplied, the conversation so far, and your latest message. It then predicts a continuation, one token at a time, feeding each token back in as it goes.
The context window has a maximum size, measured in tokens. Everything the model “knows” in the moment must fit inside it. This explains a lot:
- A long conversation eventually pushes early details out of view, so the model appears to forget things you told it.
- Pasting a document works because it puts the text into context, not because the model has learned it. Start a fresh chat and the document is gone.
- Attention is not uniform across a long context. Material at the very start and very end tends to be used more reliably than material buried in the middle, so placing your key instructions near the end of a long prompt often helps.
Why answers vary
The model produces a probability distribution over possible next tokens, then samples from it. A setting usually called temperature controls how adventurous that sampling is. Low values make output more predictable and repetitive; higher values make it more varied and more prone to drift. This is why the same question can yield different answers, and why “it worked yesterday” is not strong evidence about a tool's reliability.
Hallucination is a feature of the mechanism
When a model states something false with complete confidence, it has not malfunctioned. It has done exactly what it always does: produce a fluent continuation. Fluency and factual accuracy are correlated in training data, but they are not the same thing, and where the model's knowledge is thin the fluency remains while the accuracy does not.
Predictable danger zones include specific numbers and dates, citations and URLs, quotations, legal and medical specifics, obscure people and small organisations, and anything that happened after training ended. The failure is worst precisely where verification matters most, because a plausible fake reference looks exactly like a real one.
Practical mitigations exist. Retrieval systems fetch real documents and place them in context so the model can work from source text rather than memory. Tool use lets a model run a calculation or query a live system instead of guessing. Asking for the reasoning, or asking the same question in a fresh session and comparing, surfaces instability. None of these eliminate the problem; they reduce its rate and make it easier to catch.
What this means in practice
Once you see the mechanism, a working style suggests itself. Treat the model as a fast, widely-read, occasionally overconfident collaborator rather than an oracle. Give it the material it needs rather than assuming it knows. Verify anything you would be embarrassed to be wrong about. Notice that its confidence carries no information about its correctness — that is the single most useful habit to build.
The practical takeaway: before trusting an answer, ask yourself whether the information was in the context you supplied, or whether the model produced it from memory. Supplied information is usually reliable because the model is reading it. Recalled information is a probabilistic reconstruction, and deserves a check proportional to what it would cost you to be wrong.
Put this into practice
Work out what an AI model actually costs per month from your token usage, and compare the major models side by side.
Open the AI API Cost Calculator →A note on shelf life. AI products change fast. This guide deliberately focuses on the parts that stay true — how to judge a tool, what the trade-offs are — rather than ranking products that will have changed by the time you read it. Prices and feature claims should always be checked against the provider before you rely on them.