Skip to content
StackSignal

Prompt engineering

Prompt token estimator & context checker

Enter prompt text or word counts to estimate tokens across GPT-4o, Claude 3.5 Sonnet, and Gemini 1.5, check context window limits, and project execution costs.

Last updated October 24, 2026

How LLM Tokenization and Context Economics Work

In large language models (LLMs) such as OpenAI GPT-4o, Anthropic Claude 3.5 Sonnet, and Google Gemini 1.5, text is not processed character-by-character or word-by-word. Instead, foundation models process text through a specialized mathematical dictionary known as a tokenizer (such as Byte-Pair Encoding or SentencePiece).

Understanding tokenization mechanics is fundamental to budgeting API costs, architecting prompt templates, and avoiding context window truncation in production applications.

The Word-to-Token Ratio

As a baseline standard for English text:

  • 1 word ≈ 1.33 tokens
  • 1,000 tokens ≈ 750 words
  • 1 token ≈ 4 characters of English text

However, token efficiency varies significantly based on payload structure:

  • Standard English Prose: High token efficiency. Common words like "the", "market", and "calculate" map to a single token ID.
  • Code (Python, JavaScript, SQL): Lower token efficiency. Indentation spaces, brackets, punctuation, and camelCase naming conventions generate higher token counts (1.5 to 2.0 tokens per word equivalent).
  • JSON & Structured Data: Structural overhead (quotes, braces, keys) multiplies token consumption. Repeated schema keys across array items rapidly consume context.
  • Non-Latin Scripts: Languages using Arabic, Cyrillic, or CJK character sets can consume 2 to 5 tokens per word due to multi-byte unicode token splitting.

Understanding Asymmetric Token Pricing

Major AI providers implement asymmetric pricing: output tokens cost 3x to 5x more than input tokens.

For example, on Anthropic Claude 3.5 Sonnet:

  • Input tokens: $3.00 per million tokens
  • Output tokens: $15.00 per million tokens

Output tokens require auto-regressive generation, where the model sequentially calculates probability distributions for every subsequent token, requiring significantly more GPU compute cycles than parallelized input prompt evaluation.

Practical Optimization Strategies

  1. Prompt Compression: Strip decorative greetings, verbose framing, and repetitive examples from system instructions.
  2. Structured Output Limiting: Request compact JSON without whitespace indentation or enforce concise enumeration.
  3. Prompt Caching: On Anthropic and Google APIs, cache recurring system prompts and static documentation to reduce input costs by up to 75% to 90%.

Sources and further reading

Frequently asked questions

What is the difference between input and output tokens?
Input tokens represent the prompt and documents you send to the model; output tokens represent the response text generated by the model. Output tokens are priced 3x to 5x higher because they require sequential GPU generation.
How many tokens are in an average 1,000-word article?
An average 1,000-word English article contains approximately 1,300 to 1,350 tokens.
Does prompt caching save money on long prompts?
Yes. Both Anthropic and OpenAI support prompt caching, which reduces input token costs by 50% to 90% for repeated prompt prefixes.

Spotted an error or want a calculator we do not have yet? Tell us.