Case & CodeA FIELD GUIDE TO AI
Start learning
Beginner

Tokenizer

Also: tokenizers, tokenization

In plain words

The tool that chops text into tokens and gives each piece a number. Different models chop differently.

A sentence, cut into pieces

“The contract is signed.”

becomes

The␣contract␣is␣signed.

“unbelievable”

becomes

unbelievable

Each piece is a token. The model never sees your words; it sees these pieces, each with its own number. Short common words are one piece; long or unusual words are cut into several. A page of text is roughly 500 to 700 tokens.

The fuller definition

A tokenizer converts text into tokens and numerical identifiers, and usually supports converting those identifiers back into text.

Go deeper

How it fits together
  1. Characters

    Original text

  2. Segmentation

    Find vocabulary pieces

  3. Encoding

    Map pieces to token IDs

A simplified relationship, not a screenshot or a complete design.

A concrete example

A model's tokenizer may treat a leading space as part of the following token.

The distinction that matters

A word-count estimate is not an exact token count. Use the tokenizer for the intended model when precision matters.

Try it: words become pieces, and pieces have IDs

Choose an example and compare its coloured pieces. These results were computed in advance with OpenAI's tiktoken library using its o200k_base encoding, the one used by OpenAI's recent models. They are exact for that encoding; Claude, Gemini, and open-weight models each use their own tokenizer, so the pieces and counts differ.

The contract is signed.
TheID 976
␠contractID 6698
␠isID 382
␠signedID 14759
.ID 13

5 tokens · 23 characters in this example

The ␠ marker makes a space visible. The numeric ID identifies a vocabulary entry; its magnitude is not a measure of meaning. A model converts these IDs into representations for computation.

Why a small edit can matter

Changing a word or punctuation can change the token boundaries and count. A model's context limit and API usage can depend on tokens, rather than the number of words a person sees.

What this does not show

This visual covers text tokenization. Images, audio, message formatting, and model-specific accounting can add other units or overhead. It is not a billing estimator.

Tokenizer implementation and encoding documentation

Related terms

Where it is taught

What actually happens when you ask AI a question?

Source and further reading

Google · Machine Learning Glossary

The definition and example are written for this library. The link gives background, official documentation or legal authority as labelled. Legal scope depends on the jurisdiction and current text; product features depend on release and settings.

Lessons, terms, practical guides and sources ESC