# How do I calculate image tokens in GPT4 Vision?

**URL:** <https://community.openai.com/t/how-do-i-calculate-image-tokens-in-gpt4-vision/492318>\
**Category:** API\
**Tags:** gpt-4, token, gpt-4-vision, gpt4-vision\
**Created:** [November 10, 2023, 10:06am UTC](https://community.openai.com/t/how-do-i-calculate-image-tokens-in-gpt4-vision/492318 "2023-11-10T10:06:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Locust2520](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/locust2520/32/2290_2.png) [@Locust2520](https://community.openai.com/u/Locust2520)\
**Post date:** [November 10, 2023, 12:29pm UTC](https://community.openai.com/t/how-do-i-calculate-image-tokens-in-gpt4-vision/492318/2 "2023-11-10T12:29:41Z")

</div>

According to the [pricing page](https://openai.com/pricing), every image is resized (if too big) in order to fit in a 1024x1024 square, and is first globally described by **85** base tokens.

## Tiles

To be fully recognized, an image is covered by 512x512 tiles.  
Each tile provides **170** tokens. So, by default, the formula is the following:  
total tokens = **85 + 170 \* n** , where n = the number of tiles needed to cover your image.

## Implementation

This can be easily computed this way:

```python
from math import ceil

def resize(width, height):
    if width > 1024 or height > 1024:
        if width > height:
            height = int(height * 1024 / width)
            width = 1024
        else:
            width = int(width * 1024 / height)
            height = 1024
    return width, height

def count_image_tokens(width: int, height: int):
    width, height = resize(width, height)
    h = ceil(height / 512)
    w = ceil(width / 512)
    total = 85 + 170 * h * w
    return total

```

## Some examples

- 500x500 → 1 tile is enough to cover this up, so total tokens = 85+170 = 255
- 513x500 → you need 2 tiles → total tokens = 85+170\*2 = 425
- 513x513 → you need 4 tiles → total tokens = 85+170\*4 = 765

## `low_resolution` mode

In _“low resolution”_ mode, there is no tile; only the **85** base tokens remain, no matter the size of your image.

---

_[View the full topic](https://community.openai.com/t/how-do-i-calculate-image-tokens-in-gpt4-vision/492318)._
