Tokens · end to end

An LLM never sees your words.
It sees tokens.

Before a model can reason about text, the text is chopped into subword pieces called tokens, turned into numbers, and fed through the network one step at a time. Type below to watch it happen.

Live tokenizer

0tokens
0characters
0chars / token

Hover a chip to see its vocabulary ID. The little · marks a leading space — spaces live inside tokens, which is why " the" and "the" are different tokens.

This tool is an illustrative approximation of Byte-Pair Encoding — real GPT/Gemini vocabularies are learned from data, but the behavior you see (subword splits, leading spaces, digit fragments) is faithful.

01

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

Characters (too many units): u n h a p p i n e s s — 11 units
Words (huge, brittle vocab): unhappiness — 1 unit, but a whole slot wasted on one rare word
Subword tokens (the sweet spot): un · happ · iness — reuses pieces across thousands of words

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.

02

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

Start: every character is its own unit. The most frequent pair gets merged first.

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.

03

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

"Kubernetes"  →  "Kub" → 42055  ·  "ernetes" → 44357
" scaling"  →  "·scaling" → 27972
"429"  →  "4" → 19  ·  "29" → 1959

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.

04

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)

token "·scaling" · id 27972 becomes:
each cell is one learned number; the full vector is the model's entire "notion" of that token before it reads any context.

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 kingqueen resembles manwoman.

05

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

"Aa"raw text
▮▮▮token IDs
[·]embeddings + position
transformer layers (attention)
▁▃▇logit per vocab token
06

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

0.70

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.

07

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.

08

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.

context window

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

cost

You pay per token

Billing is input tokens + output tokens, not requests. Output usually costs several times more than input.

1,200 input tok × $3/M$0.0036
450 output tok × $15/M$0.0068
per call$0.0104

multiply by millions of calls and token efficiency becomes a real line item.

the classic failure

"How many R's in strawberry?"

The model sees chunks, not letters — so counting characters is genuinely hard for it:

str aw berry

The three R's are buried inside tokens it can't natively see through.

prompt / prefix caching

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.

The whole journey

  1. Text is chopped into subword tokens — not words, not characters, but frequent chunks.
  2. BPE learned those chunks by merging the most common adjacent pairs, over and over.
  3. Each token becomes an integer ID — a row in a fixed vocabulary.
  4. Each ID is looked up as a learned vector, where geometry encodes meaning.
  5. Layers of attention mix in context and output a logit for every vocab token.
  6. Softmax + temperature turn those scores into a probability draw.
  7. The chosen token is appended and fed back — one token at a time until stop.
  8. Context, cost, and quirks all trace straight back to the token.

Interactive tokenizer, BPE walk, embedding sketch, softmax and generation loop are illustrative — sized to build intuition, not to reproduce a specific vendor's exact vocabulary. The mechanics shown are the real ones.