sizeof(bool) in C++: why a bool is a whole byte
A C++ bool holds one bit of information but takes a whole byte. The raw bytes are 01 for true and 00 for false, and 8 bools take 8 bytes.
What does sizeof(bool) give in C++, and how is a bool stored in memory? A bool is true or false: one bit of information. Yet on every mainstream compiler it takes a whole byte. Here are the real bytes.
This is the written version of Understanding C++ #8. Everything below comes from one program, compiled with g++ -std=c++20 -Wall -O2 (GCC 13) on x86-64 Linux.

How big is a bool?
sizeof(bool) printed 1. Unlike sizeof(char), which the standard fixes at 1, the size of bool is implementation-defined. In practice it is 1 on GCC, Clang and MSVC for x86-64 and ARM, and a byte here is 8 bits (CHAR_BIT is 8).
What bytes do true and false store?
To see the stored byte, the program reads each bool through an unsigned char. That is allowed: the character types may be used to inspect the bytes of any object.
| variable | value | byte (hex) | bits |
|---|---|---|---|
t |
true |
01 |
0000 0001 |
f |
false |
00 |
0000 0000 |

So true is stored as the byte 01 and false as 00. In true, seven of the eight bits are zero and only the lowest bit is set. The other seven carry no information at all.

Why not one bit?
Because a byte is the smallest unit of memory with its own address. Every complete object in C++ occupies at least one byte and has an address you can take with &, distinct from the address of any other object alive at the same time. An address names a byte, not a bit, so the smallest an addressable object can be is one byte. A bool pays for that with seven unused bits.
What about an array of bools?
bool a[8] = {}; is eight bools, all false. sizeof a printed 8: one byte each, no packing. The loop prints the address of every element, and each is one higher than the last. In this run they were 0x7ffcbb8a2410 to 0x7ffcbb8a2417. The exact addresses change on every run, because the stack is placed at a random address; the step of one does not.
![bool a[8]: eight bytes of 00 at consecutive addresses ending 10 to 17, sizeof a = 8](https://vthvqgqmgbnywvxzqlws.supabase.co/storage/v1/object/public/blog-media/shorts/cpp-008-bool-is-a-byte/array.jpg)
If you need eight flags in one byte, you pack them yourself into an integer with bit operations, or use std::bitset<8>. (std::vector<bool> also packs bits, which is why its elements cannot be addressed like ordinary bools.)
What happens if you store 2 in a bool?
bool b = 2; is a conversion: any nonzero value converts to true and zero converts to false. So b holds true, and printing it with %d gives 1. A bool never holds the value 2; the conversion happens when you assign it.

The program and its output
#include <cstdio>
int main() {
bool t = true, f = false;
std::printf("%zu\n", sizeof(bool));
unsigned char bt = *(unsigned char*)&t;
unsigned char bf = *(unsigned char*)&f;
std::printf("%02X %02X\n", bt, bf);
bool a[8] = {};
std::printf("%zu\n", sizeof a);
for (bool& x : a)
std::printf("%p\n", (void*)&x);
bool b = 2;
std::printf("%d\n", b);
}
1
01 00
8
0x7ffcbb8a2410
0x7ffcbb8a2411
0x7ffcbb8a2412
0x7ffcbb8a2413
0x7ffcbb8a2414
0x7ffcbb8a2415
0x7ffcbb8a2416
0x7ffcbb8a2417
1
Line by line: 1 is sizeof(bool), 01 00 are the bytes of true and false, 8 is sizeof a, then the eight addresses of the array's elements, and the final 1 is b after bool b = 2.
Try it
How many bytes do 100 bools take? Work it out from the numbers above, then check it with sizeof on your own compiler.