Section 01 · Definition
What is bool in Solidity?
bool is the boolean type. It can be true or false, and nothing else.
Quick answer
What is bool? bool is Solidity's boolean type. A bool variable holds one of two values — true or false — and supports the standard logical operators && (and), || (or), and ! (not). Every condition you write inside if, require, while, and the ternary operator is a bool expression.
bool public paused; // default false
bool public initialised = true;
bool public whitelisted;
function unpause() external {
paused = false;
}Solidity does not implicitly convert other types to bool. Unlike JavaScript or Python, there is no truthy / falsy concept. You can never write if (counter) to mean "if counter is non-zero". The compiler will reject it. You write if (counter > 0). This rule eliminates an entire class of bugs.
Section 02 · Operators
The three boolean operators and a truth table
Solidity gives you the same logical operators every C-family language has — and they short-circuit, which has gas implications.
bool isOpen = true;
bool isWhitelisted = whitelist[msg.sender];
// AND — both must be true
if (isOpen && isWhitelisted) { ... }
// OR — at least one must be true
if (isAdmin || isOwner) { ... }
// NOT — invert
if (!paused) { ... }
// Short-circuit means cheapMath is NOT called when isOpen is false
require(isOpen && cheapMath(), "closed or invalid");The short-circuit behaviour matters for gas. Put the cheaper or more often-false check on the left of an &&, and the cheaper or more often-true check on the left of an ||, so the expensive check runs as rarely as possible.
Section 03 · Storage
A bool still costs a full storage slot — unless you pack it
The EVM stores everything in 32 byte slots, so a bool by itself wastes 31 bytes. Pack bools alongside other small fields and the cost disappears.
// Wasteful: each bool takes its own 32 byte slot
bool public paused; // slot 0 — 31 bytes wasted
bool public initialised; // slot 1 — 31 bytes wasted
uint256 public counter; // slot 2
// Packed: all three fit inside one 32 byte slot
struct Flags {
bool paused; // 1 byte
bool initialised; // 1 byte
uint64 counter; // 8 bytes
// 22 bytes unused but only ONE storage slot
}
Flags public flags;Inside a struct, the compiler packs adjacent small fields together. Outside a struct, two bools declared back-to-back at the contract level still take two slots. Read more about layout in the structs in Solidity guide.
Section 04 · Real-world uses
Where bool shows up in production code
Five patterns you will see in almost every contract.
// 1. Pause switch
bool public paused;
modifier whenNotPaused() {
require(!paused, "paused");
_;
}
// 2. One-time initialiser guard
bool private _initialised;
function init() external {
require(!_initialised, "already initialised");
_initialised = true;
// ...
}
// 3. Whitelist mapping
mapping(address => bool) public allowedCallers;
// 4. Return value from a low-level call
(bool ok, ) = payable(to).call{value: amount}("");
require(ok, "transfer failed");
// 5. Bid-or-buy auction logic
bool public buyNowAvailable = true;Pair bool flags with a modifier to enforce them across many functions, and emit a event whenever the flag changes so off-chain systems can keep up.
Default false is a safety property
Because uninitialised bools default to false, a contract is never accidentally 'paused = true' or 'whitelisted = true'. Design your flags so the safe state is the default. For example name a permission 'isFrozen' (default false = unfrozen) rather than 'isUnlocked' (default false = locked), so a bug never accidentally locks everyone out.