TL;DR
The short answer
A token is the unit of text a language model actually reads and writes: often a whole common word with its leading space, sometimes a piece of a longer word, a punctuation mark or a single character. Before a model sees your text, a tokenizer cuts it into tokens from a fixed vocabulary and replaces each one with a number.
In English, a token averages about four characters, or three quarters of a word: 1,000 tokens is roughly 750 words. Everything practical about language models is counted in tokens: the price of a request, the size of the context window, and the speed of the answer.
A network needs numbers, not letters
From lesson 2 you know that a neural network is a big calculator: numbers go in, numbers come out. So the first problem of any language model is turning text into numbers. There are three obvious ways to do it, and the first two don't work well.
One number per letter. Simple, and the vocabulary is tiny. But a page of text becomes thousands of steps, the model has to learn that "c", "a", "t" next to each other mean a small furry animal, and every computation gets slower because sequences are long.
One number per word. Now "cat" is a single number. But English has hundreds of thousands of words, plus names, typos, slang, code, URLs, and every other language. Any word not in the dictionary becomes "unknown," and the model is blind to it.
Something in between. Common words get their own number. Rare words are built from pieces: "tokenization" becomes "Token" + "ization." Anything at all, even a random string or an emoji, can still be spelled out from small pieces or raw bytes. These pieces are tokens, and every major language model uses them.
See what the model sees
Below is the real tokenizer used by OpenAI's GPT-4o family of models, called o200k_base, running in your browser. Type anything, or try the presets. Other models (Claude, Gemini, Llama) use their own tokenizers, so their splits differ, but the patterns are the same.
A few things to notice, because each one explains real model behavior:
- The space belongs to the next word. " magic" with its leading space is one token. That's why "hello", " hello" and " Hello" are three different tokens with three different IDs (24912, 40617 and 32949). To the model, they're as different as three unrelated words until training teaches it that they're related.
- Capitals change everything. " Hello" is one token, " HELLO" is two (" HEL" + "LO"). Shouting costs more.
- Long rare words get chopped. " antidisestablishmentarianism" is six tokens: " ant", "idis", "est", "ablishment", "arian", "ism". The pieces don't always follow the word's real structure.
- Numbers are cut into chunks of up to three digits. "1234567" becomes "123", "456", "7". The model never sees a number as a quantity, only as a few chunks, which is one reason plain language models are clumsy at arithmetic.
Where the vocabulary comes from
Nobody writes the list of tokens by hand. It's learned from a big sample of text with an algorithm called byte-pair encoding (BPE), and the idea fits in one paragraph.
Start with the smallest possible pieces: the 256 possible bytes, which can spell any text in any language. Scan the sample text and find the pair of pieces that appears next to each other most often, maybe "t" followed by "h." Merge that pair into a new piece, "th," and add it to the vocabulary. Repeat: maybe "th" + "e" becomes "the," and later " " + "the" becomes " the." Keep merging until the vocabulary reaches the size you want.
The result is a vocabulary shaped by what's common in the sample. Frequent words become single tokens; rare words stay split into pieces. The size of the vocabulary is a design choice, and it has grown over the years:
| Tokenizer | Used by | Vocabulary size |
|---|---|---|
| r50k_base | GPT-2 and GPT-3 | about 50,000 tokens |
| cl100k_base | GPT-3.5 and GPT-4 | about 100,000 tokens |
| Llama 3 tokenizer | Meta’s Llama 3 models | about 128,000 tokens |
| o200k_base | GPT-4o and later OpenAI models | about 200,000 tokens |
A bigger vocabulary mostly helps languages other than English. Early tokenizers were trained on text that was mostly English, so other languages got chopped into many more pieces, which made them slower, more expensive and harder to learn. Here's the same sentence ("The weather is beautiful today, so we are going to the beach") in three generations of OpenAI tokenizers:
| Language | GPT-2/3 (r50k) | GPT-4 (cl100k) | GPT-4o (o200k) |
|---|---|---|---|
| English | 14 tokens | 14 tokens | 14 tokens |
| Spanish | 23 tokens | 15 tokens | 13 tokens |
| German | 23 tokens | 17 tokens | 14 tokens |
| Russian | 56 tokens | 27 tokens | 14 tokens |
| Hindi | 86 tokens | 57 tokens | 17 tokens |
Why tokens explain weird AI mistakes
Many famous chatbot failures stop being mysterious once you think in tokens.
Counting letters. Ask "How many r's are in strawberry?" and the word arrives as a single token, " strawberry," ID 101830. The model never sees s-t-r-a-w-b-e-r-r-y. It sees a number. To answer, it must have learned the spelling of that number indirectly, from text that happened to spell it out. That's why models long failed this kind of question while writing fluent essays. (Newer models usually get it right, often by spelling the word out letter by letter first, which turns each letter into its own token.)
Reversing, rhyming, counting words. Same problem. Any task about the letters inside a word is about information the tokenizer hid.
Arithmetic. "1234567 + 89" is a handful of chunks, and "456" in the middle is a token like any other. Models learn to do math on these chunks, but it's fragile, which is why serious AI apps hand arithmetic to a calculator tool.
Tokens are money and memory
Once you work with AI APIs, tokens are the unit of almost everything:
- Price. Providers charge per million tokens, with separate prices for input (what you send) and output (what the model writes). Output tokens usually cost several times more, because each one requires a full pass through the model.
- Context window. The limit on how much a model can see at once is measured in tokens: your instructions, the conversation, any documents and the answer all have to fit. Lesson 7 covers what happens when they don't.
- Speed. Models generate one token at a time, so a 500-token answer takes about five times longer than a 100-token one. Speed is quoted in tokens per second.
The rule of thumb for English, from OpenAI's own guidance, is that one token is about four characters, so 100 tokens is about 75 words. A 300-page book is around 120,000 tokens. Code, numbers, unusual formatting and many other languages use more tokens per word.
import tiktoken
enc = tiktoken.get_encoding("o200k_base") # the GPT-4o tokenizer
text = "How many r's are in strawberry?"
ids = enc.encode(text)
print(len(text), "characters ->", len(ids), "tokens")
print(ids)
print([enc.decode([i]) for i in ids])Exercise · about 5 minutes
Catch the tokenizer in the act
Open any chatbot (ChatGPT, Claude, Gemini) and run three small experiments:
- Ask: "Spell the word 'lollipop' backwards, letter by letter." Then ask it to reverse the word without spelling it first. Does one approach work better? In the GPT-4o tokenizer, " lollipop" is just two tokens, " l" and "ollipop."
- Ask: "What is 48,213 × 7,029?" Check the answer with a calculator. Then ask it to show its work step by step and compare.
- Paste the same paragraph in English and in another language you know into the tokenizer demo above. Which uses more tokens?
Write down one sentence for each: what did the model see, and how did that explain the result?
Quiz
1.What is a token?
2.Roughly how many tokens is 750 words of ordinary English text?
3.Why did chatbots long struggle to count the r’s in “strawberry”?
4.How is a tokenizer’s vocabulary usually created?
5.Which of these is NOT measured in tokens?
0 of 5 answered
Key takeaways
Models read tokens, not letters or words. A tokenizer splits text into pieces and maps each to a number.
In English, 1 token ≈ 4 characters ≈ ¾ of a word. Code, numbers and many other languages use more.
The vocabulary is learned with byte-pair encoding: frequent pieces get merged into single tokens.
Tokens explain odd failures: letters inside a token are invisible to the model, and numbers arrive in chunks.
Price, context limits and speed are all counted in tokens.
Go deeper
- OpenAI TokenizerOpenAI’s official page for counting tokens and seeing how text is split.
- OpenAI Help: What are tokens and how to count them?The source of the four-characters rule of thumb, with more examples.
- Andrej Karpathy: Let’s build the GPT TokenizerA two-hour session that builds byte-pair encoding from scratch in Python. For developers.
- tiktoken on GitHubOpenAI’s open-source tokenizer library used in the code above.
- Hugging Face LLM CourseFree course with a full chapter on tokenizers and how to train your own.