How Does Binary Work? A Beginner's Guide to Bits and Numbers
By the BrainSnail editorial team. How these articles are written and checked, and how to tell us when one is wrong.
Binary is a number system that uses only two digits, 0 and 1, instead of the ten digits used in everyday decimal notation. Computers use binary because electronic systems can reliably represent two distinct states, and long patterns of those states can encode numbers, text, images, instructions, and more.
Place values in base two
Decimal place values are powers of ten. In 347, the 3 represents three hundreds, the 4 represents four tens, and the 7 represents seven ones. Binary uses the same place-value idea, but each position is a power of two instead.
Reading from right to left, binary places have values 1, 2, 4, 8, 16, 32, and so on. A 1 means include that place value, while a 0 means leave it out. The binary number 1011 therefore means 8 plus 0 plus 2 plus 1, which equals 11 in decimal.
This is the simplest answer to how binary works as a number system. There is no mysterious computer arithmetic hiding underneath. You are using familiar positional notation with a different base.
Bits combine into larger patterns
A single binary digit is called a bit. One bit can represent two possibilities. Two bits can make four patterns, 00, 01, 10, and 11. With each additional bit, the number of possible patterns doubles. Eight bits can represent 256 different patterns.
A group of eight bits is commonly called a byte. The meaning of a bit pattern depends on how a system interprets it. The same pattern could represent a number in one context, part of a character code in another, or a tiny piece of colour information in an image.
That context is important when asking how binary works inside a computer. Binary is the representation layer, not the meaning by itself. Standards, data formats, and software rules tell the machine how a particular pattern should be interpreted.
Why computers use two states
Binary fits digital electronics for several practical reasons:
- •Circuits can distinguish two voltage ranges more reliably than many finely separated levels.
- •Two states can be labelled 0 and 1 and combined with logic operations.
- •Bits can be grouped to represent larger numbers and more complex data.
- •Error checking and storage are easier when signals are designed around clear state boundaries.
- •Software can build rich information from enormous sequences of simple binary choices.
Binary arithmetic follows the same basic idea as decimal arithmetic, with carrying happening when a column reaches two rather than ten. Adding 1 and 1 gives binary 10, meaning zero in the ones place and one in the twos place. Practising small additions can make how binary works feel much less abstract. The symbols are limited to 0 and 1, but place value still lets the system represent numbers of any size.
Conversion works in the other direction too. To see how binary works for a decimal number such as 13, find the largest power of two that fits, 8, then use 4, skip 2, and use 1. The resulting pattern is 1101 because 8 plus 4 plus 1 equals 13.
Hexadecimal and negative numbers
Long strings of bits are hard for people to read, so programmers often use hexadecimal, or base sixteen. It uses the digits 0 to 9 followed by the letters A to F for the values ten to fifteen. Because sixteen is two to the power four, each hexadecimal digit stands for exactly four bits. The byte 11111111 splits into 1111 and 1111, which are F and F, so it is written FF, equal to 255 in decimal. Web colour codes such as #FF0000 for pure red use this notation, with one byte each for red, green and blue.
Negative numbers need a convention too, and most computers use one called two's complement. To write the negative of a number, take the bits of the positive number, flip every 0 to 1 and every 1 to 0, then add 1. In eight bits, 5 is 00000101, so minus 5 becomes 11111011. The clever part is that ordinary binary addition then simply works: adding the two patterns gives 100000000, and the ninth bit is discarded, leaving zero. The leftmost bit also shows the sign, because every negative value in this system starts with 1.
From Leibniz to the light switch
Binary numbers are much older than computers. The German mathematician Gottfried Wilhelm Leibniz published an account of binary arithmetic in 1703, showing that any number could be written with just 0 and 1. He was delighted when a missionary in China pointed out that the hexagrams of the ancient I Ching, built from broken and unbroken lines, could be read as a binary sequence. For Leibniz, binary was a philosophical curiosity and an elegant piece of mathematics rather than something with practical machines in mind.
The link to machines came later. In 1854 George Boole set out an algebra of logic in which statements are either true or false, a system that can be written with 1 and 0. In 1937 Claude Shannon showed in his master's thesis that electrical circuits built from switches could carry out Boole's logic, so a network of relays could both calculate and make decisions. Relays gave way to vacuum tubes and then transistors, but the principle is unchanged: each tiny switch is either on or off, and logic built from those two states runs every computer.
Binary fractions and why 0.1 is awkward
Place values continue to the right of a binary point, just as they do after a decimal point, but they halve each time instead of dividing by ten: one half, one quarter, one eighth, one sixteenth and so on. So binary 0.101 means one half plus one eighth, which is 0.625 in decimal. Any fraction whose denominator is a power of two can be written exactly this way. Others cannot. One tenth has no finite binary form, in the same way that one third becomes 0.333 recurring in decimal. In binary it is 0.0001100110011, with the 0011 pattern repeating forever.
Computers usually store such numbers in a fixed number of bits, commonly 64, so the endless pattern has to be cut off and rounded. The stored value is extremely close to one tenth but not exactly equal to it. That is why adding 0.1 and 0.2 in many programming languages produces 0.30000000000000004 rather than 0.3. Nothing is broken; the tiny rounding errors in each number have simply become visible. Programmers comparing such values check whether they are close enough rather than exactly equal, and financial software often counts money in whole pence or cents to avoid the problem.
How letters become binary
Text is stored by giving every character a number and then storing that number in binary. The ASCII standard, first published in 1963, assigned codes to 128 characters, enough for English letters, digits, punctuation and some control signals. In ASCII, capital A is 65, which is 01000001 in binary, and lower-case a is 97, or 01100001. The two differ by exactly 32, a single bit, so switching between capitals and lower case can be done by flipping one bit. The digits are arranged neatly too: the character 7 has the code 55, so subtracting 48 gives its actual value.
A set of 128 characters cannot cover the world's writing systems, so modern computers use Unicode, which gives a code number to well over 100,000 characters, from Greek and Arabic letters to Chinese characters and emoji. The most common way of storing those numbers, called UTF-8, uses a variable number of bytes. Ordinary English letters keep their old ASCII codes and need only one byte each, while an accented letter such as e with an acute accent takes two bytes, many Chinese characters take three, and most emoji take four. The leading bits of each byte signal how many bytes belong to the character, so software never loses its place.
The takeaway
Binary uses powers of two as place values, with each bit showing whether a value is included or not. Groups of bits create many possible patterns, and computers give those patterns meaning through agreed rules. Learn to convert a few small binary numbers by adding powers of two, and the basic logic behind digital representation quickly starts to feel familiar.