Special Topic · Token Cost Engineering: Make the Numbers Work

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 FIRST

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

DECISION RULE

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.

TRY NEXT

Measure one real request before you optimize an imagined average.

WATCH FOR

A cheaper call that quietly creates more retries, latency, or review work.

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 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.

Evolution of tokenization from character-level and word-level to subword-level
A Token isn't simply a character or a word—it's a “subword” built from statistical patterns. By balancing vocabulary size and semantic expression, BPE became the foundation of modern LLM training and inference. (Figure: from the author's original share deck)
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:

1

Initialize: split the whole corpus into smallest units (for Unicode text, UTF-8 encode first and work in bytes).

2

Count frequencies: tally how often every adjacent byte pair appears in the corpus.

3

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.

4

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.

BPE training and inference process
Left: during BPE training, iteratively merge the highest-frequency byte pairs to build the vocabulary. Right: at inference, pre-tokenize by regex, then greedily merge by merge priority. (Figure: from the author's original share deck)
The hidden “Token tax”: language and format change the bill

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.

InputExampleIllustrative countWhat to checkWhy it varies
English proseDonald John Trump3Words and punctuationCommon words may map directly to one Token
Chinese example唐纳德·约翰·特朗普6Characters, punctuation, and tokenizerSome characters or byte sequences may split more finely
Korean example도널드 존 트럼프7Script coverage and spacesCoverage 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.

Token-count differences across languages
Token boundaries depend on the model's vocabulary and training mix: compare representative inputs instead of assuming one language-wide multiplier. (Figure: from the author's original share deck)
Interactive Demo · Same meaning, different tokenizer bill

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.

Click any sentence above to start.

A script-specific pitfall: text without spaces

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.

Space pre-tokenization compared with scripts that rely more on co-occurrence
Space-delimited languages and scripts without spaces expose different tokenizer trade-offs; both should be checked on real product prompts. (Figure: from the author's original share deck)
Key Takeaways

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.

Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing How Tokens Are Counted: BPE and the Hidden Token Tax Token Cost Engineering: Make the Numbers Work
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

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.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

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.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

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.

ARTICLE DISCUSSION4 helpful