LLM Tokenizer Explained 2026
Models read tokens, not words. The same paragraph can cost nearly twice as many tokens on a different model, and your bill and context limit scale with it. Here is how tokenizers split text, how to count tokens yourself, and which habits quietly burn money.
📜 Table of Contents
LLM Tokenizer Explained 2026: Why Your Prompt Costs More Than You Think
Models read tokens, not words. The same paragraph can cost nearly twice as many tokens on a different model, and your bill and context limit scale with it.
What a Tokenizer Does
A tokenizer maps text to integer IDs. The dominant algorithm is BPE (byte pair encoding): start from raw bytes, repeatedly merge the most frequent adjacent pairs, and end up with a vocabulary of tens to hundreds of thousands of entries. The model never sees characters, only IDs.
Three consequences matter for cost:
- Frequent words already merged in the vocabulary cost one token. Rare words fall back to subwords or single bytes.
- Chinese is 3 UTF-8 bytes per character. Chinese-first models usually map common characters to one token; many Western models split rare characters, names and mixed-script strings into 2-4 tokens.
- Long digit strings get shredded, which is a large part of why models are bad at arithmetic.
Vocabularies differ per model. OpenAI publishes tiktoken vocabularies (e.g. o200k_base); Claude, Gemini and most Chinese providers do not. Token counts are not portable across models - always measure with the model you will actually call.
Anchors You Can Check Yourself
| Content | Rough conversion | Note |
|---|---|---|
| English prose | 1 token ≈ 4 chars ≈ 0.75 words | about 1.3 tokens per word |
| Chinese | 1 character ≈ 1-1.7 tokens | vocabulary dependent |
| Code / JSON | 0.3-0.5 tokens per character | indentation is billed |
| Emoji | 2-4 tokens each | 4-byte UTF-8, often split |
| Long numbers | ~1 token per 3-4 digits | do not expect digit accuracy |
Treat these as estimates; measure once with the real tokenizer and the guessing stops.
Counting Tokens: Three Routes
# OpenAI
import tiktoken
enc = tiktoken.get_encoding("o200k_base")
print(len(enc.encode("count this prompt")))
# Open models
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct")
print(len(tok("count this prompt")["input_ids"]))
No-code route: OpenAI's tokenizer page shows the exact split, which makes it obvious which segment is being shredded.
Context Windows in Words
| Window | English | Chinese |
|---|---|---|
| 32K | ~24k words | ~26k chars |
| 128K | ~96k words | ~106k chars |
| 200K | ~150k words | ~166k chars |
| 1M | ~750k words | ~833k chars |
Capacity is not usable quality: information in the middle of a long context is often ignored. See the context-window guide.
Four Habits That Cut Cost Immediately
- Trim history - keep the last few turns verbatim, summarise the rest. Agents resend history every turn.
- Compress JSON - drop indentation, shorten keys, send only the fields downstream uses.
- Cache the static prefix - system prompt, tool definitions and corpus background unchanged at the front. Cached-input discounts differ per provider; check official pricing.
- Cap output - set
max_tokensand ask for conclusions only. Output usually costs several times input.
One multiplication people miss: a 2,000-token system prompt at 10,000 requests per day is 20 million input tokens per day, for text that never changes.
FAQ
Same text, different token count? Something dynamic is in the prompt: timestamps, random IDs, retrieval order, tool order. Move variable parts to the end.
Is Chinese more expensive? Depends on the vocabulary. Measure the same text with each model's tokenizer instead of converting heuristics.
How do I count tokens for a local model? Use that model's AutoTokenizer or llama.cpp's tokenize interface.
Why is output priced higher? Generation is sequential, one token at a time. Multiples vary by provider; see official pricing pages.
Note: vocabularies and prices change with releases; verify against official documentation.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.