esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Is a Token?

What a token is, why models split text into pieces instead of whole words, and why token counts drive cost, explained simply for your AI interview.

In short

A token is a small piece of text that a model reads and writes, such as a whole word, part of a word or a punctuation mark. Models use tokens because a fixed word list cannot cover every new name, typo or product code.

11 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A token is a small piece of text that a model reads and writes. It can be a whole word, part of a word, or a punctuation mark. A fixed word list can't cover every new name, typo or product code, so text is split into smaller known pieces the model can still work with. Tokens also set the usage and cost of each request, so I measure them with the model's own counter.

What is a token, in plain words?

A language model reads text as tokens, not as letters or whole sentences. A tokenizer, the program that cuts text up, turns your message into a row of tokens before the model sees it. Each token has a number, and the model works with those numbers.

Think of a bank's cheque clearing system. It takes a cheque apart into the sort code, the account number and the amount, and handles each field it already knows. A support assistant does the same with words: it reads reblocked as the known parts re, block and ed.

Key words

Token
A small piece of text the model reads, such as a word, part of a word or a punctuation mark.
Tokenizer
The program that cuts text into tokens before the model sees it.
Vocabulary
The fixed list of pieces the tokenizer knows.
Unknown token
In older word-list systems, a stand-in for a word the list cannot match. Its meaning is lost.

Why not just use whole words?

Whole words look simple, but they break in real use. A chat assistant meets names, typos, product codes and slang every day. A word list built last year has no entry for them, so a model that relies on whole words cannot work with them.

Two ways to read a new word

New word in a chat

reblocked is not in the word list

Old word list

Unknown token

meaning lost from the message

Known pieces

Split into known parts

re + block + ed, parts kept

Model

sees only the tokens it is given

Reply

wrong if the meaning is missing

  1. 1The word is missing from the list, so it becomes an unknown token.
  2. 2The tokenizer breaks it into pieces it does know.
  3. 3The model gets a blank where the meaning should be.
  4. 4The model gets three known pieces it can work with.
  5. 5The reply is right only when the meaning reached the model.
A new word in a chat either misses a fixed word list, or gets split into known pieces the model can work with. The reply can only be right if the meaning reached the model.
  • Whole words

    Short, but brittle

    Every name, typo and product code needs its own entry. In a fixed list, anything missing loses its meaning.

  • Characters

    Never unknown, but long

    Every letter becomes a token. A long message turns into many small pieces, which uses more of the limit and costs more.

  • Subword pieces

    The working middle

    Common words stay whole, and rare words split into known parts. The model still gets parts it can work with.

A fixed word list is a closed vocabulary: anything not on it is out. An open vocabulary means the words can be anything, so the system has to cope with new ones. The two quotes below describe this same problem, one from a research paper and one from a model maker's glossary.

  • “Neural machine translation (NMT) models typically operate with a fixed vocabulary, but translation is an open-vocabulary problem.”

    Sennrich and co-authors (2015)

  • “Larger tokens improve data efficiency during inference and pretraining (and are used when possible), whereas smaller tokens allow a model to handle uncommon or never-before-seen words.”

    Anthropic

How does a tokenizer split text?

Many modern tokenizers learn their pieces from a large sample of text, and keep the pieces that show up often. A 2015 paper built its splitting on byte pair encoding, a compression method. Common words end up as one token, and rare words stay as several smaller pieces.

Here is a small, runnable demo. The piece list is typed by hand and the matcher is a simple longest-match rule, so it is not real byte pair encoding. Many real tokenizers learn their pieces from text. The word list comes from a bank's support logs, and the customer's message contains a word the list never saw.

Python
# A bank's support bot. Its word list came from last year's chats,
# so new words, like product names and typos, are missing from it.
WORDS = {"my", "card", "was", "blocked", "after", "the", "payment", "failed"}
PIECES = ["my", "card", "was", "after", "the", "payment", "fail", "failed", "re", "block", "ed", "pay", "ment"]

def whole_words(text):
    # A word not in the list becomes an unknown token, and its meaning is lost.
    return [w if w in WORDS else "<unk>" for w in text.lower().split()]

