So you’re wondering how binary code works, eh?
If you are learning computer science or computer programming, understanding binary code is part of the fundamentals you must learn.
But where should you start? What’s the easiest way to understand the binary system?
You may know that the binary system is based on 1’s and 0’s. Those two digits are the foundation for all tech gadgets around us.
So even if you aren’t a coding student, knowing how binary code works helps you understand the world around you.
In this guide, I’ll walk you through a simple way of wrapping your head around the binary system. I’ll share with you what I’ve learned about those simple 1’s and 0’s that make our tech-filled world go round.
Let’s get started!
Here are a couple of related articles you may find helpful, too:
- Learn to Code Faster: Learning Computer Science Basics for Computer Programming
- 26 Best Websites to Learn Coding for Beginners
- 8 Crucial Things to Know Before You Learn Programming
Please note: This post contains affiliate links to products I use and recommend. I may receive a small commission if you purchase through one of my links, at no additional cost to you. Thank you for your support!
Table of contents
- Why should you understand how binary code works?
- What is binary code?
- What do all the 1’s and 0’s mean?
- How do computers store data?
- How does binary code work?
- Where can you learn more about binary code and computer science?
- FAQ: How does binary code work?
Why should you understand how binary code works?
But if binary code is something only computers understand, why should you learn more about it?
You are absolutely right. You will (most probably) never write a computer programs in binary code.
Instead, developers like you and me use more user-friendly programming languages to give instructions to computers.
Nevertheless, binary code is probably the most fundamental concept underlying programming and Computer Science. It is what makes every computer you use work the way it does.
All in all, binary code enables us to communicate with computers and give them instructions.
And even though the programming languages you use for writing code are hopefully far from binary code, they are still translated into binary for computers to be able to interpret them and run your programs.
Those 1’s and 0’s define how computers take inputs, store and process information, as well as produce outputs for their users – that’s you and me.
Thus, understanding at least the basics of what binary is and how it works is not only interesting and quite fascinating, but also quite useful.
But don’t worry if the concept of binary code seems abstract and difficult to grasp at first.
What matters is that you are aware of how such a simple language can translate into the most complex computer programs and information structures that you see and use on a daily basis.
What is binary code?
What is binary code then? How does binary code work exactly?
How can a highly complex computer program consist of only 1’s and 0’s?
To simplify things, you can think of binary as being a way of telling a computer whether a switch should be on or off. Thus, 1 means “on”, 0 means “off”.
But wait a minute: What kind of a switch are we talking about here?
How does a switch that is either on or off translate into what computers do?
To understand this better, let’s look at how computers work:
Computers do four fundamental things:
- Take inputs
- Store information
- Process information
- Output results
These are the four basic tasks a machine needs to perform to be a computer in the first place.
For example, when you’re typing on your computer, your fingers hitting the keyboard are giving the computer inputs.
Your computer magically knows how to translate a certain key into the right letter.
Finally, the computer produced an output: you see the right letter on the screen.
So what does this have to do with binary code?
Read also: Computer Science 101: What is a Computer?
What do all the 1’s and 0’s mean?
Those 1’s and 0’s, or the switches I mentioned above, are how your computer stores and processes data.
Back in the day when the very first computers were built, they had actual lights bulbs to provide outputs to their users. A user would see a certain light switched on to indicate a certain kind of output or message from the computer.
The same thing happens nowadays when you are driving your car and the gas light comes on. That is an output from your car, telling that you should get off the freeway and find a gas station asap.
So with a computer, these 1’s and 0’s can be pretty much anything in modern computers. But generally they represent numbers, letters, and other symbols.
The bottom line here is that this simple concept of a switch being ON or OFF can translate into something really complex.
Even the most sophisticated, modern computers all work according to this very basic, rudimentary machine language with the 1’s and 0’s representing two states: either ON or OFF.
But to make this happen, your computer obviously deals with a lot more than just a single switch being turned on or off.
How do computers store data?
Before we dive into how binary code and binary numbers actually work and how you can decode a simple binary sequence, let’s consider one fundamental point about data storage first.
As I mentioned above, computers take inputs to store and process information. This information or data is the fundamental ingredient for any computer to work.
Now, when you look inside a computer, you will see a bunch of circuits and electric wires. They carry all the information inside a computer, getting it to the right place to be either stored or processed.
But how do you store or represent information using electricity?
Now, the 1’s and 0’s we were just discussing represent the smallest unit of data that a computer understands.
One switch being either on or off is what we need to store one bit of data.
Hence, a bit is the fundamental, basic unit of information. It is enough to indicate two different options, either “on” or “off”.
Also, it could mean “true” or “false”, or simply “yes” or “no”.
I know, having just two choices does not give us too many options really… But it is a good start!
With one light bulb we can store 1 bit of information.
With 10 light bulbs, we could do 10 bits.
So, if we had enough light bulbs, we could store any amount of data we wanted in a digital form.
Storing data in bits: A simple example
Of course, computers use other methods and technologies than simple light bulbs to store data these days.
Using light bulbs would not only take up too much space but it would also be difficult to store the data: turning off a computer using only light bulbs would mean that we would lose the data when the power goes off.
Thus, instead of light bulbs, computers store bits of data by holding electrons in capacitors, for example. Your computer uses this technology in its DRAM memory.
So, how many light bulbs would fit into your DRAM exactly?
Let’s assume your computer has a 4GB DRAM, for example.
One GB is approximately a billion bytes. Or to be more exact, 1 GB is 230 bytes. And 1 byte = 8 bits.
That means your 4GB of DRAM holds 230 x 4 x 8 = 34,359,738,368 bits.
That’s 34 billion light bulbs – and we are only talking about your DRAM here, not your 2TB hard drive!
So it’s obvious that modern computers can do much more than decide whether to switch on a single light or not.
Even though binary code consists of only 1’s and 0’s, it can represent the most complex of computer programs.
How does binary code work?
Now, what does it mean to have 34 billion bits to store and represent information?
To understand what these bits can do for us, let’s take a closer look the binary number system.
The binary number system only uses 0’s and 1’s to represent any further numeral values – and other types of data, too.
First, let’s do a quick refresher on how the “normal” numbers that we are used to…
Understanding the decimal number system
The numbers you and I learned in school, ranging from 0 to 9, make up the decimal number system.
You can use any combination of these 10 digits to represent a numeral value.
Moreover, you know how to do additions, subtractions, and other basic calculus using these numbers relatively quickly.
In the decimal system, each digit in a certain number represents the 1’s, the 10’s, the 100’s, and so on, starting from the right hand side.
So, with the number 216, for example, we have:
- A 6 representing the 1’s
- A 1 representing the 10’s
- A 2 to represent the 100’s
The decimal system uses powers of 10 to differentiate between these three “levels” of digits:
- 1’s: the 1’s represent how many times the numeric value includes 100
- 10’s: the 10’s stand for 101
- 100’s: the 100’s represent 102
So you see the pattern here?
10 to the power of 0, 1, 2, and so on.
We simply keep increasing the powers of 10 as our number gets bigger. Therefore, the decimal system is also called the base-ten numeral system.
And for my dear, fellow language nerds:
The word decimal comes from the Latin word decem for “ten”, while “binary” is derived from the Latin word bi, meaning “two” as a prefix.
Now let’s see how the binary number system is different from the decimal one.
How to understand the binary number system?
In the binary system, instead of using powers of 10, we use powers of 2.
Similar to the decimal example above, let’s think about what the different positions in a number mean.
Assuming we have a binary number with several digits, we can start from the right hand side again:
- First digit stands for 20, so these are the 1’s
- Second digit: 21, these are the 2’s
- Third digit: 22, these are the 4’s
- Fourth digit: 23, these are the 8’s
- Fifth digit: 24, these are the 16’s
- Sixth digit: 25, these are the 32’s
- Seventh digit: 26, these are the 64’s
- Eighth digit: 27, these are the 128’s
- Ninth digit: 28, these are the 256’s
Unlike in the decimal system, here in binary each of these digits simply tells us whether the digit is “on” or “off”.
When you see a “1”, it means that the value of that digit is included in the numerical value that we wish to represent.
When you see a “0”, that the value shouldn’t be included.
How to “decode” a binary number? A simple binary example
So how would we represent the number we just saw in decimal notation, 216, in binary?
Let’s give it a go!
- First, let’s start by looking at the powers of 2 in the list above. We need to find the largest value that is less than the value of 216.
- We see that it is the 128’s, so we need 8 binary digits in this case, from 20 to 27. You can see these 8 spots in the image below.
- Since 128 is “included” in our number, let’s indicate this by a “1” in the 128’s place in the image below.
- Then, let’s do a simple subtraction: 216 – 128 = 88.
- Again, let’s repeat the first step and find the largest value that is less than this leftover of 88. We see it is the 64’s, so we put a “1” in the digit for 26.
- Now, let’s subtract again: 88 – 64 = 24.
- So, going back to the first step we see that the next digit we will need to use a “1” for, is the 16’s place, or 24.
- We simply keep repeating these steps for finding out which binary digits get a value of either “1” or “0”.
Finally, we end up with the following binary sequence:
1 1 0 1 1 0 0 0
As such, this binary number sequence doesn’t really mean anything to you and me, since we are not used to the binary system.
Let’s calculate the values for the powers of two for each digit and add them together:
128 + 64 + 0 + 16 + 8 + 0 + 0 + 0
So, we end up with the correct number that we wanted to display in binary: 216.
Clearly, we do need a few more digits than we did with the decimal system, but the value of the number is exactly the same. And that’s what we wanted to achieve!
Thinking and calculating in binary numbers is of course somewhat tricky since we are used to a number system based on the powers of 10.
But even though the fundamental idea of having just two states representing two values, either “on” or “off”, the binary system is just as good as the decimal system for displaying numbers.
But how does binary code work for other sorts of information, like text, images, or audio?
Well, as it turns out, all of these types of information can also be represented in binary code, too!
Representing text in binary code
With binary, we can use simple numbers to represent the different letters in the alphabet. So, “A” could be “1”, “B” could be “2”, and so on.
That way, we can represent any word or paragraph of text as a sequence of these numbers. A computer can then store these numbers as information using the “on” or “off” signals.
So whenever you are reading text on your phone or your computer, what you see on your screen is based on binary code like this.
Representing images and graphics in binary code
In a similar way to representing the alphabet in numbers, we can do the same thing for images and other graphic media, too.
An image displayed on your screen consists of pixels. Each pixel in an image has a numerical value that determines the color it should display.
Considering a single image can be made of millions of pixels, we’re talking about a huge amount of information here!
Where should you learn more about binary code and computer science?
If you want to learn how to code, you should also understand what’s happening inside your computer.
Thus, if you are new to coding, make sure to take some time to get familiar with some computer science fundamentals.
You don’t need any advanced skills, though. The basics are enough.
Once you understand how computers work under the hood, learning how to code will be much easier.
And when you are familiar with how computer process data, you can write better, more efficient code, too.
To help you start learning computer science right away, I’ve gathered my favorite tutorials and courses below:
1: Computer Basics (Codecademy)
Computer Basics on Codecademy teaches you about how computers work, important hardware, the troubleshooting method, and more.
Computer Basics is part of the Introduction to IT course. If you are new to computer science and programming, check out the full curriculum for even more helpful lessons and modules.
Here’s another fun Codecademy course for you:
Binary and Bases is a quick beginner-level course. It introduces you to the logic of bases and helps you understand how different bases work in practice.
If you are not familiar with Codecademy yet, read my full Codecademy review here.
2: CS101 Bootcamp: Introduction to Computer Science & Software (Udemy)
You don’t need any technical experience with Computer Science to take this course, so it’s perfect for absolute beginners.
As long as you’ve used a smartphone or a computer in the past, that’s enough to start this quick 2-hour course.
By the end of the course, you will understand the fundamentals of databases, mobile apps, and the basics of software programming.
Moreover, you will even write you very own basic software programs and applications.
If you are not familiar with Udemy, check out my full Udemy review here.
3: Computer Science 101: Master the Theory Behind Programming (Udemy)
Computer Science 101: Master the Theory Behind Programming on is a comprehensive computer science course for beginners.
If you are looking to master CS theory – which is highly recommended for any programmer – this course is the perfect choice.
By the end of this course, you will be familiar with how binary code works and be comfortable with analysing and using algorithms of various kinds.
4: CS50’s Introduction to Computer Science (Harvard College)
CS50’s Introduction to Computer Science from Harvard College is my favourite free CS basics course for beginners. With over 2,000,000 students worldwide (and counting), this is one of the most popular computer science courses out there.
If you are looking to explore computer science, mobile app and game development, business technologies, and the art of programming, CS50 is the perfect place to start.
The professor does an amazing job explaining everything, so you’ll never feel like you’re left behind.
You’ll be taken into the lecture halls of Harvard, where you can enjoy full-length lecture videos and solve exercise sets that help you apply what you’re learning.
5: Crash Course Computer Science (YouTube)
Crash Course Computer Science is a free course with 40 lessons for computer science beginners.
Each lesson is about 10–15 minutes long and walks you through important fundamentals like:
- Boolean logic
- What is binary code
- How computers calculate
- Registers and RAM
- Programming basics
- and much more
6: Computer Basics (Treehouse)
If you’re in a hurry, Computer Basics at Team Treehouse is the perfect introduction to computer science.
In just 55 minutes, you will learn a bunch of computer science basics, including a quick lesson on binary code and how binary code works
You will take a look at the underlying concepts of how computers work and what’s happening behind the scenes when you run your computer programs.
Also, you will learn the basics of data processing, how memory works, what binary means in CS, and how computer software works.
7: Intro to Theoretical Computer Science (Udacity)
Intro to Theoretical Computer Science at Udacity is another one of my favourites.
This free intermediate course helps you deepen your understanding of algorithms and problem-solving.
Also, you will walk away with powerful tools to deal with the toughest algorithmic problems in practice.
FAQ: How does binary code work?
A binary number system is a number system that uses the number 2 as its base. Unlike the decimal number system where we use the digits 0 to 9 to represent a number, in a binary system, we use only 2 digits that are 0 and 1.
In computer programs, binary numbers are represented by only two symbols or digits, i.e. zero “0” and one “1”. Any numerical value can be represented as a binary value consisting of just 0’s and 1’s. With enough binary code, we can represent any value we want and store millions and billions of bits of data using just these two numbers.
“Bi” means “two” in Latin. Since the binary system only has two options, 0’s and 1’s, a single digit in a binary number can only represent two different things or values. All numbers are constructed from the two digits 0 and 1.
11111111 is 255 in the decimal number system. To find the decimal to binary equivalent, divide 255 successively by 2 until the quotient becomes 0. You can then obtain the binary equivalent by writing the remainder in each division step from the bottom to the top.
Final thoughts: What is binary code and how does binary code work – Binary code explained
I hope you are still with me!
I know this topic is somewhat abstract if you are new to computer science. And it might be difficult to think of a situation where you would need to know how binary code works.
Because the truth is:
When you write code and programs for your computer, you are not dealing with these binary numbers directly. You will most likely use a programming language that helps you get the job done more easily and quickly.
However, you will be dealing with what all those 1’s and 0’s can do for you. You write and read text, create and see images, and watch videos and other media on your computer.
Binary code is the foundation for everything that computers do:
- Getting inputs
- Storing information
- Processing information
- Producing outputs
No matter how complex or sophisticated a computer program or system is, it all comes down just 1’s and 0’s.
Knowing how binary code works and what the binary system means will help you understand how computers work and how to write better code as a developer.
Here are a couple of related articles you may find helpful, too:
Did you find this post on binary code and how binary works helpful? Drop me a line in the comments below!
P.S. Share it with others so that they can learn about binary code, too. Thanks!