Code Token Counter
Estimate tokens and cost for source code.
With the default inputs, 0 tokens (estimated) — 0 words · 0 characters · 0 sentences. Enter your own numbers below to recompute instantly; the full step-by-step math is shown under the worked example.
Results update automatically as you type.
- Estimated tokens
- 0
- Words
- 0
- Characters
- 0
- Characters (no spaces)
- 0
- Sentences
- 0
- Input cost at this model(GPT-5)
- $0.0000
| Prose / English | 4 | 0 |
| JSON | 3.5 | 0 |
| Code | 3.3 | 0 |
| Non-Latin / other | 2 | 0 |
Estimate how many tokens a snippet of source code uses and its cost as model input. Useful for code assistants, review bots and anything that sends files to an LLM.
How this is calculated
We estimate tokens from your code using a code-tuned ratio (~3.3 characters per token — symbols and short tokens make code denser than prose), then price it as input at your chosen model. A typical 45-character line is about 14 tokens.
Is this a good result? What to do next
For code assistants and review bots the token count drives both cost and whether a file fits the context window. If snippets routinely blow the budget, the fix is usually retrieving only relevant files rather than sending everything.
Typical planning ranges
- Code
- ~3.3 characters per token
- Typical 45-char line
- ~14 tokens
- 1,000 lines
- ~14,000 tokens
Ranges are typical planning figures to sanity-check your result, not authoritative benchmarks. Your numbers will vary with use case, volume, and vendor.
How to improve this number
- Send only the relevant functions/files, not the whole repo.
- Strip comments and blank lines when they aren't needed for the task.
- Use a larger-context or cheaper model for big code inputs.
Common mistakes
- Estimating code at prose ratios and under-budgeting context.
- Pasting entire files when a snippet would do.
When to use a different approach
For a whole repository, use the codebase token calculator; for JSON payloads, use the JSON token counter.
Worked example (defaults)
With the default inputs above, here is the result:
- Estimated tokens
- 0
- Words
- 0
- Characters
- 0
- Characters (no spaces)
- 0
- Sentences
- 0
- Input cost at this model(GPT-5)
- $0.0000
| Prose / English | 4 | 0 |
| JSON | 3.5 | 0 |
| Code | 3.3 | 0 |
| Non-Latin / other | 2 | 0 |
- Heuristic: tokens ~= characters / 3.3
- 0 chars -> ~0 tokens
Sources & references
Frequently asked questions
How many tokens is a line of code?+
Code averages roughly 3.3 characters per token, so a typical 45-character line is about 14 tokens. Dense or minified code varies.
Related calculators
Answering a real question?
This calculator powers these problem-solving guides: