The Maths You Actually NeedLesson 70 of 76

Module 8 · Numbers inside a machine

Integers, overflow, and the token id that would not fit

In this lesson

  • 8 min read
  • 8 reading sections
  • Knowledge check
  • Lesson 4 of 10 in this chapter

This chapter’s goalPredict from the bit layout of float32, fp16 and bf16 which computation will overflow, underflow or lose its digits, explain why a long sum drifts and how to fix it, quantise a weight to int8 by hand and say what an outlier does to the rest of the tensor, derive the initialisation scale that keeps variance constant through a layer, and diagnose a NaN in training back to the operation that produced it.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 9Free · no account needed
Lesson steps

Integers are exact, until they are not

An integer type stores a whole number exactly, with no rounding, within a fixed range set by its width:

Text
uint8    0 to 255
int8     −128 to 127
int16    −32,768 to 32,767
int32    −2,147,483,647 to 2,147,483,647   (about ±2.1 billion)
int64    about ±9.2 × 10^18

Inside the range, every operation is exact, which is why counters, indices, ids and pixel values are integers. Outside it, the behaviour is not an error. In NumPy and most compiled code, an int32 that passes 2,147,483,647 wraps to −2,147,483,648, and the program continues with a negative number where a large positive one should be. Python’s own int grows without limit, so this never happens in plain Python; it happens the moment data enters a NumPy array, a PyTorch tensor, a database column or a file format, all of which have fixed widths.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Integers, overflow, and the token id that would not fit’, in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/integers-overflow-and-the-size-of-things (Accessed: 29 November 2026).