← All guides

How Large Language Models Work

A practical, math-free guide to how LLMs work. Tokenization, embeddings, transformer processing, and next-token prediction. Learn why prompts matter, context windows exist, and models hallucinate.

Ebenezer Don

Large language models like ChatGPT, Claude, and Gemini feel like magic. You type a question, and coherent, often insightful text appears. But under the hood, they’re doing something surprisingly mechanical. Understanding how they work, even at a high level, will make you a better user. You’ll know why some prompts work and others don’t, why context limits matter, and why models sometimes make things up.

This guide explains LLMs without math, using analogies and practical examples. By the end, you’ll have a mental model that improves how you use these tools every day.

Step 1: Tokenization. Breaking Text Into Chunks

Before a model can process your text, it has to break it into smaller pieces called tokens. Think of tokens like LEGO bricks: the model doesn’t work with whole words or sentences, but with these standardized chunks.

A token might be a word (“hello”), part of a word (“ing” in “running”), or even a single character for rare symbols. On average, one token is roughly four characters or three-quarters of a word in English. So “How do large language models work?” might become six or seven tokens.

Why this matters for you: When you see “context window” limits (e.g., 128K tokens), that’s counting these chunks. Longer prompts and conversations consume more tokens. Being concise saves space for the model to “remember” more of your conversation. Also, odd formatting, special characters, or non-English text can use more tokens than you expect, eating into your context budget.

Step 2: Embeddings. Turning Tokens Into Numbers

Raw text is useless to a computer. The model converts each token into a list of numbers (a vector) that captures its meaning and relationships to other tokens. This process is called embedding.

Imagine a giant map where similar words sit close together. “King” and “queen” would be nearby; “king” and “banana” would be far apart. The model learns these positions from massive amounts of text during training. Each token gets coordinates in a high-dimensional space (often 4,000+ dimensions), and those coordinates encode semantic meaning.

Why this matters for you: When you rephrase a prompt, you’re feeding different tokens. Slightly different wording can land in different parts of this “meaning space,” which can change the model’s behavior. That’s why prompt tweaks sometimes have outsized effects. You’re nudging the model toward different regions of its learned knowledge.

Step 3: Transformer Processing. The Brain of the Model

Once your tokens are embedded, they flow through a transformer architecture. This is the core innovation behind modern LLMs. The transformer doesn’t process tokens one by one in order; it looks at all of them at once and lets each token “attend” to every other token.

Think of it like a brainstorming session. Each word in your prompt can look at every other word and ask: “Given what else is here, what does my presence imply?” The model runs many layers of this attention, building up a rich representation of your full input. It’s not just reading left-to-right. It’s considering the whole context at once.

This is why context matters so much. Everything in your prompt influences the output. A stray sentence, an example you included, or the tone you used. All of it feeds into the transformer’s calculations. The model is doing pattern-matching at scale, and your prompt is the pattern you’re asking it to complete.

Step 4: Next-Token Prediction. One Word at a Time

Here’s the key insight: LLMs don’t “know” anything in the way you do. They predict the next token. Given everything they’ve seen (your prompt plus their own previous output), they assign probabilities to what token should come next. They sample from those probabilities and append the chosen token. Then they repeat.

It’s like autocomplete on steroids. Your phone suggests the next word; an LLM suggests the next token across billions of parameters trained on the internet, books, and code. The model has learned statistical patterns: “After ‘The capital of France is,’ the next token is very likely ‘Paris.’” It doesn’t have a database of facts. It has learned correlations from training data.

Why this matters for you: The model is always guessing. When it’s confident (common patterns, well-represented in training data), it’s usually right. When it’s uncertain (rare facts, edge cases, or topics it wasn’t trained on), it can guess wrong. That’s hallucination: the model generating plausible-sounding but incorrect text. It’s not lying; it’s predicting what looks right based on patterns, not what is right.

Step 5: Autoregressive Generation. Building Output Token by Token

The model generates text autoregressively: each new token depends on all previous tokens. It can’t jump ahead or revise. Once it outputs “Paris,” that’s fixed; the next token is predicted given “Paris” is there.

This has practical implications. Long outputs can drift. Early tokens constrain later ones, and small errors compound. That’s why breaking complex tasks into smaller steps often works better than asking for one giant response. You’re giving the model multiple “restart” points instead of one long chain of predictions.

What This Means for How You Use LLMs

Why Prompts Matter

The prompt is the only input the model has. It shapes which patterns the model activates, which “region” of its training it draws from, and what kind of output it considers likely. A vague prompt leaves more to chance; a clear one steers the model toward the patterns you want. Prompting isn’t trickery. It’s giving the model the right context so its next-token predictions align with your goals.

Why Context Windows Exist

The transformer has a fixed capacity. It can only “attend” to so many tokens at once. Beyond that limit, something has to be dropped or summarized. Context windows (32K, 128K, 200K tokens) are that limit. When you hit it, the model literally cannot see your earliest messages. Prioritize what matters: put critical instructions and examples where the model will still “see” them.

Why Models Hallucinate

Hallucination isn’t a bug; it’s a side effect of next-token prediction. The model optimizes for plausible continuations, not factual correctness. When the right answer isn’t strongly represented in its training, or when the prompt encourages creativity over accuracy, it will confidently produce wrong answers. Mitigate this by asking for citations, breaking tasks into verifiable steps, or using retrieval-augmented tools that ground the model in real data.

The Bottom Line

LLMs are pattern-completion engines. They tokenize your input, embed it, process it through attention layers, and predict the next token over and over. They don’t “think” or “know.” They extrapolate from learned statistical patterns. Understanding this demystifies their behavior and makes you a more effective user.


For a deeper dive into how to work with these models, including advanced prompting, tool use, and building reliable AI systems, check out Get Insanely Good at AI.

Go deeper with the book

This guide covers the essentials. Get Insanely Good at AI goes further, with practical frameworks, real workflows, and the understanding that makes everything click.

Get the Book