How do tokenizers work?

Almost every current model uses a variant of byte-pair encoding (BPE). The vocabulary is learned once, from a large amount of text: start from the 256 possible bytes, then repeatedly merge the most frequent pair of neighbouring pieces into a new token, until the vocabulary has the size the model makers want. Frequent words end up as single tokens, rare words stay split into smaller pieces.

Turning your text into tokens then happens in three steps:

  1. A pre-tokenizer splits the text into chunks with a fixed pattern: words, numbers (often in groups of at most three digits), punctuation and whitespace.
  2. Each chunk is merged into the longest pieces the learned merge rules allow.
  3. Each piece is replaced by its number in the vocabulary: the token ID.

Because the vocabulary starts from bytes, any text can be encoded: a character the model has never seen as a whole simply falls back to its bytes. Older SentencePiece-style tokenizers (Mistral 7B v0.3 in TokenCutter) work the same way but mark spaces with a special character and keep a separate set of byte tokens.

Every model family trains its own vocabulary with its own splitting rules, which is why the same text gives a different count per model. Vocabulary sizes in TokenCutter range from about 33,000 tokens (Mistral 7B v0.3) over 100,000 (GPT-4), 128,000 (Llama 3.1) and 200,000 (GPT-5, MiniMax M2.5) to about 248,000 (Qwen 3.8). A larger vocabulary usually means fewer tokens per text, especially outside English.

All questions