C++ integer overflow: unsigned wraps, signed is undefined
Integer overflow on real bytes: why 0xff + 1 is 0 in a uint8_t, why unsigned always wraps mod 2^N, and why INT_MAX + 1 is undefined behaviour.
Integer overflow is what happens when an arithmetic result does not fit in the bits of its type. In C++ the answer depends on the type: unsigned integers wrap around, always, by definition, while overflowing a signed integer is undefined behaviour. Here is what both look like in real bytes.
This is the written version of Understanding C++ #4. Everything below comes from one real program, compiled with g++ -std=c++20 -Wall -O2 on x86-64 Linux.
What does 0xff look like in a byte?
std::uint8_t b = 0xFF; is one byte. In this run it lived at 0x7fffffffc133, and the four bytes after it, c134 to c137, held std::uint32_t u. 0xff in binary is 11111111: all eight bits set, the value 255, the largest a byte can hold.

Where does the carry go when you add one?
Binary addition works like the column addition you already know. Adding 1 to bit 0, which is already 1, gives 0 and a carry. That carry hits bit 1, which is also 1, so it becomes 0 and carries again, all the way up.

The full result is 0x100, which needs a ninth bit. A uint8_t has no bit 8, so the carry is simply lost. What remains is eight zeros: b is 0.

(Strictly, b + 1 is computed as an int after integer promotion, giving 256, and storing 256 into a uint8_t keeps it modulo 2⁸. The bytes end up the same: 00.)
Is it the same for 32 bits?
Yes. u = 0xFFFFFFFF is all 32 bits set. Adding one carries through all 32 of them into a 33rd bit that does not exist, and the four bytes at c134…c137 read 00 00 00 00. The program prints 0 0 for b and u.

This is not an accident of the hardware that you happen to get away with. The standard defines unsigned arithmetic modulo 2ᴺ, where N is the width of the type:
| type | N | max | max + 1 |
|---|---|---|---|
uint8_t (stored back) |
8 | 255 (0xff) |
0 |
uint32_t |
32 | 4294967295 (0xffffffff) |
0 |
What about a signed int?
int s = 0x7FFFFFFF; is INT_MAX, 2147483647: the sign bit is 0 and the other 31 bits are 1. Adding one to it is undefined behaviour. The standard does not say what the result is, or even that there is one. The program on purpose never computes s + 1; it only says so in a comment.

If you do want to see it happen, build a separate test with -fsanitize=undefined. The sanitizer stops treating it as silent and reports, at run time:
runtime error: signed integer overflow: 1 + 2147483647 cannot be represented in type 'int'
Why does the compiler care?
Because a correct program never overflows a signed int, the compiler is allowed to assume it never happens, and it optimises on that assumption. The program contains bool up(int x) { return x + 1 > x; }. For every x where x + 1 is defined, the answer is true, so g++ at -O2 compiles the whole function to "return 1" (from g++ -std=c++20 -Wall -O2 -S, assembler directives removed):
_Z2upi:
endbr64
movl $1, %eax
ret

There is no comparison and no addition left. An overflow check written as if (x + 1 < x) disappears the same way, which is why signed overflow has to be prevented before it happens, not detected after.
The program and its output
#include <cstdint>
#include <cstdio>
bool up(int x) { return x + 1 > x; }
int main() {
std::uint8_t b = 0xFF;
std::uint32_t u = 0xFFFFFFFF;
std::printf("%p %p\n", (void*)&b, (void*)&u);
b = b + 1; // carry falls off
u = u + 1; // mod 2^32
std::printf("%d %u\n", b, u); // 0 0
int s = 0x7FFFFFFF; // INT_MAX
std::printf("%d\n", s); // 2147483647
// s + 1: undefined behaviour
}
0x7fffffffc133 0x7fffffffc134
0 0
2147483647
The addresses come from a run with address randomisation turned off (setarch -R); on your machine they will differ, and the compiler may place b and u differently. The other two lines are the same with any compiler where int is 32 bits. -Wall prints no warning for this program.
Unsigned wraps. Signed overflow is a bug.
Try it
What is 200 + 100 stored in a uint8_t? Work it out modulo 2⁸, then check it by adding a line to the program.