Works on this device
Token Counter
Paste a text to see its characters, words and bytes and an estimate of its tokens. For an exact count, open the tokenizer.json file of an open model from your own disk. Nothing is uploaded.
Your text
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your counts will show here
Type or paste some text, or choose Try an example.
Your counts
How it was worked out
How to use the token counter
- Type or paste your text, or open a text file. The counts update as you type.
- Read the two token estimates. They follow stated rules of thumb, so they are not the count of any model.
- To check a limit, type it in Your token limit, for example the context window given in your model’s documentation.
- For an exact count, choose Count tokens exactly with a tokenizer file and open the
tokenizer.jsonfile of the model. Many open models publish this file with their weights.
How the estimate works
A model does not read letters. It reads tokens: pieces of words, whole words, spaces with a word, or single bytes. Each model has its own tokenizer, so the same text gives different counts in different models.
This page gives two estimates from the rules of thumb that OpenAI gives for English text in its help article on tokens:
- From characters: characters ÷ 4, rounded up to a whole token.
- From words: words ÷ 0.75, rounded up. So 100 tokens are about 75 words.
- You can change both ratios under More options, for example to a ratio you measured for your own language and model.
- Program code, numbers, web addresses, rare words and many other languages need more tokens than these rules give. Chinese, Japanese and Korean text often needs one or more tokens for each character.
What is counted exactly
- Characters (Unicode code points): each code point counts once. The estimate from characters uses this count.
- Characters as a reader sees them: an emoji made of several parts, or a letter with an accent mark, is one character. Your browser’s Intl.Segmenter decides this.
- UTF-16 code units: the length of the text in JavaScript. Emoji and some rare characters take two units.
- Words: an unbroken run of characters with a letter or digit in it. Each Chinese character and Japanese kana is one word.
- Bytes in UTF-8: the size of the text in the most common file encoding. Byte-level tokenizers start from these bytes.
Exact counts with a tokenizer file
The second mode reads a tokenizer.json file of the Hugging Face tokenizers format for a byte-level BPE model (byte pair encoding on the UTF-8 bytes, as GPT-2, Llama 3 and many other open models use). It splits your text with the file’s own pattern and joins bytes with the file’s own merge list, so the count is the count of that file.
It also lists the tokens with their ID numbers, and says how many special tokens (such as a start token) the file’s template adds when a library encodes one text with special tokens.
A file that uses parts this page does not read is refused with a message that names the part. You then get no count, never a near count. Not read: other model types (WordPiece, Unigram, SentencePiece files with byte fallback), a space added before the text, and splitting patterns with forms such as possessive repeats or start and end marks.
No vocabulary is shipped with this page. The example file is a tiny made-up vocabulary for trying the tool, so its counts are much higher than a real model’s.
Worked example
The text Hello world, this is a test. has 28 characters and 6 words. The estimate from characters is 28 ÷ 4 = 7 tokens. The estimate from words is 6 ÷ 0.75 = 8 tokens. The tokenizer of a real model can give another number.
Limits you should know
- The estimates are rules of thumb for English. They are not the count of any model, and they can be far off for code, numbers or other languages.
- This page does not call any model or service. Prices per token are not shown here.
- Exact counts need the model’s own tokenizer.json. OpenAI publishes its tokenizers as tiktoken ranks files. This page does not read those files, because a ranks file does not hold its splitting pattern.
- The exact count covers the text you typed. Chat formats add their own tokens for each message, which differ by model and service.
- Texts of up to 1,000,000 characters and tokenizer files of up to 32 MB are read.