How Tokens Are Counted: BPE and the Hidden Token Tax
From characters to subwords, BPE merge rules, and why token costs vary by language, format, and context — plus the hidden tax of long prompts
THE QUESTION THIS PAGE ANSWERS
ANSWER FIRSTHow Tokens Are Counted: BPE and the Hidden Token Tax?
From characters to subwords, BPE merge rules, and why token costs vary by language, format, and context — plus the hidden tax of long prompts
Read cost as a shape, not a single number. Break a request into input, output, retries, tools, and waiting time. The shape of usage usually tells you which design choice is expensive and where a smaller change can help.
Measure one real request before you optimize an imagined average.
A cheaper call that quietly creates more retries, latency, or review work.
Early NLP swung between two poles. Word-level tokenization is semantically clear, but English's hundreds of thousands of words plus morphology (look / looks / looking / looked) explode the vocabulary—and still can't handle unseen words (the OOV problem). Character-level tokenization can split anything, but sequences get too long, each character carries little information, and inference is painfully inefficient.
Modern LLMs took the middle road—subword tokenization: keep common words as whole Tokens, split rare ones into meaningful pieces. Vocabularies stay between 32k and 200k—no explosion, yet everything is representable.
GPT-series models and Llama 3 all use BPE (Byte-Pair Encoding). The vocabulary isn't hand-crafted—it's “merged” out of the corpus:
Initialize: split the whole corpus into smallest units (for Unicode text, UTF-8 encode first and work in bytes).
Count frequencies: tally how often every adjacent byte pair appears in the corpus.
Merge the most frequent pair: e.g. if "u" and "g" often sit next to each other, merge them into a new symbol "ug" and add it to the vocabulary.
Iterate: repeat steps 2 and 3 until the vocabulary hits the target size—32,000 for Llama 2, 100,277 for GPT-4's cl100k_base.
At inference, look it up in reverse: a common word like "hug" is one Token; a rarer "bug" splits into ["b", "ug"]. The larger the vocabulary and the more “common” your text, the fewer Tokens—and the thinner the bill. That's why after GPT-4 moved to a 100k vocabulary, it specifically merged multi-level indent space sequences into single Tokens—code-generation efficiency jumped several times over.
Tokenizers learn merge rules from their training mix, so efficiency depends on the exact model, language, script, punctuation, and content domain. Some multilingual or non-Latin inputs use more Tokens than an English equivalent, while other tokenizers narrow the gap—the practical “Token tax” is a measurement problem, not a universal multiplier.
| Input | Example | Illustrative count | What to check | Why it varies |
|---|---|---|---|---|
| English prose | Donald John Trump | 3 | Words and punctuation | Common words may map directly to one Token |
| Chinese example | 唐纳德·约翰·特朗普 | 6 | Characters, punctuation, and tokenizer | Some characters or byte sequences may split more finely |
| Korean example | 도널드 존 트럼프 | 7 | Script coverage and spaces | Coverage differs across vocabularies and model families |
These are teaching examples, not a universal language price table. For the same meaning, token counts can diverge enough to affect API spend and effective context length, so benchmark representative prompts with the tokenizer and model you will actually deploy.
Pick a sentence and compare an English version with a Chinese-language example using rough teaching estimates. For exact splits, use the tokenizer for your target provider—for example, the OpenAI Tokenizer.
English has a visible guardrail: before BPE merges, text is pre-tokenized on spaces, so merges stay inside words and Token boundaries often match linguistic intuition. Chinese, Japanese, Thai, and other scripts may not use spaces between words, so a tokenizer relies more heavily on statistical co-occurrence and its training coverage. The result can be either compact or surprisingly fragmented—measure the target workload.
One often-cited Chinese example is an unusual string discussed as a “glitch Token”: it became a single token in one model vocabulary because of corpus frequency. The lesson is broader than that one string: tokenizer behavior is statistical, model-specific, and sometimes unintuitive.
Tokens are statistical subwords, not characters or words. BPE iteratively merges by corpus frequency; vocabulary size is a hyperparameter.
Token overhead is model-specific: language, script, formatting, and domain can change the count. Do not budget from English intuition alone.
Vocabulary size sets compression. cl100k_base's 100k vocab + space-merge optimizations are a direct reason GPT-4 is efficient on code. When picking models, tokenizer efficiency is a cost parameter too.
Source: Adapted from Part 1 “What Makes Up a Token” of the author's internal team share “AI Token Cost Engineering Strategies.” For BPE details see OpenAI Tokenizer and the open-source tiktoken library. To review the underlying principles of tokenization and vocabulary, revisit LLM Fundamentals · Vocabulary & Training.
The complete interaction cost of “From characters to subwords: balancing two extremes”
“Early NLP swung between two poles.” is a reminder that AI cost is not one price multiplied by one call. Input, output, retries, tools, waiting time, and human cleanup together decide what a task really costs.
Find what the bill repeats
The key variables behind “Modern LLMs took the middle road— subword tokenization : keep common words as whole Tokens, split rare ones into meaningful pieces.” are usually repeated context, oversized output, retries after failure, and calls that do not produce useful progress. Removing wasted Tokens can reduce cost, latency, and concurrency pressure at the same time.
A cheaper call can make the whole workflow more expensive
Start with “Vocabulary size sets compression.” and keep a small table for input, output, retries, tools, and human review. Compare quality before and after optimizing instead of looking at one price in isolation.
From “From characters to subwords: balancing two extremes” to “BPE: a vocabulary merged by frequency”
“From characters to subwords: balancing two extremes” grounds the problem in “Early NLP swung between two poles. Word-level tokenization is semantically clear, but English's hundreds of thousands of words plus morphology (look / looks / looking / looked) explode the vocabulary—and still…”. “BPE: a vocabulary merged by frequency” then moves it toward “GPT-series models and Llama 3 all use BPE (Byte-Pair Encoding) . The vocabulary isn't hand-crafted—it's “merged” out of the corpus”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.
Carry the judgment into the next situation
When analyzing cost, map the complete interaction first, then find repeated input, wasted output, and retries. A cheap individual call does not make the whole task cheap.
- “From characters to subwords: balancing two extremes”: Early NLP swung between two poles. Word-level tokenization is semantically clear, but English's hundreds of thousands of words plus morphology (look / looks / looking / looked) explode the vocabulary—and still…
- “BPE: a vocabulary merged by frequency”: GPT-series models and Llama 3 all use BPE (Byte-Pair Encoding) . The vocabulary isn't hand-crafted—it's “merged” out of the corpus
- “The closing point”: At inference, look it up in reverse: a common word like "hug" is one Token; a rarer "bug" splits into ["b", "ug"]. The larger the vocabulary and the more “common” your text, the fewer Tokens—and the thinner the…
The final “The closing point” brings the discussion to “At inference, look it up in reverse: a common word like "hug" is one Token; a rarer "bug" splits into ["b", "ug"]. The larger the vocabulary and the more “common” your text, the fewer Tokens—and the thinner the…”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.
I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.
After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.
When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.
No discussion on this article yet.