def pieces(text):
    out = []
    for word in text.lower().split():
        while word:
            options = [p for p in PIECES if word.startswith(p)] or [word[0]]
            best = max(options, key=len)  # the longest known piece wins
            out.append(best)
            word = word[len(best):]
    return out

msg = "My card was reblocked after the payment failed"
print(whole_words(msg))
print(pieces(msg))
print(len(whole_words(msg)), len(pieces(msg)))

Output

['my', 'card', 'was', '<unk>', 'after', 'the', 'payment', 'failed']
['my', 'card', 'was', 're', 'block', 'ed', 'after', 'the', 'payment', 'failed']
8 10

The whole-word version gave one unknown token for reblocked, so the bot lost the key word. The piece version gave three known pieces for it and used two more tokens in total. That is the trade-off: more tokens, but the model gets parts it can work with.

Tip

In an interview, name the trade-off first: pieces cost more tokens, while a fixed word list fails on anything new.

Why do token counts change by language and model?

The same text can make a different number of tokens in two places. OpenAI's guide says a word can split differently depending on its spelling, its capitals and the words around it. It also says other languages can have different relationships between characters, words and tokens. Anthropic says the number of characters a token stands for depends on the model and the language. Its glossary, checked in November 2026, also notes that its newer tokenizer (Claude 4.7 and later) produces about 30 percent more tokens for the same text.

From a message to a bill

Customer message

the text the bot must read

Tokenizer

cuts the text into known pieces

Token count

depends on language and model

Usage and cost

limits and cost follow the count

  1. 1The whole message goes to the tokenizer first.
  2. 2Each piece it produces becomes one token in the count.
  3. 3The count sets the usage, the limits and the cost of the request.
A message goes to the tokenizer, each piece is counted, and the count sets what the request uses, what it can fit and what it costs. Measure real messages with the model's own counter.

Worked example. A bank's support assistant handles about 40,000 chats a month, and an average chat uses about 1,200 tokens. Both figures are made up for this example. If customers write in a language that splits into more tokens, the same chats cost more, because the input and output counts go up. So the team counts real chats first and sets the budget from those counts, not from a word count.

How would you cut a support bot's token bill?

Start by measuring. Log the input and output token counts for real chats, then find the long parts: a pasted policy document, a long chat history, or a tool that returns a whole file.

  1. 1

    Measure

    Count tokens on real chats, not on the test prompts the team wrote.

  2. 2

    Trim the input

    Send only the policy section that matches the question, and keep the history short.

  3. 3

    Limit the reply

    Ask for a short answer when a short one is enough. Output tokens count toward usage too.

What does the interviewer want to hear?

A strong answer covers

  • A token is a piece of text: a word, part of a word or punctuation.
  • Why not whole words: a fixed list misses new and rare words, and pieces give the model parts it can work with.
  • The trade-off: subword pieces mean more tokens, but the model still has parts to work with.
  • Token counts change with language and model, so measure real text.
  • Tokens set usage, limits and cost, so budget from real counts.

Common traps

  • Trap"A token is always one word."

    BetterA token can be a word, part of a word or a punctuation mark. Count with the model's own tool.

  • Trap"Tokens and words are the same, so I can budget by word count."

    BetterA word count is only a rough guide for English. Measure real text before you set a budget.

  • Trap"Whole words are simpler, so we should use them."

    BetterSimple until a new name arrives. Subword pieces give the model parts it can work with for words the list never saw.

Can you spot the wrong assumption?

Spot the wrong line

This is from a bank's chatbot budget note. Which line is wrong?

Quick check

A chatbot meets a new product name that its word list never saw. What should happen?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q004How do tokenizers like BPE, WordPiece and SentencePiece work?11 min
  2. Q005Why do token counts differ across languages and models?10 min
  3. Q006What is an embedding?11 min
  4. Q008What is a context window?11 min
  5. Q030Why are input and output tokens priced differently?11 min
  6. Q040How do you estimate the token count of a text?10 min

Learn it in depth

Last updated on 26 November 2026

Running an AI assistant and watching its token bill?

I design and build AI products and agents, the interface and the system behind them. Book a short call and tell me what you need to build.