Binary basics

What is binary code?

Two digits, 0 and 1, hold every photo, song and message on your phone. Here is what binary code is and why computers chose it.

Written by
Reviewed by
Updated · 7 min read

Binary code is information written with only two symbols, 0 and 1. The letter A you see on screen, for example, is stored as 01000001. Each 0 or 1 is called a bit, and a row of bits can stand for a number, a letter, a pixel, a sound sample or an instruction for the processor. Computers use it because their circuits only have to tell two states apart: a voltage that is high or one that is low.

Key takeaways

Binary code stores information with two symbols, 0 and 1. Each one is a bit.
Each place is worth twice the one to its right: 1, 2, 4, 8, 16 and so on.
8 bits make a byte, which holds 256 values. In general, n bits hold 2 to the power of n values.
Computers use binary because a switch that is clearly on or off is cheap to build and hard to misread.
Bits mean nothing on their own: 01000001 is 65 as a number and the letter A as text.
binarytranslator.ai

What binary code means

The word comes from the Latin binarius, "consisting of two". Binary is a number system with base 2, the same way the numbers you write every day use base 10. Decimal has ten digits and each place is worth ten times the one to its right. Binary has two digits and each place is worth twice the one to its right.

DecimalBinary
Base102
Digits used0 to 90 and 1
Place values, right to left1, 10, 100, 10001, 2, 4, 8, 16
Thirteen is written131101
Largest 3-digit number999111 (7)

Both systems work the same way. Only the size of each step changes. That is why the decimal number 13 and the binary number 1101 describe exactly the same amount.

Place values compared: in decimal, 13 is 1 ten plus 3 ones. In binary, 1101 has 1s in the places worth 8, 4 and 1, which also adds up to 13.

Bits and bytes

One bit can hold two values. Add a second bit and you get four patterns: 00, 01, 10 and 11. Every extra bit doubles the count, so n bits can hold 2 to the power of n different values. The powers of 2 chart lists them all the way to 64 bits.

BitsNameDifferent valuesTypical use
1bit2on or off, yes or no
4nibble16one hex digit, 0 to F
8byte256one character of English text
1665,536one sample of CD audio
2416,777,216one RGB pixel color
324,294,967,296an IPv4 address

One reason the byte settled at 8 bits is that 8 bits cover every letter, digit and symbol on an English keyboard, with room to spare. File sizes are counted in bytes, and the byte converter turns bytes into KB, MB and GB.

How binary works: counting with two digits

Counting in binary follows the same rule as an odometer, only it rolls over after 1 instead of after 9. Zero is 0, one is 1, and two has no single digit, so it becomes 10. Then come 11, 100, 101, 110, 111 and 1000, which is eight.

To turn a binary number back into decimal, write the place values over the bits and add the ones that sit over a 1. In 01000001 the 1s are under 64 and 1, so it equals 65. Click the bits below to try other patterns.

Our guide on how to read binary goes through decoding step by step, and the binary to decimal converter shows the sum for any number you paste in.

Why computers use binary

A computer chip is made of billions of transistors, and each one works like a switch. A switch that only has to be clearly on or clearly off is simple to build and hard to misread. If a chip had to tell ten voltage levels apart, a small amount of electrical noise could turn a 6 into a 7. With two levels there is a wide gap between them, so a wobble in the signal does not change the bit.

The same idea works in every kind of storage. A hard drive records bits as tiny areas magnetized in one of two directions. Flash memory in a phone traps or releases electric charge in each cell. A fiber optic cable sends pulses of light that are either there or not. In each case the hardware only has to answer one question per bit, which keeps reading it reliable.

There is a second reason. In his master's thesis, written at MIT in 1937, Claude Shannon showed that circuits of switches can carry out Boolean logic, the true and false algebra George Boole published in 1854 in An Investigation of the Laws of Thought. Once 1 meant true and 0 meant false, the same circuits could both store numbers and make decisions. Those circuits are called logic gates, and they are what a processor is built from.

Early machines did not all agree. ENIAC, finished in 1945, stored numbers in decimal. Binary designs won because they needed fewer parts for the same job.

What binary code can store

Bits have no meaning on their own. The program that reads them decides what they stand for. The byte 01000001 is a good example.

