What Is a Boolean?
In programming, a boolean is a data type with exactly two values, true and false. Programs get booleans from comparisons such as age >= 18 and use them to decide which code runs, in if statements and loop conditions.
Updated September 24, 2026
Every decision a program makes comes down to a question with two possible answers: whether the password is correct, whether the cart is empty, whether the timer has reached zero. The boolean is the data type that holds those answers. It is named after George Boole, an English mathematician who described an algebra of true and false values in books published in 1847 and 1854.
Where booleans come from
You rarely type True or False directly. Most booleans are produced by comparisons, which ask a question about two values and answer with a boolean:
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | equal to | 3 == 3 | True |
!= | not equal to | 3 != 3 | False |
<, > | less than, greater than | 2 < 5 | True |
<=, >= | at most, at least | 17 >= 18 | False |
A boolean can be stored in a variable like any other value and combined with other booleans:
False
<class 'bool'>
False
True
Combining booleans: and, or, not
Three logical operators build larger conditions out of smaller ones. and is true only when both sides are true. or is true when at least one side is true. not flips a single value.
a | b | a and b | a or b | not a |
|---|---|---|---|---|
True | True | True | True | False |
True | False | False | True | False |
False | True | False | True | True |
False | False | False | False | True |
Python spells these operators as words. C, Java and JavaScript use symbols: && for and, || for or, ! for not. All four languages stop evaluating as soon as the answer is known, so in a and b, the right side is never checked when a is false. This is called short-circuit evaluation. The Python logical operators guide covers it in detail.
How booleans control a program
An if statement runs its block only when its condition is true. A while loop repeats its block for as long as its condition stays true, so every loop is driven by a boolean that is checked again before each pass. That repetition is called iteration.
Hot day
Countdown: 3
Countdown: 2
Countdown: 1
When count reaches 0, the condition count > 0 becomes False and the loop ends. If the condition could never become false, the loop would run forever.
Booleans as 1 and 0
A boolean needs only one bit of information: 1 for true, 0 for false. In practice, languages store a boolean in at least one whole byte, because a byte is the smallest unit of memory that has its own address. In C, a bool from <stdbool.h> takes 1 byte with gcc and clang. Programs that need millions of flags pack 8 of them into each byte with bitwise operators.
Languages disagree on whether a boolean is also a number. In Python, bool is a subclass of int, so True equals 1 and False equals 0. That makes counting easy:
True True
2
3 correct
JavaScript also gives 2 for true + true. C had no boolean type until C99 and still treats any nonzero number as true. Java is strict: if (1) does not compile, because a Java condition must be a boolean.
Truthy and falsy values
Python and JavaScript let you use any value as a condition, not only True and False. Values that count as false are called falsy; everything else is truthy.
0 -> False
42 -> True
'' -> False
'False' -> True
[] -> False
[0] -> True
None -> False
In Python, zero, empty strings, empty collections and None are falsy. The string "False" is truthy, because it is a string with five characters in it. JavaScript has its own falsy values, including false, 0, "", null, undefined and NaN, and there an empty array [] is truthy. See truthy and falsy in JavaScript for the full rules.
Common mistakes
Comparing to True. if is_ready == True: works, but if is_ready: says the same thing with less to read. For the false case, write if not is_ready:.
Treating text as a boolean. Input from a user, a file or a form arrives as a string, so bool("false") is True. Compare the text instead: answer == "yes".
Wrong capitalization. Python writes True and False; JavaScript, Java and C write true and false. Typing true in Python gives NameError: name 'true' is not defined.
Vague names. Name a boolean like a yes or no question, such as is_valid, has_access or can_edit, so a condition reads as a sentence: if user.can_edit:.
Where to go next
Booleans decide how many times a loop runs, so what iteration is is the natural next page, and what a bit is shows the 0 and 1 underneath every true and false. For the Python details, read numbers and booleans, then practice conditions in the Python course.
Frequently Asked Questions
What is a Boolean example?
5 > 3 is a boolean expression, and its value is True. A variable such as is_logged_in = False holds a boolean value. In a library catalog, the search cats AND dogs is a Boolean query that uses the same logic.Is a Boolean 1 or 0?
True == 1 is True, and in C any nonzero number counts as true. Java keeps them apart: a Java boolean cannot be used as a number at all.Is Boolean just yes or no?
What is a Boolean in Python?
bool, and its two values are True and False, written with a capital letter. bool is a subclass of int, so True behaves as 1 in arithmetic. The bool() function converts any value to True or False using Python's truthiness rules.What is a Boolean search?
python AND tutorial requires both words, python OR java accepts either, and python NOT snake excludes pages with the second word. Library catalogs and research databases support it directly, and Google accepts OR and a minus sign for NOT.