---
title: "How to count tokens in a prompt before sending it"
description: "Count the tokens in your prompt with the cl100k_base or o200k_base encoding, and see how that figure maps to a context window or API cost."
canonical: https://toolsugar.com/blog/how-to-count-tokens-for-ai-models
image: https://toolsugar.com/og.png
---

# How to count tokens in a prompt for GPT models

Updated 2026-11-09

To count tokens in a prompt, run the text through the same tokenizer the model uses. AI Token Counter does this in your browser with OpenAI's cl100k_base or o200k_base encoding, and it also shows characters and words. The count is exact for OpenAI models that use those encodings, and only an estimate for other vendors.

[Open AI Token Counter](https://toolsugar.com/tools/token-counter)

## Count tokens in four steps

The counts update as you type, so you can trim a prompt and watch the number fall.

1. Paste or type your prompt into the box.
2. Choose cl100k_base or o200k_base to match the model family.
3. Read the token, character and word counts.
4. Compare the token count with the model's context limit.

## What a token is

A token is a chunk of text the model reads as one unit. It may be a whole short word, part of a long word, or a single punctuation mark. Common words are often one token. Rare words, code and non-English text split into more pieces, so a short message can cost more than its word count suggests.

## Pick cl100k_base or o200k_base

cl100k_base belongs to GPT-4 and GPT-3.5. o200k_base belongs to GPT-4o. The same text can give different counts under each, so pick the one that matches the model you call.

The tokenizer data downloads the first time you use an encoding, which is why the first count takes a moment. After that it responds as you type.

## Use the count for limits and cost

A context window limits input and output together. Leave room for the reply. If your prompt already fills most of the window, shorten it before you send it.

API prices are quoted per token, so multiply your count by the rate for your model. Compare two phrasings by pasting each and reading the difference. The word and character counts help when a limit is set in words instead. For long documents, count a section at a time and add the results, so you can see which part of the text uses the most of your budget before you decide what to cut.

## Counts for Claude, Gemini and Llama

Other vendors use their own tokenizers. The figure here lands in the same range for plain English but can differ noticeably for code or other languages. Treat it as a rough guide and keep a margin below the limit. If a hard limit matters, such as a prompt that must fit a small context window, leave a generous buffer rather than aiming for the exact edge. Count the system prompt and any attached text too, since the model reads all of it.

## Questions

### How many words is a token?

There is no fixed ratio, but a common rule of thumb for English is about four characters, or three quarters of a word, per token. Code and other languages use more tokens per word. The count covers your input only, so it cannot predict how long the reply will be. Paste your own text to see the real figure.

### Does the token counter send my prompt anywhere?

No. Counting runs in your browser. Only the tokenizer data is downloaded.

### Why do the words and tokens differ so much?

Tokens follow the tokenizer's vocabulary, not spaces. Numbers, symbols and long compound words split into several tokens.

[Open AI Token Counter](https://toolsugar.com/tools/token-counter)

## Related guides

- [How to compare two texts and find the differences](https://toolsugar.com/blog/how-to-compare-two-text-files)
- [How to count words in a text](https://toolsugar.com/blog/how-to-count-words-in-a-text)
- [How to generate a strong random password](https://toolsugar.com/blog/how-to-make-a-strong-password)
- [How to format JSON online](https://toolsugar.com/blog/how-to-format-json)