The byte 01000001 read three ways: as a number it is 65, as ASCII text it is the capital letter A, and as a grayscale pixel it is a dark gray with brightness 65 out of 255.
  • Read as a plain number, 01000001 is 65. Negative numbers usually use a format called two's complement, which the two's complement calculator shows bit by bit.
  • In ASCII text, 65 is the capital letter A. Letters outside English, such as é or emoji, use 2 to 4 bytes in UTF-8, as the guide to Unicode, UTF-8 and ASCII explains. The ASCII table lists the first 128 codes.
  • For color, a screen pixel is usually three bytes, one each for red, green and blue. The color #B83A14 is 10111000 00111010 00010100. The RGB to hex converter shows both forms.
  • Sound is stored as a long list of measurements. CD audio takes 44,100 of them per second for each channel, and each one is a 16-bit number.
  • Programs end up as machine code, which is binary the processor reads as commands. On Intel and AMD chips, the byte 10010000 means "do nothing for one step".

Binary code examples

To write a word in binary, look up each letter's ASCII number and write that number as 8 bits. Each letter becomes one byte. Here is "Hello":

LetterASCII numberBinary
H7201001000
e10101100101
l10801101100
l10801101100
o11101101111

Put together, that is 01001000 01100101 01101100 01101100 01101111. You can check it, or write your own, with the text to binary converter. The binary alphabet lists every letter from A to Z, and teachers can hand out the free secret messages worksheet, where students decode words like this one.

A short history of binary

Binary patterns are older than computers. Braille, from the 1820s, marks each character with six dots that are either raised or flat, which gives 64 possible patterns. Francis Bacon published a cipher in 1623 that hid each letter as a group of five A and B symbols.

The German mathematician Gottfried Wilhelm Leibniz wrote up binary arithmetic in 1703 and showed how to add and multiply with only 0 and 1. Boole's algebra of logic followed in 1854, and Shannon tied the two together in 1937. Within a few years, binary computers were being built, and almost every digital device since then has worked the same way.

Binary code, machine code and source code

These three terms get mixed up. Binary code is any information written as bits. Machine code is one particular kind of binary: the instructions a processor runs directly. Source code is what programmers write in a language such as Python or C, and a compiler or interpreter turns it into machine code. A photo file and an app are both binary, but only the app contains machine code.

Questions people ask

What is binary code in simple terms?

It is a way to write any information using only 0 and 1. A computer stores everything this way because its circuits are switches that are either off or on.

What does 11111111 mean in binary?

It is 255, the largest number one byte can hold. All eight places are 1, so you add 128, 64, 32, 16, 8, 4, 2 and 1.

How do you say hello in binary?

Hello is 01001000 01100101 01101100 01101100 01101111. Each group of eight bits is one letter in ASCII.

Who invented binary code?

Gottfried Wilhelm Leibniz described modern binary numbers in 1703. Claude Shannon showed in 1937 that electric circuits could work with them, which led to binary computers.

Is binary code still used today?

Yes. Phones, laptops, game consoles and web servers all store and process data as bits. Even quantum computers give their final answers as ordinary bits.

Why is it called binary?

Binary means "made of two parts". The system has only two digits, 0 and 1, so it is also called base 2.

About the authors

Written byUma VictorTechnical writer

Uma Victor is a technical writer and software engineer with seven years of engineering work. He writes API documentation, integration guides and tutorials for developer tools, and his articles have run in Smashing Magazine, freeCodeCamp and LogRocket. He runs the code before he writes about it. On binarytranslator.ai he writes the guides on binary, hex and text encoding.

All guides by UmaLinkedIn

Reviewed byKhushboo GuptaPhD student in computer science, University of Illinois Chicago

Khushboo Gupta is a PhD student in computer science at the University of Illinois Chicago, where she researches natural language processing. As a graduate teaching assistant she has taught Program Design, Data Structures, Introduction to Data Science and Natural Language Processing. Before her PhD she was a software development engineer at Amazon Web Services and a software engineer at Pacific Northwest National Laboratory, and she holds an MS in computer science from Syracuse University. On binarytranslator.ai she reviews the guides on text encoding, data structures and number systems.

ProfileLinkedInHow we review

Keep reading

All posts
In an 8-bit signed integer, 127 + 1 equals -128.Binary basics

MSB and LSB: most and least significant bits, signed integers and overflow

The MSB is the leftmost, highest-value bit and the LSB the rightmost. See what each tells you, how signed integers use the MSB as a sign bit, and how integer overflow wraps values around.9 min read
In floating point, 0.1 + 0.2 equals 0.30000000000000004.Binary basics

Floating point numbers explained: why 0.1 + 0.2 is not 0.3

A floating point number is scientific notation in binary. See why 0.1 + 0.2 is 0.30000000000000004, how precise floats are, float vs double, and how to compare floats and handle money.9 min read
The hexadecimal number 2F3 equals 755 in decimal.Binary basics

What is hexadecimal? The base 16 number system explained

Hexadecimal is base 16, with digits 0 to 9 and A to F. See how place values work, why programmers use hex for bytes, the values worth knowing and how octal compares.7 min read
Scroll to Top