# What are LLM tokens? How models count text, with examples

URL: https://sdclabs.com/glossary/llm-tokens/

> LLM tokens are the pieces of text a model reads and writes. How tokenizers split words, what counts in an API request, and a runnable tiktoken example.

# What are tokens in LLMs?

[Mykhailo Poliarush](https://sdclabs.com/author/poliarush/) 2026-12-03

Definition

LLM tokens are the units of text a language model reads and writes: whole words, parts of words, punctuation or single characters, each mapped to a number by a tokenizer. Providers bill, rate-limit and size context windows in tokens. For English, OpenAI and Google estimate about 4 characters per token, but counts vary by model and language.

## How does text become tokens?

A tokenizer cuts text into pieces from a fixed vocabulary and maps each piece to a number. Google's Gemini docs put it simply: a token can be a single character like z or a whole word like cat, and long words are broken into several tokens. The README of OpenAI's [tiktoken](https://github.com/openai/tiktoken) library explains the method it uses, byte pair encoding (BPE), with the example of "encoding" split into "encod" and "ing".

Providers publish rules of thumb for English text. They are estimates, and each provider says so:

| Provider | Rule of thumb | Caveat on the same page |
|---|---|---|
| OpenAI | 1 token is about 4 characters, or about three-quarters of a word; 100 tokens are about 75 words | Other languages can have different ratios, and the same text can give different counts by model and encoding |
| Google (Gemini) | A token is about 4 characters; 100 tokens are about 60 to 80 English words | Images, video and audio are tokenized too |
| Anthropic (Claude) | No ratio on its token counting page | Claude 4.7 and later use a newer tokenizer, so counts from older models do not carry over |

Sources: OpenAI's help article [Understanding and counting tokens](https://help.openai.com/en/articles/4936856-understanding-and-counting-tokens) , Google's [Understand and count tokens](https://aistudio.google.com/docs/tokens) and Anthropic's [token counting docs](https://platform.claude.com/docs/en/build-with-claude/token-counting) . The size of the Claude tokenizer change, and what it does to price comparisons, is covered on our [inference cost](https://sdclabs.com/glossary/inference-cost/) page.

Two details from the OpenAI article explain many surprises. Spaces change how text is split, and a word can become different tokens depending on its spelling, capitalization and the text around it. Token IDs also depend on the encoding, so an example ID from one model does not apply to every other.

## What counts as a token in an API request?

More than the text you typed. The OpenAI article lists four kinds:

- **Input tokens:** everything sent in the request, also called prompt tokens.
- **Output tokens:** what the model generates, called completion tokens in Chat Completions.
- **Cached input tokens:** input reused through prompt caching, which can be priced differently.
- **Reasoning tokens:** internal steps of a reasoning model. You never see them as answer text, but they count toward output usage and are billed as output.

The same article adds that message structure, tools, schemas, images and files can all add to the input count beyond the plain text. [Gemini's docs](https://aistudio.google.com/docs/tokens) give numbers for images: an image of 384 pixels or less in both dimensions counts as 258 tokens, and larger images are cut into 768x768 pixel tiles of 258 tokens each. Gemini's usage object reports separate totals for input, output, thinking, cached content and tool use.

As the OpenAI article puts it, a short visible answer can use more tokens than its displayed text suggests.

## Example: the same text under two encodings

This script uses tiktoken to count tokens for four strings under two OpenAI encodings, cl100k_base and o200k_base, then shows how small changes to one word change its tokens.

# How the same text splits into tokens under two OpenAI encodings (tiktoken). # Plain text only: API requests add tokens for roles, tools and images on top. import tiktoken encodings = [tiktoken.get_encoding(name) for name in ("cl100k_base", "o200k_base")] samples = { "English": "Please refund the duplicate charge on order 1182.", "Polish": "Proszę zwrócić podwójną opłatę za zamówienie 1182.", "JSON": '{"order_id": "A-1182", "amount_eur": 120}', "Date": "2026-11-19", } print(f"{'sample':8} {'chars':>5} {'words':>5} {'cl100k':>6} {'o200k':>6}") for label, text in samples.items(): counts = [len(enc.encode(text)) for enc in encodings] print(f"{label:8} {len(text):>5} {len(text.split()):>5} {counts[0]:>6} {counts[1]:>6}") o200k = encodings[1] for word in ["refund", " refund", "Refund", "REFUND", "refunded"]: ids = o200k.encode(word) pieces = [o200k.decode([i]) for i in ids] print(f"{word!r:12} -> ids {ids} pieces {pieces}")
Output with tiktoken 0.14.0 on Python 3.11:

sample chars words cl100k o200k English 49 8 11 11 Polish 50 7 24 22 JSON 41 4 18 18 Date 10 1 6 6 'refund' -> ids [148482] pieces ['refund'] ' refund' -> ids [18376] pieces [' refund'] 'Refund' -> ids [70182] pieces ['Refund'] 'REFUND' -> ids [10060, 21592] pieces ['REF', 'UND'] 'refunded' -> ids [1874, 87591] pieces ['ref', 'unded']
What the numbers show:

- **Language changes the count.** The Polish sentence has about the same number of characters as the English one and needs 22 to 24 tokens instead of 11. On these two strings, o200k_base uses two fewer tokens than cl100k_base on Polish and the same number on English.
- **Structured text is dense.** The JSON object averages about 2.3 characters per token, and the date about 1.7, well below the 4-character rule of thumb.
- **A leading space makes a different token.** "refund" and " refund" are both one token, with different IDs.
- **Case and suffixes split words.** "REFUND" and "refunded" each become two pieces.

The counts are for plain text with two OpenAI encodings. Other models tokenize differently, so use each provider's own counter for its numbers.

## How do you count tokens exactly?

Use the provider's counter on the full request, not a local estimate:

| Provider | How to count before sending | What the docs warn |
|---|---|---|
| OpenAI | Input token counting for the Responses API (POST /v1/responses/input_tokens) | The count includes formatting tokens for message roles and boundaries; the article says counting is free and does not use your inference quota |
| Anthropic | The messages/count_tokens endpoint, with the same inputs as a message | The count is an estimate and can differ from actual usage by a small amount; server tools (except the advisor tool), the MCP connector, and images or documents passed by URL or file return an error |
| Google | count_tokens with the request input | It counts the input only; output and thinking appear in the response's usage |

After the call, read the usage field of every response: it reports what the request actually used. Anthropic notes that counts may include tokens it adds for system optimizations, and that you are not billed for those.

Tokens matter beyond price. They also set how much fits in one request, which is the [context window](https://sdclabs.com/glossary/context-window/) .

## What should you check before budgeting by tokens?

1. **Measure on your own text.** Run a sample of real prompts, in every language you serve, through each candidate model's counter.
1. **Count the whole request.** Tool definitions, schemas, images and conversation history are input tokens too.
1. **Budget output separately.** Reasoning and thinking tokens are output, and they can dwarf the visible answer.
1. **Recount when the model changes.** A new tokenizer can change the count, even for identical prompts.
1. **Track tokens per task, not per call.** An agent that needs three extra calls costs more than its per-call count suggests.

In our [AI agent benchmarking](https://sdclabs.com/services/ai-agent-benchmarking/) work, we record tokens, tool calls and wall-clock time per completed task, so you can price an agent before it scales.

## Sources

1. [Understanding and counting tokens](https://help.openai.com/en/articles/4936856-understanding-and-counting-tokens) , OpenAI Help Center, 2026-11-05
1. [Understand and count tokens](https://aistudio.google.com/docs/tokens) , Google AI Studio (Gemini API docs), 2026-11
1. [Token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) , Anthropic (Claude API docs), 2026-11
1. [tiktoken](https://github.com/openai/tiktoken) , OpenAI (GitHub), 2026-11-08

## Frequently asked questions

### How many tokens is 1,000 words?

About 1,300 by OpenAI's rule of thumb that 100 tokens are about 75 words, or roughly 1,250 to 1,700 by Google's estimate of 60 to 80 English words per 100 tokens. Other languages, code and data can differ, so count a sample of your own text.

### What is a tokenizer?

The component that turns text into token IDs before the model sees it, and turns generated IDs back into text. Tokenizers differ between models and encodings, which is why the same prompt can get different counts on different models.

### Do spaces and punctuation count as tokens?

They take part in tokenization. A punctuation mark can be its own token, and a leading space can be part of the next word's token: in our test, "refund" and " refund" were different tokens.

### Why does the same prompt cost more in another language?

Because it can need more tokens. In our tiktoken test, a Polish sentence of about the same length as an English one took about twice as many tokens, and tokens are what you pay for.

Services

- [Generative AI](https://sdclabs.com/services/generative-ai/)
- [AI agent benchmarking](https://sdclabs.com/services/ai-agent-benchmarking/)

Read next

- [The state of AI engineering in 2026](https://sdclabs.com/blog/state-of-ai-engineering-2026/)
- [Generative AI fails after the demo, not before it](https://sdclabs.com/blog/generative-ai-production/)

Related terms

- [Context window](https://sdclabs.com/glossary/context-window/)
- [Inference cost](https://sdclabs.com/glossary/inference-cost/)
- [Embeddings](https://sdclabs.com/glossary/embeddings/)

[Mykhailo Poliarush](https://sdclabs.com/author/poliarush/) Founder and CEOLeads SDCLabs, an AI development company founded in Krakow in 2011.[LinkedIn](https://www.linkedin.com/in/poliarush/) [GitHub](https://github.com/poliarush)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
