OpenAI Token Counter – Free

This AI token counter runs your text through the real cl100k_base or o200k_base vocabulary and reports the exact token count, plus characters and UTF-8 bytes. The text is tokenized in your browser.

How to use the AI token counter tool

  1. Pick a vocabulary under Tokenizer: cl100k_base for GPT-4 and GPT-3.5 Turbo, o200k_base for GPT-4o and newer models.
  2. Paste your prompt, document or code into the Text box, or select Example to load a short sample.
  3. Select Count tokens to run the tokenizer on the text.
  4. Read the four lines in the Result box: Tokens, Tokenizer, Characters and UTF-8 bytes.
  5. Select Copy to copy the four counts.

How a token counter turns text into tokens

Language models read tokens, numbered pieces of text taken from a fixed vocabulary. OpenAI builds its vocabularies with byte pair encoding: training starts from the 256 possible byte values and repeatedly merges the most frequent neighboring pair into a new entry, until the vocabulary reaches its target size.

To tokenize, the encoder first cuts the text into rough chunks such as words, numbers and punctuation runs, converts each chunk to UTF-8 bytes, and then applies the learned merges in rank order. Common words end up as one token, often with the leading space attached. Rare words, identifiers and non-Latin scripts break into several pieces. This tool runs that algorithm with the published rank files, so the number is a count, not an estimate.

Worked example: one sentence, token by token

The sentence below is 34 characters long and becomes 7 tokens in both vocabularies. Tokenization is split into two pieces, while each following word keeps its leading space inside the token. The vocabularies diverge on other input: the five Chinese characters 你好,世界 take 6 tokens in cl100k_base and 3 in o200k_base.

Text:   Tokenization is not word counting.
Pieces: [Token][ization][ is][ not][ word][ counting][.]

Tokens: 7
Tokenizer: o200k_base
Characters: 34
UTF-8 bytes: 34

cl100k_base or o200k_base: which tokenizer to pick

The right choice depends on the model that will receive the text. Counting with the wrong vocabulary usually gives a close number for English prose and a noticeably different one for CJK text and other non-Latin scripts.

  • cl100k_base has roughly 100,000 entries. GPT-4, GPT-4 Turbo, GPT-3.5 Turbo and the text-embedding-3 and ada-002 embedding models use it.
  • o200k_base has roughly 200,000 entries and often needs fewer tokens for non-English text. GPT-4o, GPT-4o mini and the o-series reasoning models use it.
  • Models from other vendors use their own tokenizers, so neither option is exact for them.

What the count includes and what it leaves out

The tool counts the raw text you paste and nothing else. A chat request adds a few formatting tokens around every message, and tool definitions, images and the model's reply are counted on top. Leave some headroom when you compare the number with a context window or a max token setting.

Special markers such as <|endoftext|> are encoded as ordinary characters here, so that string counts as 7 tokens instead of 1. The Characters line counts Unicode code points, so a single-code-point emoji is one character even though it occupies four UTF-8 bytes. Input is limited to 500,000 UTF-16 code units.

Frequently asked questions

How many tokens is 1,000 words?

For ordinary English prose, 1,000 words come to roughly 1,300 to 1,400 tokens, because a token averages about four characters or three quarters of a word. Code, URLs, numbers and non-English text use more tokens per word.

Is my prompt sent to OpenAI or to a server?

No. The tokenizer and its vocabulary file are loaded into the page on first use, and the counting happens in JavaScript on your device. The text you paste is not transmitted to any API.

Why does the count differ from the usage in my API response?

The API counts the whole request: message wrappers, system prompt, function or tool schemas and any images. This tool counts only the text in the box.

Does whitespace count as tokens?

Yes. A single space before a word is normally merged into that word's token, but indentation, blank lines and trailing spaces produce tokens of their own. Minifying JSON or trimming repeated blank lines is a simple way to shorten a prompt.

Can I count tokens for Claude, Gemini or Llama with this tool?

Only approximately. Those models use different vocabularies, so their counts for the same text will not match cl100k_base or o200k_base. Use the result as a rough check only.

Related tools