Learn · Guide
Tokens and Tokenization
Why language models read text as tokens, and how that shapes cost, limits and output quality.
Models do not see words
A language model receives numbers, not characters or words. Tokenization is the step that converts text into a sequence of integer IDs. A tokenizer uses a vocabulary learned from training data, so common strings become single tokens while rare strings are split into pieces. In English, a token is often a word or part of a word. In Chinese and Japanese, it may be a character or a short phrase. The exact mapping depends on the model, which is why the same sentence can produce different token counts in different systems.
Why tokens matter in practice
Token count determines how much of a conversation fits in the context window, and it usually determines API price. A prompt that looks short to a person can be expensive if it contains many rare names, code snippets, or mixed scripts. Output limits are expressed in tokens too. If you ask for a long answer and set a low output limit, the response stops mid-sentence even though it looks short on screen. Learning to estimate tokens is therefore a practical skill, not a theoretical curiosity.
Subwords and rare strings
Subword tokenization solves a problem: a vocabulary cannot contain every possible word. By splitting unfamiliar words into known pieces, the model can still process them. The side effect is that rare words consume more tokens. A long URL, a hashed identifier, or a line of base64 may fragment into dozens of tokens. This also explains why models sometimes struggle with character-level tasks such as reversing a string or counting letters: they never see individual characters as clean units.
Multilingual text
Non-English text is often less efficient in token terms. A single Chinese character may be one token or several, depending on the tokenizer, and Japanese text with mixed kanji and kana can fragment unpredictably. If you are building a multilingual product, measure token counts in every language you support rather than assuming translation preserves length. Budget your context window for the worst case, not the English case.
A useful workflow
When a result is unexpectedly bad or expensive, inspect the tokenization first. Remove boilerplate, shorten repeated instructions, and replace long IDs with shorter references where possible. Put stable instructions in a reusable template so you do not pay to rewrite them in every request. If a task depends on exact character manipulation, use a normal program for that step and let the model handle the language part. The prompt templates tool is a convenient place to keep and refine those reusable instructions.