A token counter shows how many tokens a piece of text uses, which is what language models read and what their limits and prices are based on. People use one to estimate what a prompt will cost, to check that a document fits a context window, to compare JSON with a more compact format, and to trim a prompt that has grown too long. Everything here runs in your browser, so your text never leaves your browser. You choose the model, and the page tells you plainly whether the count is exact or an estimate.
What is a token?
A token is a piece of text that a language model reads as one unit. It can be a whole word, part of a word, a space plus a word, a punctuation mark or a single byte of an unusual character. Models read, price and limit text by tokens, not by words or characters, so the count matters.
Take the sentence "The quick brown fox jumps over the lazy dog." It has 9 words and 44 characters, and it comes to 10 tokens in o200k_base. A token is not a word and not a character, and the relationship changes with the language, the formatting and the encoding.
How do I count tokens for GPT models?
Paste your text, keep GPT-4o selected, and the count appears as you type. Tick other models to compare them side by side. GPT-4o, GPT-4.1, GPT-5 and the o-series use the o200k_base encoding, and GPT-4 and GPT-3.5 use cl100k_base. Both counts are exact, computed in your browser.
How to use this token counter
- Add your text: paste it, upload a .txt, .md, .json, .csv or .log file, drop a file on the box, or load the sample.
- Pick a model: the summary and the token view follow the model you choose, and each model is labelled Exact or Estimate.
- Compare models: tick more rows in the table to count them too. A tokenizer file is downloaded only when a ticked or chosen model needs it.
- Check cost and context: edit the price per million input tokens for any row, and pick a context size to see how much of it your text uses.
- See the tokens: tick Show tokens to list the first 500 tokens with their ids, then copy the results or download them as a .json file.
The JSON Formatter tidies a payload before you count it, the JSON Sorter puts keys in order, and the JSON Schema Validator checks its shape. To see how a large array becomes one record per line, try the JSON to JSONL converter, and read JSON Lines explained and What is JSON if the formats are new to you. To compare JSON with a compact text format for prompts, try the JSON to TOON converter.
Is the token count for Claude and Gemini exact?
No. Claude and Gemini use their own tokenizers, and this page runs OpenAI encodings only, so their counts use o200k_base as a proxy and are labelled Estimate. They can differ by 30% or more, especially for code, non-English text and newer Claude models. Use the vendor's token counter when you need an exact number.
Anthropic documents that newer Claude models count the same text differently from older ones, which is one reason a proxy cannot be exact. Estimate rows show the label next to the number, never in a footnote.
Why do JSON and code use more tokens than plain text?
Structure costs tokens. In our test, compact JSON of one small record came to 23 tokens in o200k_base while the same facts as a sentence took 16, and indenting the JSON raised it to 45. Quotes, braces, colons, repeated key names and indentation each add tokens that prose does not need.
Code behaves the same way: operators, brackets, indentation and long identifiers split into many small tokens. If tokens matter for your prompt, remove indentation, shorten repeated keys, or send one record per line instead of one large array.
What do the real numbers look like?
The table below was produced by running this page's own counting code on each text. The text sits in the first column, and the two columns on the right are its token counts under each encoding.
Sample texts and their token counts
| Text | Characters | o200k_base | cl100k_base |
A plain sentence: The quick brown fox jumps over the lazy dog. | 44 | 10 | 10 |
The same facts as the JSON, written as a sentence: User 1042 is Ada, tagged admin and beta, and is active. | 55 | 16 | 16 |
Compact JSON: {"user":{"id":1042,"name":"Ada","tags":["admin","beta"],"active":true}} | 71 | 23 | 22 |
| The same JSON, indented with 2 spaces | 122 | 45 | 45 |
Japanese: 今日はいい天気ですね。 | 11 | 6 | 11 |
Hindi: नमस्ते दुनिया | 13 | 5 | 13 |
| 200 line breaks | 200 | 13 | 7 |
Text containing a special-token string: hi <|endoftext|> there | 22 | 9 | 8 |
The indented JSON used in the fourth row
{
"user": {
"id": 1042,
"name": "Ada",
"tags": [
"admin",
"beta"
],
"active": true
}
}
Token counting gotchas
Tokens are not words or characters
The Hindi greeting in the table has 13 characters and 2 words but 5 tokens in o200k_base. The compact JSON line has 71 characters and 1 word, because it contains no spaces, yet it takes 23 tokens. Neither words nor characters predict the count, which is why the counter works on tokens.
The same text counts differently under different encodings
The Japanese sentence takes 6 tokens in o200k_base and 11 in cl100k_base, a difference of 5 for 11 characters. The newer encoding is not always smaller: the compact JSON takes 23 in o200k_base and 22 in cl100k_base. Always count with the encoding your model uses.
JSON and code cost more than prose
The indented JSON takes 45 tokens against 23 for the compact form, a difference of +22 from whitespace alone, and 16 for the sentence that holds the same facts. Minify JSON before it goes into a prompt when the layout does not matter.
Whitespace and line breaks count
Spaces and line breaks are tokens or parts of tokens. 200 blank lines come to 13 tokens in o200k_base and 7 in cl100k_base, so trailing blank lines are not free.
Special-token text is counted as ordinary text
Some strings, such as the end-of-text marker, are special tokens in the OpenAI encodings and make many tokenizers stop with an error. This counter treats them as ordinary text, so the line in the last table row counts 9 tokens in o200k_base and 8 in cl100k_base instead of failing. A real API may treat such a string differently.
Exact for OpenAI encodings, an estimate for the rest
The two encodings here are the ones OpenAI models use, so those counts match what the models read. Claude and Gemini tokenize differently and this page does not run their tokenizers, so their rows are proxies. Their vendors offer their own counters, and those are the numbers to trust.
Chat messages add overhead
The count is for your text only. Chat APIs wrap each message with role markers and other formatting tokens, and tool definitions and system prompts add more, so the total a request uses is higher than the number shown here.
What are the limits of this counter?
Live counting pauses above about 1 MB, and you press Count instead. Text above about 5 MB shows a warning, and text above 50 MB is refused. A count that takes too long stops, and a Cancel button appears after one second. The token view lists the first 500 tokens only, and the file size shown while a tokenizer loads is the real size of that file.