How Byte-Pair Encoding slices raw text into integer IDs, why non-Latin scripts pay a hidden token tax, and how token boundaries quietly affect caching.
Human characters
strawberry
Model input (integer IDs)
496 straw675 berry
01
Models never read the text you type
Ask a language model how many rs are in strawberry and smaller models stumble. Before your prompt touches a neural layer, a tokenizer slices it into opaque integer IDs like [496, 675].
Live Tokenizer Inspector
10 chars · 10 bytes → 2 tokens
What you type (characters)10 chars
strawberry
What the model receives (IDs)2 IDs
straw#496berry#675
[496, 675]
Spaces bind to the next word (·cat vs cat).
02
How Byte-Pair Encoding builds a vocabulary
Single-character tokens bloat sequence length and KV cache memory , while whole-word dictionaries cannot handle typos or code. Byte-Pair Encoding (BPE) merges frequent adjacent byte pairs into reusable subwords like ” the” and “ing”.
BPE Merge Stepper
Step 0 · Raw UTF-8 bytes79 / 79 tokens
5×low
2×lower
6×newest
3×widest
Learned MergesNext: e + s (9×)
Base 0..255 (UTF-8)256 bytes
Start with individual byte tokens. Count every adjacent pair across the training corpus.
03
The hidden multilingual token tax
Because training corpora skew toward English and code, non-Latin scripts like বাংলা, العربية, and हिन्दी expand into 3× to 5× more tokens, multiplying API cost and KV cache usage .
Multilingual Token Tax Comparator
English8 tokens (33 bytes · 1.0× English)
Hello, how are you feeling today?
Español10 tokens (28 bytes · 1.3× English)
Hola, ¿cómo te sientes hoy?
বাংলা (Bengali)28 tokens (73 bytes · 3.5× English)
হ্যালো, আজ আপনার কেমন লাগছে?
العربية (Arabic)19 tokens (41 bytes · 2.4× English)
مرحبا، كيف تشعر اليوم؟
हिन्दी (Hindi)31 tokens (93 bytes · 3.9× English)
नमस्ते, आज आप कैसा महसूस कर रहे हैं?
3 UTF-8 bytes per Bengali code point + fewer BPE merges inflate the count 3.5×.
04
How a single trailing space can break Prompt Caching
BPE merges greedily across string boundaries, so trailing whitespace at the end of a static prefix can shift token IDs and break Prompt Caching via the causal mask .
Prefix Boundary Shift Lab
DIVERGES AT TOKEN #7
Turn 1 · Cached Prefix"System: Be concise. Answer: 42"