What a token is
A language model never sees letters or words. Before any text reaches it, a tokenizer cuts the text into pieces taken from a fixed vocabulary and replaces each piece with its number in that vocabulary. The model reads a sequence of those numbers and writes its answer as numbers too, which the tokenizer turns back into text.
How2437␣do466␣I314␣reset13259␣my616␣password9206?30Vocabularies today hold from tens of thousands to a few hundred thousand entries. Frequent words get their own entry, usually with the space before them attached. Less frequent words are spelled out of smaller pieces: an unusual product name might become four or five tokens.
How tokenizers are built: byte-pair encoding
Most current tokenizers use a form of byte-pair encoding (BPE), adapted for language models by Sennrich, Haddow and Birch. The vocabulary is learned from a large sample of text before the model itself is trained:
- Start from the smallest units: single characters, or the 256 possible bytes.
- Count every pair of neighbouring units in the sample and find the most frequent pair.
- Merge that pair into a new unit and add it to the vocabulary.
- Repeat until the vocabulary reaches its target size.
The vocabulary ends up spending its entries on whatever was common in that sample. Byte-level versions start from bytes rather than characters, so any input — any language, emoji or stray symbol — can still be encoded, just less efficiently when it is unusual.
- The sample contains “walking”, “talking” and “making” many times. At first each is split into characters:
w a l k i n g. ifollowed bynis the most frequent pair, so it becomes one unit:w a l k in g.- Now
infollowed bygis the most frequent pair:w a l k ing. - After tens of thousands of merges a frequent word like “walking” is likely to be a single token, while a rare one like “unwalkable” is still built from several pieces.
Why the same text gives different counts
| Kind of text | Typical behaviour |
|---|---|
| Everyday English | About 4 characters, or ¾ of a word, per token |
| Numbers, IDs and dates | Split into short chunks: 2024-03-17 can take five or more tokens |
| Code and JSON | Brackets, quotation marks and indentation all cost tokens |
| Other languages | Often more tokens for the same meaning; one 2023 study measured differences of up to 15 times for the same translated text |
| Rare names and jargon | Split into several sub-word pieces |
Each model family trains its own tokenizer, so a document that is 1,000 tokens for one model might be 1,150 for another. Any count made with a different tokenizer, or estimated from the number of characters, is an approximation.
Why it matters for training
- Cost. Training is billed per token processed, and use per input and output token.
- Limits. The context window and the per-example training limit are counted in tokens, not in messages or words.
- Odd weaknesses. A model sees “strawberry” as a few tokens, not ten letters, which is why counting letters or reversing a word is surprisingly hard for it.
Common mistakes
- Treating a token as a word when estimating cost or limits.
- Assuming a count made for one model applies to another.
- Budgeting for non-English data with English characters-per-token ratios.
- Forgetting that formatting — JSON, markup, long IDs — consumes tokens too.
References and further reading
External sources open in a new tab.
- 01Neural Machine Translation of Rare Words with Subword UnitsSennrich, Haddow & Birch, 2016 · arXiv · arxiv.orgThe paper that introduced BPE tokenization to NLP.
- 02Byte-Pair Encoding tokenizationHugging Face LLM Course · huggingface.coBPE training worked through step by step, with code.
- 03Language Model Tokenizers Introduce Unfairness Between LanguagesPetrov et al., 2023 · arXiv · arxiv.orgHow much more the same content costs in some languages.
- 04openai/tiktokenOpenAI · GitHub · github.comA widely used BPE tokenizer you can run to count tokens yourself.
- 05Understand and count tokensGemini API docs · ai.google.devAnother provider's explanation of tokens and how to count them.