How tokenization works: BPE, WordPiece and special tokens
Before an LLM can read your text, a tokenizer cuts it into tokens and swaps each one for a number (its token ID) from a fixed vocabulary. Modern models use subword tokenization: common words stay whole, while rare words are split into familiar pieces, so the model never meets a word it can't handle.
Everyday analogy
Lego bricks. You don't need a special brick for every object: a few thousand standard bricks can build anything. Subword tokens are the standard bricks of language.
Example
"unbelievable" might become un + believ + able, three IDs such as 521, 7381 and 412. A brand-new word like "aifromzero" still works: it is simply split into smaller pieces the model already knows.
Why not just use whole words?
- The vocabulary would need millions of entries, and new words appear every day.
- Characters alone are too small: sentences become very long and slow to process.
- Subwords are the middle path: a vocabulary of roughly 30,000 to 200,000 pieces covers almost any text, in many languages.
Common tokenization methods
| Method | Used by | Key idea |
|---|---|---|
| BPE (byte pair encoding) | GPT models and many others | Start from characters or bytes and repeatedly merge the most frequent pair |
| WordPiece | BERT | Like BPE, but merges the pair that most improves the likelihood of the text |
| SentencePiece | T5, Llama 2 and many multilingual models | Works on raw text, treating spaces as normal symbols, so it suits any language |
| Unigram | Often inside SentencePiece | Starts with many pieces and keeps the set that best explains the text |
Special tokens
| Token | Purpose |
|---|---|
| <BOS> / <EOS> | Beginning and end of a sequence; the model stops writing when it produces end-of-sequence |
| <PAD> | Padding, so texts of different lengths can be processed together |
| <UNK> | Unknown token (rare with subword tokenizers) |
| [CLS] / [SEP] | BERT's classification and separator tokens |
| Chat markers | Hidden tokens that mark where the system prompt, your message and the reply start |
Why it matters to you: tokens decide cost, speed and limits. Many languages other than English need more tokens for the same sentence, so they cost more and fill the context window faster.
Try it yourself
About 10 minSee subword tokens for yourself
- Open a free online tokenizer (search OpenAI tokenizer).
- Paste: unbelievable, internationalization, your own name and a sentence in Hindi or Arabic.
- Note how each is split and count the tokens.
What you should see: Common words stay whole, rare words split into pieces, and non-English text usually needs more tokens.
Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.