Flashcard: what is a token in LLM prompting and why does it matter for cost and context?
A token is the model's subword unit of text, roughly 0.75 English words, and it is the unit both API pricing and context-window limits are measured in.
Imagine a typewriter that can only press one of fifty thousand pre-cut stamps instead of individual letters. Each stamp is a token. Some stamps are whole common words like the or apple, others are partial pieces like tion or ing, and others are single characters for rare symbols. To write any sentence the typewriter has to find the right sequence of stamps. When you ask an LLM a question, the model first turns your text into a sequence of these stamps, then predicts the next stamp, then the next, then the next, until it stops. The price you pay is per stamp pressed, both for reading your input and writing its reply. The maximum number of stamps the typewriter can hold in memory at once is the context window.
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.
6 min: define tokens as subword units, give the 0.75-words conversion, separate input vs output pricing, explain the context-window budget, name the non-English and code penalty, point to tokenizer libraries.
Real products, models, and research that use this idea.
- Anthropic publishes a tokenizer endpoint so teams can count tokens exactly before sending a Claude Opus 4.7 request.
- OpenAI's tiktoken library is the standard way to count tokens locally for GPT-5.5 and GPT-4o prompts without making a network call.
- Google's Gemini 3.1 docs show that a 500-page novel fits in about 700K tokens, well inside the 1M context window.
- The Llama 3 family uses a 128K-token vocabulary via a tiktoken-style BPE tokenizer (Llama 2 used SentencePiece), roughly double the older vocab size, partly to improve tokenization efficiency on code and non-English text.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy are output tokens typically 3 to 5 times more expensive than input tokens?
QHow does prompt caching change the token economics of a multi-turn conversation?
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.
Estimating token count by multiplying word count by 1.0 and being surprised when a code-heavy or non-English prompt blows the context-window budget; tokens are not words.
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.