What Is a Tokenizer? How AI Turns Your Text Into Numbers — A Simple Explanation
Every time you chat with an AI model, the very first thing that happens isn't "thinking" — it's translation. Your words get chopped up, converted to numbers, and only then does the model go to work. The piece of software that does this is called a tokenizer, and understanding it explains a surprising number of things: why AI miscounts letters, why pricing is per-token, why some languages cost more than others, and why your long documents eat your budget so fast.
The Simple Version
A tokenizer is a program that cuts text into small pieces called tokens and maps each piece to a number the model can process.
That's it. That's the core idea. Language models don't see letters or words — they see sequences of token IDs, like:
"The cat sat" → [464, 8418, 3332]The model was trained on millions of such sequences, so it has learned statistical patterns over tokens, never over raw text. Everything it "knows" about spelling, grammar, or your question lives in how tokens relate to each other.
Why Not Just Use Words? Or Letters?
Three options existed, and each has problems:
- Whole words: English alone has hundreds of thousands of word forms, plus new words appear constantly ("rizz," brand names, code identifiers). A fixed vocabulary can't keep up, and related words ("run," "running," "ran") would be treated as totally unrelated symbols.
- Single characters: A tiny vocabulary and no out-of-vocabulary problem — but your sequences become extremely long, and long sequences mean slow, expensive processing.
- Subwords (the winner): Common words stay whole ("the," " and"), while rare words get split into reusable chunks ("tokenization" → "token" + "ization"). Best of both worlds.
Nearly every modern model — GPT, Claude, Gemini, Llama, DeepSeek, Qwen — uses a subword tokenizer, typically a variant of an algorithm called Byte-Pair Encoding (BPE).
How Byte-Pair Encoding Actually Works
BPE starts with raw characters and greedily merges the most frequent adjacent pairs until it hits a target vocabulary size (often 100,000–250,000 tokens). Conceptually:
- Start with every character as its own token.
- Count all adjacent token pairs in a huge training corpus.
- Merge the most frequent pair into a new token ("t" + "h" → "th").
- Repeat thousands of times.
High-frequency text ends up as few tokens; rare or unusual text gets fragmented. This single fact explains a LOT of real-world behavior — more on that below.
Rules of Thumb: How Many Tokens Is My Text?
For modern English-focused tokenizers, useful approximations:
- 1 token ≈ 4 characters of English text
- 1 token ≈ ¾ of a word (so 100 words ≈ 133 tokens)
- 1 page of text ≈ 500–600 tokens
- Code often tokenizes worse than prose — expect more tokens per "word"
But watch out: tokenization is wildly uneven across languages and content types.
Why the Same Sentence Can Cost Different Amounts
Because BPE merges are learned from (mostly English) training data, text that looks like the training data compresses well, and text that doesn't... doesn't:
- Non-English languages often need 2–4× more tokens for the same meaning. A Spanish or Hindi sentence may split into many more subword fragments than its English equivalent.
- Unusual spelling, emojis, and rare Unicode characters can consume several tokens each.
- Numbers frequently get split digit-by-digit or in odd chunks — one reason models historically fumble arithmetic.
- Whitespace and indentation in code count as tokens, so deeply nested, heavily formatted code inflates fast.
The practical consequence: if you pay per token (and virtually everyone does), your language choice directly changes your bill. The same request answered in English might cost half of what it costs in German or Thai.
Three Famous Tokenizer Quirks Explained
"How many r's in strawberry?" For years, models got this wrong because "strawberry" may tokenize into chunks like "straw" + "berry," and the model never sees individual letters. (Modern models trained on character-level counting tasks mostly fixed this — by learning workarounds, not by seeing letters.)
Glitch tokens. Certain odd strings like " SolidGoldMagikarp" triggered bizarre behavior in early ChatGPT models — they were rare token IDs in the vocabulary that appeared in weird corners of the training data, so the model never learned what they meant.
Why models can't easily rhyme on demand or do acrostics. Wordplay requires letter-level awareness, but the model operates on tokens. Clever models compensate; the fundamental limitation is real.
Why Tokenizers Matter for Your Wallet
API pricing is quoted per million tokens, separately for input and output. Output tokens usually cost 3–5× more than input tokens, because generation is compute-heavier than reading.
Quick math: if a model costs $1 per million input tokens and you send a 10,000-token context on every request in a loop that runs 1,000 times a day, you're paying ~$10/day in input alone — even if each request generates only a 50-token answer. This is exactly why:
- Prompt caching (reusing tokens across requests at a discount) is such a big deal — see our guide on cutting AI costs with prompt caching.
- Model routing matters: sending a 40,000-token summarization job to a frontier flagship vs. a cheap mid-tier model can be a 20× cost difference for comparable quality.
- Context windows are token budgets — a "200K context" model fills up fast if you're stuffing entire codebases into it.
How to Check Token Counts Yourself
Most providers ship tokenizer tools, and OpenAI's tiktoken is the standard open-source option:
import tiktoken
enc = tiktoken.get_encoding("o200k_base") # modern GPT tokenizer
tokens = enc.encode("Tokenizers turn text into numbers.")
print(len(tokens)) # token count
print([enc.decode([t]) for t in tokens]) # see the individual piecesRun your real prompts through a tokenizer before estimating costs — "eyeballing it" is usually off by 20–40%, and rarely in your favor.
Quick Recap
- A tokenizer converts text into numbered chunks (tokens) that the model actually processes.
- Modern models use subword tokenization (usually BPE): common text stays whole, rare text gets fragmented.
- Token counts vary by language, code, and formatting — and since pricing is per token, this directly affects your costs.
- Knowing your token counts is step one of any cost optimization; caching and smart model routing are steps two and three.
If you're choosing models for a real workload, don't guess — compare real per-token pricing across providers on Qubax's model marketplace, and check the Qubax docs for integration guides.
FAQ
What is a token exactly?
A token is a chunk of text — usually a common word, part of a word, punctuation, or whitespace — that the model treats as a single unit. "unbelievable" might be one token or three ("un" + "believ" + "able"), depending on the tokenizer's vocabulary.
How many tokens are in 1000 words?
Roughly 1,300 tokens for typical English prose (about 1.3 tokens per word). Code, tables, and non-English text usually run higher.
Do all AI models use the same tokenizer?
No — each model family ships its own tokenizer with a different vocabulary. The same sentence can tokenize differently (and cost differently) on GPT, Claude, Gemini, or DeepSeek models.
Why does output cost more than input?
Generating tokens requires a full forward pass per token, while input tokens are processed in parallel. That's why output pricing is typically 3–5× higher across the market.
Can I reduce how many tokens I use?
Yes: trim system prompts, deduplicate context, use retrieval instead of pasting entire documents, enable prompt caching, and route simple tasks to cheaper models. Our cost-cutting tutorials on the Qubax blog walk through each technique with code.