An LLM never sees raw text. So what does it actually process?
A token is the atomic unit an LLM reads and emits, usually a sub-word chunk of bytes mapped to an integer id by the tokenizer. The model only ever sees token ids, never raw text.
Imagine the language model only understands numbers, not letters. Before the model ever sees your message, a small program called the tokenizer chops the text into little pieces and looks up a number for each piece. Sometimes a piece is a whole short word like 'the'. Sometimes it is half of a long word, like 'token' plus 'ization'. Each piece gets its own number, and the model reads the list of numbers. When the model replies, it produces numbers, and the tokenizer turns them back into letters for you. The pieces are called tokens. They are not characters, they are not words, they sit somewhere in between. The bill you pay and the size of the conversation the model can remember are both measured in tokens, not in characters and not in words.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: state the byte-level definition, place the tokenizer as a separate component before and after the model, contrast tokens against characters and words, show that counts are tokenizer-specific, and link the concept to cost, context window, and latency.
Real products, models, and research that use this idea.
- OpenAI's tiktoken library exposes cl100k_base (GPT-4, GPT-3.5-turbo, text-embedding-ada-002) and o200k_base (GPT-4o, o1, o3, GPT-5, GPT-5.5), letting you count tokens locally before sending a request.
- Anthropic's Claude tokenizer is proprietary; the only reliable way to count tokens for Opus 4.7 or Sonnet 4.6 is the messages.count_tokens endpoint.
- Llama 3 and Llama 4 ship with a 128K-vocabulary tiktoken-style BPE tokenizer, replacing the 32K SentencePiece tokenizer used in Llama 2.
- Hugging Face's tokenizers library (Rust core, Python bindings) is the production standard for training and applying custom tokenizers.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does the same text produce different token counts under different tokenizers?
QIf the model only ever sees token ids, how does it handle a brand-new word it has never seen?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating tokens as words or as characters. Tokens are sub-word units defined by the tokenizer, and the same string can produce different token counts under different tokenizers.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.