Last verified

Tokens & usage AI glossary

What is a tokenizer?

A tokenizer is the component that converts text into a sequence of tokens from a model's fixed vocabulary and back again, deciding how many tokens — and so how much billed usage — a given text becomes.

At a glance

  • How it works: It matches the text against a vocabulary of common words and word pieces learned from training data, splitting rare words into several smaller pieces.
  • Why it matters: Each vendor has its own tokenizer, so the same prompt is a different number of tokens — and a different price — on each model.
  • What it costs: Nothing directly; but Anthropic documents that its newer tokenizer turns the same text into roughly 30 percent more tokens than earlier Claude models.
  • Related to: Token, input vs output tokens, context window, price per million tokens.

How a tokenizer works

A model's vocabulary is a fixed list of text pieces, each with a number. The tokenizer's job is to express any input as a sequence of those pieces. Frequent words become a single token; rarer words are assembled from several sub-word pieces; anything truly unusual falls back to individual bytes, so no text is ever unrepresentable.

Most current tokenizers use some form of byte-pair encoding, which builds the vocabulary by repeatedly merging the most frequent pairs of symbols in a training corpus. OpenAI's tiktoken README describes the result in three properties: it is reversible and lossless, so tokens convert back into the original text; it compresses the text; and it lets the model see common sub-words. The same process runs in reverse on output — the model produces token numbers and the tokenizer turns them back into text.

Why tokenizers disagree

A vocabulary reflects the data it was built from. A tokenizer trained on lots of code merges common code patterns into single tokens; one trained heavily on English prose does the same for English. Vendors also choose different vocabulary sizes. The result is that one paragraph can be a noticeably different token count on two models — and since the price is per token, a model with a lower list rate can still cost more for your text.

Tokenizers also change between model generations. Anthropic documents that Claude Opus 4.7 and later models use a newer tokenizer that produces approximately 30 percent more tokens for the same input than earlier models, and tells developers to recount prompts on the model they plan to use. A migration that keeps the per-token price flat can still raise the bill.

Content type changes the ratio as much as the vendor does. In our measurements, code and JSON pack noticeably fewer characters into each token than English prose on every tokenizer we could load — the table below shows the figures.

In our indexSame text, different token counts

Tokenizers measured 10
Words per token · prose 0.83–0.88
Characters per token · code 3.3 median
Characters per token · JSON 2.5 median
TokenizerProse chars/tokenCodeJSONWords/token
MiniMax5.333.332.690.881
OpenAI5.283.472.710.872
DeepSeek5.263.262.580.869
GLM (Zhipu)5.253.362.690.867
Qwen (Alibaba)5.233.192.240.863
Hunyuan (Tencent)5.233.342.490.863
Baichuan5.233.342.490.863
Doubao (ByteDance)5.203.162.220.858
Mistral5.093.282.420.840
Yi (01.AI)5.062.712.000.835

Measured on 2026-06-10 with each vendor's own published tokenizer on one fixed English corpus (436 words of prose plus code and JSON samples). Anthropic and Google publish no tokenizer, so they are not in this table. How we collect prices.

Counting when the tokenizer is not public

OpenAI publishes its tokenizer, and open-weight models ship theirs alongside the weights, so their counts can be reproduced exactly offline. Anthropic and Google do not publish theirs. For those models the vendor's counting endpoint is the authority: Anthropic's token-counting API is free and rate-limited by usage tier, and Google exposes count_tokens. Our token counter is exact for OpenAI's encoding and uses measured characters-per-token calibrations for the other vendors, which is an estimate and is labelled as one.

Frequently asked.

Short answers to the questions that come up next.

Q · 01 Do all LLMs use the same tokenizer? +
No. Each vendor trains its own, and a vendor can change it between model generations — Anthropic's newer tokenizer produces roughly 30 percent more tokens for the same text than its earlier one.
Q · 02 What tokenizer does OpenAI use? +
Byte-pair encodings published in the open-source tiktoken library; current models use o200k_base. OpenAI's own guide recommends selecting the encoding for your target model rather than assuming one.
Q · 03 Can I count Claude or Gemini tokens offline? +
Not exactly — neither tokenizer is published. Use Anthropic's token-counting endpoint or Google's count_tokens, or accept an estimate from a calibrated counter.
Q · 04 Why does code use more tokens than prose? +
Code is full of symbols, indentation and identifiers that tokenizers split into short pieces. In our measurements every tokenizer we tested fitted fewer characters per token into code and JSON than into English prose.