← All news

News / Learn / LLM fundamentals

What are tokens and why do they matter?

You'll be able to explain what a token is, estimate how many a text uses, and see how tokens drive cost, speed and limits.

A token is a small chunk of text that a language model reads and writes. It is often a whole short word, part of a longer word, or a punctuation mark. The model never sees letters or sentences directly. It sees a sequence of tokens and predicts the next one.

Your bill, your speed and your limits all count tokens. A model charges for the tokens you send in and the tokens it returns. Longer prompts take more time to process. Every model also has a maximum number of tokens it can handle in one request. If you ignore tokens, your costs and failures will surprise you.

Before a model sees your text, a tokenizer splits it into tokens. The tokenizer uses a fixed vocabulary learned ahead of time. Common words such as "the" are usually one token. Rare words, names and code often split into several pieces. Spaces and capital letters can change the split, so the same word may tokenize differently in different positions.

Each model family has its own tokenizer. The same sentence can produce different token counts on different models. Never assume that one token equals one word. A rough rule for English prose is that one token is about three-quarters of a word. This rule breaks down for code, other languages and unusual text, so measure real inputs when accuracy matters.

Tokens affect three things. Cost usually scales with input and output tokens. Latency grows as the model processes more tokens and generates more of them. The context window sets a hard cap on the total tokens in one request, including your instructions, the conversation so far and the reply. Once you exceed that cap, the request fails or older content gets dropped.

When you design a product, count tokens for your typical inputs. Limit how much history and retrieved text you send. Ask for concise outputs when you do not need long ones. Track token usage per request so you can see where the money goes.

Count tokens with a tokenizer that matches your model. This example uses the tiktoken library. Your model provider may use a different tokenizer, so check its documentation.

import tiktoken

# Pick the encoding that matches your model family.
enc = tiktoken.get_encoding("cl100k_base")

text = "Tokens are the units a language model reads."
tokens = enc.encode(text)

print("Token count:", len(tokens))
print("Pieces:", [enc.decode([t]) for t in tokens])

A short sketch to show the idea. Check the official docs of the tool you use.

  • Assuming one token equals one word Measure with the real tokenizer. Code, names and non-English text often need more tokens per word than plain English.
  • Ignoring output tokens in cost estimates Estimate both input and output tokens. Long generated answers can cost more than the prompt that produced them.
  • Stuffing the context window Send only the history and documents the task needs. Trim or summarize older content so requests stay under the limit.
  • Using a tokenizer from a different model Use the tokenizer that belongs to your model. Counts from another tokenizer can be off enough to break your limits.

Read about context windows next. Then study how prompt caching and batch processing change the cost of repeated token use. Learn how to count tokens in your own stack before you set budgets.

Is a token the same as a character?

No. A token is usually several characters, though it can be one character or a short word. Token counts run lower than character counts for normal English.

Why does my text use more tokens than I expected?

Rare words, numbers, code, emoji and non-English scripts often split into many small tokens. Hidden system instructions and formatting also add tokens.

Do spaces count as tokens?

Often a space is attached to the start of the next word rather than counted alone. The exact split depends on the tokenizer.

Can two models give different token counts for the same text?

Yes. Each model family uses its own tokenizer and vocabulary, so the same text can split differently.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.