What the AI Token Calculator does
The AI Token Calculator is a free, privacy-first tool that tells you exactly how many tokens a piece of text, a source file or an image will consume when sent to a large language model (LLM). Tokens are the currency of modern AI: every request to GPT-4o, GPT-4, Claude, Gemini, Llama or any other model is measured, billed and capped in tokens rather than words. If you have ever been surprised by an API invoice, hit a mysterious “context length exceeded” error, or tried to squeeze a long document into a prompt, this calculator gives you the precise numbers you need before you spend a cent. Alongside the token total it also reports characters, characters without spaces, words, lines and sentences, so you get a complete picture of your content in one place.
How to use it
Getting a count takes just a few seconds:
- Add your content. Paste or type directly into the text box, click Upload file to pick a document, or simply drag and drop a file or image anywhere onto the input box.
- Choose a tokenizer that matches the model you are targeting — for example o200k_base for GPT-4o and the o-series, or cl100k_base for GPT-4 and GPT-3.5.
- Read your results instantly. The token count and every other metric update live as you type or as soon as a file finishes loading — there is no “calculate” button to press.
- Press Clear when you are done to wipe the content from memory. Nothing persists between sessions and nothing is ever saved.
Because everything runs locally, you can safely paste confidential prompts, proprietary code, contracts or customer data without it ever leaving your machine.
How it works
Language models do not read raw characters — they read tokens produced by a tokenizer. Most modern models use a technique called byte-pair encoding (BPE), which starts from individual bytes and repeatedly merges the most frequent adjacent pairs into larger units. The result is a vocabulary in which common words become a single token, rarer words split into several sub-word pieces, and spaces and punctuation are represented explicitly. This is why “dog” might be one token while “antidisestablishmentarianism” becomes many, and why the same word can tokenize differently depending on whether it is preceded by a space.
This calculator loads OpenAI’s actual open-source tokenizers in your browser and runs them over your text, so the count for OpenAI models is exact rather than estimated. When you pick the generic option, or if the tokenizer library cannot be loaded, it falls back to the well-known heuristic of roughly four characters per token and marks the figure with a “≈” to show it is an approximation. All of this happens client-side in JavaScript; your data never touches a server, which is what makes the tool both fast and private.
The tokenizer options explained
- o200k_base — the newest OpenAI tokenizer, used by GPT-4o, GPT-4o mini, GPT-4.1 and the o1 / o3 reasoning models. It has a ~200k-token vocabulary and is more efficient on code and non-English text, so the same passage often uses fewer tokens than with older encoders.
- cl100k_base — the tokenizer behind GPT-4, GPT-4 Turbo, GPT-3.5 Turbo and the text-embedding-3 models. Choose this whenever you are budgeting for those specific models.
- Generic estimate (~4 chars/token) — a fast, model-agnostic approximation for providers whose tokenizers are not bundled here, such as Anthropic Claude, Google Gemini or Meta Llama. Treat it as a close ballpark; real counts on those platforms will be within a small margin.
Supported file types
You can drag in or upload files up to 10 MB. There are two categories:
Text & code (counted as text tokens):
.txt, .text, .md, .markdown, .mdx, .rst, .csv, .tsv, .json, .jsonl, .ndjson, .yaml, .yml, .toml, .ini, .env, .xml, .html, .htm, .css, .scss, .js, .mjs, .cjs, .jsx, .ts, .tsx, .py, .rb, .php, .java, .kt, .c, .h, .cpp, .cc, .cs, .go, .rs, .swift, .sh, .bash, .zsh, .sql, .log, .tex, .srt, .vtt — and most other UTF-8 text formats.
Images (measured as vision tokens):
.png, .jpg, .jpeg, .webp, .gif, .bmp
Binary formats such as PDF, DOCX, XLSX or ZIP are not decoded here because their tokenization depends on how a given model extracts text from them; export or copy the underlying text first for an accurate count.
How image (vision) tokens are counted
Multimodal models like GPT-4o charge for images in tokens too. When you drop in a PNG, JPG, WebP or GIF, the calculator reads the image’s pixel dimensions locally and applies OpenAI’s high-detail tiling formula: the image is first scaled to fit inside a 2048×2048 box, then its shortest side is scaled to 768 pixels, and the result is divided into 512-pixel tiles. Each tile costs 170 tokens on top of an 85-token base, so a small image might be a few hundred tokens while a large, detailed one can be well over a thousand. Low-detail mode, by contrast, is a flat 85 tokens regardless of size. The image itself is never uploaded — only its width and height are used.
How it helps you
- Estimate cost before you call the API. Multiply your input and expected output tokens by a model’s per-token price — you can compare those prices across providers on our models directory — to forecast spend accurately.
- Stay inside the context window. Every model has a maximum number of tokens it can handle in one request. Counting first prevents truncated prompts and “context length exceeded” errors.
- Optimise prompts and RAG chunks. See instantly how trimming instructions, compressing examples or resizing retrieved passages changes your token footprint.
- Budget fine-tuning and embeddings. Training files and embedding jobs are billed per token, so a quick count keeps large datasets predictable.
- Protect sensitive data. Because the tool is fully client-side, you can measure private or regulated content without any compliance risk.
Tokens vs. words vs. characters
A common rule of thumb for English is that one token is about four characters or roughly 0.75 words, so 1,000 tokens is around 750 words and a single page of prose is often 500–650 tokens. These ratios shift with language, formatting and code: dense punctuation, emoji, non-Latin scripts and long identifiers all push the token count up relative to the word count. That is exactly why an exact tokenizer beats guessing — and why this page shows characters, words and tokens side by side so you can see the relationship for your own content.
Frequently asked questions
What is a token in AI models?
A token is the basic unit a language model reads and generates. Tokens are chunks of text produced by a tokenizer — often a whole short word, a word fragment, a space, or a punctuation mark. As a rough guide, one English token is about four characters or roughly three-quarters of a word, so 1,000 tokens is around 750 words. Models bill you and enforce context limits in tokens, not words, which is why counting them accurately matters.
How accurate is this token counter?
For OpenAI models the count is exact: we run the same byte-pair-encoding (BPE) tokenizers OpenAI uses — o200k_base for GPT-4o, GPT-4.1 and the o-series, and cl100k_base for GPT-4, GPT-3.5 Turbo and the v3 embeddings. For other providers such as Anthropic, Google or Meta, tokenization differs slightly, so use the generic estimate as a close approximation.
Is my text or file uploaded anywhere?
No. All counting happens entirely inside your browser using JavaScript. Your pasted text, uploaded documents and images are never transmitted to our servers, never logged, and never stored. Closing the tab or pressing Clear removes everything from memory.
Which file types are supported?
Plain-text and code files (.txt, .md, .csv, .json, .yaml, .xml, .html, .js, .ts, .py, .java, .go, .rb, .php, .sql, .log and many more) are counted as text. Image files (.png, .jpg, .jpeg, .webp, .gif) are measured as vision tokens using the image-tiling formula that GPT-4o-class models use.
How are image (vision) tokens calculated?
For images we estimate high-detail vision tokens the way OpenAI GPT-4o does: the image is scaled to fit within 2048×2048, then its shortest side is scaled to 768 pixels, and the result is divided into 512-pixel tiles. Each tile costs 170 tokens plus an 85-token base. Low-detail mode is a flat 85 tokens regardless of size.