Kolkata ·  
AI engineering
foundations
deep · 5 min

Tokenization

How text becomes the integer tokens a model actually sees, and why that explains odd behavior and pricing.

updated 23 Sept 2026

Type this into a model:

Tokenization is

What arrives at the model isn't letters. With GPT-2's tokenizer it's three numbers: 30642, 1634, 318. The first two together spell "Tokenization". The third is " is", space included. Those three numbers are everything the model gets to see.

When we say a model predicts "the next token" (next-token prediction), this is the thing it's predicting: one entry from a fixed list. So let's follow our little string through, and then look at the odd things that happen because of it.

The trip in

First the text becomes bytes, stored as UTF-8. An English letter is 1 byte. Greek, Cyrillic, Arabic and Hebrew letters take 2. Chinese, Japanese and Korean characters take 3.

Then the tokenizer groups those bytes into chunks it learned from a big pile of text. The usual way of learning the chunks is byte-pair encoding, BPE. Each chunk has an id, which is just its position in the tokenizer's list, the vocabulary.

Inside the model, each id picks one row out of a big table. That row of numbers, an embedding, is what the network actually works with. On the way out it all runs backwards: the model produces ids and the tokenizer turns them back into text, exactly, with nothing lost.

Why chunks?

Why not one token per letter? You could do it. A toy model trained on Shakespeare needs only 65 characters. But every text gets very long, and the model's work grows with the number of tokens.

One token per word, then? Now any word the tokenizer never saw (a typo, a new product name, a word in another language) has no id at all.

Chunks sit in between. Common words get one token. Rarer words get split into common pieces: "encoding" usually becomes "encod" + "ing". And since the list starts with all 256 possible byte values, any text at all can be encoded.

On OpenAI's tokenizers a token averages about 4 bytes, so for English, about 4 characters. Hold onto that loosely. We're about to see how far off it can be.

Notice the " is" in our example had its space attached. Spaces aren't thrown away; they're usually glued to the front of the next word. In GPT-2, " the" is 262 and " at" is 379. So "the" at the start of a line and " the" after a space are different tokens to the model. (That's also why a stray space at the end of a prompt can make a model act oddly. The space is real text that has to become a token.)

The model can't see letters

Lots of "the model is dumb" moments are really "the model can't see letters" moments.

Ask a model to reverse "encoding". It gets two ids, "encod" and "ing". It doesn't get eight letters, and nothing in an id shows which letters are inside it. Spelling and string tricks are hard for the same reason.

Numbers are worse. With GPT-2's tokenizer:

NumberTokens
127127
677 6 + 77
804 8 + 04
127512 + 75

To write "804", the model has to produce " 8" and then "04". Those clumps have nothing to do with place value, which is how anyone actually adds. The same goes for code and formats: GPT-2 had more trouble with Python than it should have, and YAML tends to go better than JSON, both down to how their characters get chunked.

And the chunk list is shaped by whatever text it was learned from. In GPT-2, the internet string BuyableInstoreAndOnline is one token, while the Bulgarian word for "why" takes six.

Same words, different bill

That last example points at something bigger. Take the same text, translated, and count tokens with GPT-4's tokenizer:

APIs bill per token. So processing German or Italian costs about 50% more than the same content in English, and the worst languages over 12 times more. It's slower too, since more tokens take longer. And the context window holds less: in Burmese you fit less than a tenth of what fits in English.

Can't you just train the tokenizer on more languages? People have, and the gap stays. Working on raw bytes doesn't fix it either, because some scripts need 3 bytes for a character that takes 1 in English. A fix might not cost much, though. One estimate: giving two thirds of GPT-4's vocabulary to other languages would make English text only about 10% longer.

Every model counts differently

The chunk list is learned, and each model family learns its own. OpenAI names theirs: cl100k_base for GPT-4, o200k_base for GPT-4o. The same text gives a different count on each.

How you count differs too. OpenAI publishes its tokenizers as an open library, tiktoken, so you can count on your own machine. Anthropic doesn't publish Claude's. You send your request to a free counting endpoint, and the number you get back is an estimate that can be off a little.

Counts change even inside one family. Claude got a new tokenizer with Opus 4.7. When Sonnet 5 came out on it, the same text came to about 30% more tokens than on Sonnet 4.6, depending on the content. The price per token dropped at the same time, from $3 to $2 per million input tokens and from $15 to $10 per million output. So you pay less per token, for more tokens, and the request doesn't get cheaper by the full third. The same context window holds less text, and a max_tokens limit that fit a full answer before can now cut it short.

What's actually in a request

Here's one more thing that surprises people. A few small requests to Claude Opus 5.5:

RequestTokens
A one-line system prompt and "Hello, Claude"14
The same, plus one tool definition403
A short question about an image1,028
A short question about a PDF2,188

The words you type are often the smallest part. Tool definitions, images and documents take up most of the count, and that's what you pay for (token pricing).

So count tokens on the model you'll actually use, with your users' languages and your real tools in the request, and count again when you change models. Most of the examples on this page are old: the number splits come from GPT-2, and the language numbers were measured on 2023 tokenizers. Newer tokenizers split things differently, and as far as we know nobody has published the language comparison for them yet. That one you'd have to measure yourself.

Further reading