Boolean is a data type that has only two possible values: true and false.
Because an individual bit also has just two possible values (0 and 1), it's tempting to think that a boolean is stored in just 1 bit. But in practice, booleans often take up a whole byte (8 bits). This is because a byte is usually the basic addressable unit in a computer. In other words, usually the computer doesn't grab individual bits in memory—instead it grabs "chunks" of 8 bits or more at a time.
Sometimes booleans take up as much space as an integer, which is often 32 or 64 bits in modern computers. In fact, in some languages, like Python, booleans are subclasses of integers.
Interview coming up?
Get the free 7-day email crash course. You'll learn how to think algorithmically, so you can break down tricky coding interview questions.
No prior computer science training necessary—we'll get you up to speed quickly, skipping all the overly academic stuff.
No spam. One-click unsubscribe whenever.
You're in! Head over to your email inbox right now to read day one!