How to Find the Smallest and Largest Value a TensorFlow Data Type Can Hold
Every TensorFlow data type has limits: uint8 stops at 255, float16 at 65,504. A value outside those limits doesn't fit, and maths that goes past them gives wrong answers. Each data type can tell you its own limits and how many bytes it uses. This guide prints them for five common types in TensorFlow 2.22.0.
Syntax
tf.<data type>.min
tf.<data type>.max
tf.<data type>.size
| Part | What it means |
|---|---|
tf.<data type> | A data type, such as tf.uint8 or tf.float32, or a tensor's .dtype |
.min | The smallest value the type can hold |
.max | The largest value the type can hold |
.size | How many bytes one value of the type takes |
The DType API page describes the first two: max "Returns the maximum representable value in this data type", and min "Returns the minimum representable value in this data type."
The Example
A loop over five types: uint8, the type of photo pixels; int8 and int32, whole numbers; float16 and float32, decimal numbers. It prints each type's limits and size on one line.
Prerequisites
- A uv project with TensorFlow. This guide uses TensorFlow 2.22.0 on Python 3.14.10, with uv 0.13.10.
Step 1: Write the Script
import tensorflow as tf
for dtype in [tf.uint8, tf.int8, tf.int32, tf.float16, tf.float32]:
print(f"{dtype.name:<8} min {dtype.min}, max {dtype.max}, bytes per value {dtype.size}")

dtype.name:<8 pads each name to 8 characters, so the columns line up.
Step 2: Run It
uv run python ranges.py
uint8 min 0, max 255, bytes per value 1
int8 min -128, max 127, bytes per value 1
int32 min -2147483648, max 2147483647, bytes per value 4
float16 min -65504.0, max 65504.0, bytes per value 2
float32 min -3.4028234663852886e+38, max 3.4028234663852886e+38, bytes per value 4

| Type | Range | Bytes | Typical use |
|---|---|---|---|
uint8 | 0 to 255 | 1 | Photo pixels: one byte per colour |
int8 | -128 to 127 | 1 | Small whole numbers |
int32 | about ±2.1 billion | 4 | Whole numbers, TensorFlow's default for them |
float16 | ±65,504 | 2 | Decimals, when memory matters more than precision |
float32 | about ±3.4 × 10³⁸ | 4 | Decimals, TensorFlow's default for them |
Fewer bytes per value means less memory, and a smaller range. A photo stored as uint8 takes a quarter of the memory it takes as float32. The command works unchanged in PowerShell.
The first run in a new environment is slow, while TensorFlow loads for the first time.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Asking a non-number type for its range: tf.string.max | TypeError: Cannot find maximum value of <dtype: 'string'> with type <dtype: 'string'>. Text has no smallest or largest value | Ask only number types, such as tf.int32 or tf.float32 |
Doing maths in uint8 near its limit | 255 + 50 doesn't fit in uint8, and came out as 49 | Cast to a wider type first, as Fixed: 255 + 50 Gives 49 for a uint8 Tensor in TensorFlow shows |
FAQ
Can I read the range from a tensor?
Yes, through its data type: photo.dtype.max gives the largest value the tensor's type can hold, not the largest value in the tensor. For that, use tf.reduce_max(photo).
Why are float16 and float32 ranges so different?
Because of their size: float16 packs a decimal number into 2 bytes, and float32 into 4. More bits allow bigger numbers and more digits, so float32 reaches about 3.4 × 10³⁸ where float16 stops at 65,504.
Conclusion
.min, .max and .size gave each type's limits and bytes: uint8 holds 0 to 255 in 1 byte, int32 about ±2.1 billion in 4, float16 ±65,504 in 2 and float32 about ±3.4 × 10³⁸ in 4. Text types have no range, and asking for one fails.
Additional Resources
- tf.dtypes.DType — every property of a data type.
- tf.dtypes — the list of TensorFlow's data types.
