What actually is a token?
A token is the smallest unit of text the model works with. It is usually not a whole word and not a single character — it sits in between, at the level of frequently-seen chunks. Common words like the are one token. Rare or long words get split: tokenization might become token + ization. Whitespace, punctuation, and even emoji all become tokens too.
Three ways to cut the same sentence
Subwords are a compromise: small enough that a fixed vocabulary (typically ~50,000 to ~200,000 tokens) can express any text, large enough that common text stays short. That vocabulary size is a hard design constant of the model.
How the split is learned — Byte-Pair Encoding
The vocabulary isn't hand-written. An algorithm called Byte-Pair Encoding (BPE) starts from raw characters and repeatedly merges the most frequent adjacent pair into a new single unit. Do that thousands of times over a huge corpus and the merges that survive are the vocabulary. Step through a tiny run below.
Merging the word "lowering" · click to run BPE
In the real training run this happens across billions of words, so the pairs that win are the ones that recur everywhere — ing, tion, the. That's why the tokenizer feels like it "knows" English morphology: it doesn't, it just kept the merges that paid off statistically.
Every token is really an integer
Once the vocabulary exists, each token maps to a fixed integer ID — its row number in the vocabulary. The model never manipulates letters; it manipulates these IDs. Tokenizing is just a dictionary lookup from text chunk to number, and detokenizing is the same lookup in reverse.
text → token → id
That last line is why models are shaky at arithmetic: a number like 429 isn't a quantity to them, it's an arbitrary sequence of digit-fragment IDs. The model has to learn that 4+29 means four hundred twenty-nine — nothing in the IDs tells it so.
From ID to meaning — embeddings
An integer ID carries no meaning on its own (ID 5,000 isn't "bigger" than ID 12). So the first thing the model does is look up each ID in an embedding table and replace it with a long list of numbers — a vector, often 2,000–12,000 dimensions wide. These vectors are learned, and tokens that behave similarly end up pointing in similar directions.
One token → one vector (showing 24 of ~4096 dimensions)
Why it's a vector: similar tokens cluster (2D sketch)
Illustrative projection. In real models these live in thousands of dimensions, but the intuition holds: geometry encodes meaning, so directions become reusable — the step from king→queen resembles man→woman.
Through the model — the network turns vectors into a prediction
The sequence of token vectors (plus a position signal so order isn't lost) flows through many transformer layers. Attention lets every token look at every earlier token and mix in relevant context, so the vector for bank ends up different in "river bank" vs "bank account." After the final layer, the model produces one score — a logit — for every token in the vocabulary: "how likely are you to come next?"
the whole pipeline, one glance
Picking the next token — softmax & temperature
Raw logits are unbounded scores. Softmax squashes the whole set into probabilities that sum to 100%. Then temperature reshapes that distribution before a token is drawn: low temperature sharpens it toward the top choice (deterministic, safe), high temperature flattens it (diverse, riskier). Drag the slider.
"The cache was completely ___" · next-token probabilities
At temperature → 0 the model always takes the single highest-probability token (greedy) — repeatable, but flat. Turn it up and rarer tokens get a real chance, which is where both creativity and hallucination come from. This one knob is the difference between a boring answer and a wild one.
One token at a time — the autoregressive loop
A model doesn't emit a sentence in one shot. It predicts one token, appends it to the input, and runs the whole thing again to predict the next — over and over until it emits a special stop token. Everything it has already written becomes part of the context for what comes next.
generating "scaling pods now" token by token
This is also why latency scales with output length: every single output token is a full forward pass through the network. Longer answers literally cost more compute, token for token.
Why any of this matters in practice
Tokens aren't trivia — they're the unit of nearly every real constraint you hit when building with LLMs.
Memory is measured in tokens
A "128K context" means 128,000 tokens of prompt + history + output combined. When the budget fills, the oldest tokens fall out of view.
system · history · your prompt · room to answer
You pay per token
Billing is input tokens + output tokens, not requests. Output usually costs several times more than input.
multiply by millions of calls and token efficiency becomes a real line item.
"How many R's in strawberry?"
The model sees chunks, not letters — so counting characters is genuinely hard for it:
The three R's are buried inside tokens it can't natively see through.
Reuse the prefix, skip the work
Because generation is left-to-right, an unchanged prompt prefix produces identical early computation. Caching it means a stable system prompt or tool schema isn't re-processed every call — cheaper and faster, the same reason a fixed model prefix earns implicit caching.