Every time you send text to ChatGPT or the OpenAI API, the model doesn’t read words. It reads tokens. Tokens decide how much an API request costs and whether your prompt fits in the model’s memory. The OpenAI tokenizer is the tool that shows you exactly how your text gets split up.
This guide explains what tokens are, how to use the OpenAI tokenizer, how to count tokens in code, and a few practical tricks to use fewer of them.
What is the OpenAI tokenizer?
The OpenAI tokenizer is a free tool on the OpenAI platform website (platform.openai.com/tokenizer). You paste in any text and it shows:
- the total number of tokens
- the number of characters
- each token highlighted in a different colour, so you can see where the splits happen
- the token IDs, the numbers the model actually works with

The tool also states the same rule of thumb we use below: about four characters, or three-quarters of a word, per token for common English text.
Behind the scenes, OpenAI uses an open-source library called tiktoken to do this. Developers can use the same library in their own code to get exact counts.
What is a token?
A token is a chunk of text. It can be a whole word, part of a word, a space plus a word, a punctuation mark or a single character.
For example, a common word like great is usually one token. A long, rare word like antidisestablishmentarianism is split into several pieces. Even the space before a word is often part of the token, so " great" (with a space) and "great" can be different tokens.
The model sees your text as a list of numbers, one per token. That’s why token count, not word count, is what matters.
How many tokens is a word?
For normal English text, these rules of thumb are close enough for planning:
- 1 token ≈ 4 characters
- 1 token ≈ ¾ of a word
- 100 tokens ≈ 75 words
- 1 word ≈ 1.3 tokens
- 1,500 words ≈ 2,000 tokens
These are averages. The real count can be much higher for:
- code – brackets, symbols and indentation all use tokens
- JSON and long URLs
- numbers – long numbers are often split into several tokens
- emoji
- languages other than English, especially those that don’t use the Latin alphabet. The same sentence in Urdu, Hindi or Arabic can take noticeably more tokens than in English.
When the number really matters, don’t guess. Paste the text into the tokenizer.
How to use the OpenAI tokenizer (step by step)
- Go to the tokenizer page on the OpenAI platform website.
- Choose the model family or encoding you’re working with (newer models use a newer encoding, see below).
- Paste or type your text into the box.
- Read the token and character count under the box.
- Look at the coloured blocks to see how the text was split. Switch to “Token IDs” to see the numbers.
It’s a great way to understand why one prompt is “heavier” than another, and to spot things like unnecessary whitespace or huge pasted URLs.
Tokenizer encodings: why counts differ between models
Different OpenAI models use different encodings, which are basically different dictionaries of tokens. The same text can give a different count depending on the encoding.
| Encoding | Used by |
|---|---|
o200k_base |
GPT-4o and newer OpenAI models |
cl100k_base |
GPT-4 and GPT-3.5 Turbo |
p50k_base / r50k_base |
Older GPT-3 and Codex models |
Newer encodings have a bigger vocabulary, so they usually need fewer tokens for the same text, especially for non-English languages.
Also note: other companies’ models (such as Claude, Gemini or Llama) use their own tokenizers. An OpenAI token count is only exact for OpenAI models.
How to count tokens in Python with tiktoken
If you’re building with the API, count tokens in code before you send a request. Install the library:
pip install tiktoken
Then count tokens like this:
import tiktoken
enc = tiktoken.get_encoding("o200k_base")
text = "Tokens decide what your prompt costs."
tokens = enc.encode(text)
print(len(tokens)) # number of tokens
print(enc.decode(tokens)) # turns the tokens back into text
You can also let tiktoken pick the right encoding for a model with tiktoken.encoding_for_model("model-name"). If a brand-new model name isn’t recognised yet, update the library or use o200k_base directly.
For JavaScript, community libraries such as gpt-tokenizer offer the same encodings.
Why token count matters
1. Cost
The OpenAI API charges per token, usually as a price per million tokens. Input tokens (what you send) and output tokens (what the model writes) are priced separately, and output is normally more expensive. A shorter prompt and a tighter answer both save money.
2. Context window
Every model has a maximum number of tokens it can handle in one go, covering your instructions, any documents you include, the chat history and the answer. If you go over, older parts of the conversation are cut or the request fails.
3. Speed
More tokens take longer to process and generate. Lean prompts get faster replies.
4. Output limits
The answer itself has a token limit too. If a reply stops mid-sentence, it probably hit the maximum output length you set.
7 practical ways to use fewer tokens
- Cut the padding. “Please could you kindly help me to…” can just be “Summarise…”.
- Don’t paste what isn’t needed. Send the relevant section of a document, not the whole thing.
- Shorten URLs and remove tracking parameters. Long links eat tokens fast.
- Minify JSON by removing extra spaces and line breaks when you send data.
- Ask for a specific length, like “in 3 bullet points” or “under 100 words”.
- Summarise long chat history instead of sending every past message again.
- Reuse a fixed system prompt. Many APIs offer cheaper pricing for repeated (cached) input.
Frequently asked questions
Is the OpenAI tokenizer free?
Yes. Both the web tokenizer and the tiktoken library are free to use.
Does ChatGPT count tokens the same way as the API?
It uses the same kind of tokenizer, but in the ChatGPT app you don’t pay per token, so you rarely need to count. Token counts matter most when you use the API.
Are spaces and punctuation counted as tokens?
Yes. Spaces are usually attached to the following word, and punctuation marks are often separate tokens. Extra spaces and line breaks add up.
Why does my word counter give a different number?
Because a token isn’t a word. On average a word is a bit more than one token in English, and more than that in many other languages and in code.
Summary
The OpenAI tokenizer shows you how AI models really “see” your text. Use the rough rule of four characters or three-quarters of a word per token for quick estimates, and use the tokenizer or tiktoken when you need the exact number for cost or context limits.
Building with AI? See how the leading assistants compare: ChatGPT, Claude and more in the chatbots category, or read our list of the best free AI apps.