Binary Code Explained Step-by-Step: How Does Binary Work?


updated Apr 26, 2022


Even if you are not an expert in programming or Computer Science, you probably know that computers only possess a very limited vocabulary. The alphabet every computer in the world understands is binary code, that cryptic, seemingly never-ending sequence of 1’s and 0’s. But how does binary code work?

In today’s post, I’m sharing what I have learned about how these simple 1’s and 0’s make our tech-filled world go round.

In short, they are the backbone of what is happening in your computer all the time. Therefore, having a basic understanding of what binary code is and how it works helps you understand how your computer works on the inside.

So if you are new to coding, pair this post with my Free Coding Guide for Beginners and you’re good to go!

Keep reading!

Here are a couple of related articles you may find helpful, too:

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. But please, only buy products you believe will help you achieve your goals faster. Thank you for your support!

Why Should I 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 I use other, 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.

Recommended: 6 Best Online Computer Science Courses For Beginners

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.

Binary Code Explained for Beginners - Computer Science 101 Learn how binary code works with this step-by-step article for Computer Science and coding beginners

What is Binary Code?

So how does binary work then? How can a complex computer program consist of only 1’s and 0’s?

To simplify things just a little bit, 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 can do for us these days?

To shed some more light on this, let’s briefly think about what computers do.

Simply put,

  1. computers take inputs from their users,
  2. store and process them as information, and
  3. finally provide their users with outputs of various kinds.

For example, when you’re typing on your computer, your fingers hitting the keyboard are providing your computer with some input. Then, your computer magically knows how to translate certain keys into the desired letters and text. Finally, the output from your computer is the text it displays on your screen.

So what does this have to do with binary code?

Read also: Computer Science 101: What is a Computer?

Binary in Computer Science: What Do Computers Do With the 1’s and 0’s?

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. So 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.

Read also: How to Start Learning Coding? 6 Tips for Beginners

How Do Computers Store Information?

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.

Read also: Why Learn Coding? 12 Benefits From Learning Programming

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 1TB hard drive!

So it’s quite obvious that modern computers can do much more than decide whether to switch on a single light or not. Thus, even though binary code consists of only 1’s and 0’s, it can represent the most complex of computer programs these days.

Binary 101: 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. It 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…

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.

Binary code and binary number system explained: a simple example

So, with the number “216”, for example, we have a 6 representing the 1’s, a 1 representing the 10’s, and finally 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.

How to “decode” a binary number?

In the binary system, instead of using powers of 10, we use powers of 2. 

So, similarly 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:

  1. First digit stands for 20, so these are the 1’s
  2. Second digit: 21, these are the 2’s
  3. Third digit: 22, these are the 4’s
  4. Fourth digit: 23, these are the 8’s
  5. Fifth digit: 24, these are the 16’s
  6. Sixth digit: 25, these are the 32’s
  7. Seventh digit: 26, these are the 64’s
  8. Eighth digit: 27, these are the 128’s
  9. Ninth digit: 28, these are the 256’s
  10. etc.

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.

Binary numbers decoded: a simple example

So how would we represent the number we just saw in decimal notation, 216, in binary?

Let’s give it a go!

  1. 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.
  2. 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.
  3. Since 128 is “included” in our number, let’s indicate this by a “1” in the 128’s place in the image below.
  4. Then, let’s do a simple subtraction: 216 – 128 = 88.
  5. 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.
  6. Now, let’s subtract again: 88 – 64 = 24.
  7. 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.
  8. 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: 11011000.

As such, it 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:

Binary code and binary number system explained

So, we end up with the correct number that we wanted to display in binary.

Great success!

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 is all that matters!

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 all in all, 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 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!

Text in binary

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.

Images and graphics in binary

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!

Read also: 10 Reasons Why You Should Start an Online Coding Course

Where to Learn Computer Science Basics Online?

I hope you’re still with me!

Understanding how binary code works is a great start into learning Computer Science basics!

If you want to learn how to code, knowing what happens inside a computer makes learning programming much more efficient. You’ll find it easier to understand what your programs are doing when you code a certain series of instructions for your computer to execute.

To learn more about Computer Science basics online, I’ve gathered a few helpful courses I’ve taken myself (and that I shamelessly recommend!). If you’re just starting out with Computer Science or learning how to code in general, all of these courses are perfect for getting started!

1: Computer Basics (Treehouse)

Learning Computer Science Basics - Computer Basics Treehouse 01

If you’re in a hurry, Computer Basics at Team Treehouse is the perfect introduction to Computer Science.

In just under an hour, you will learn a bunch of Computer Science basics, including a refresher on binary code. You’ll take a look at the underlying concepts of how computers work and what’s happening behind the scenes when you run your computer programs.

You’ll learn the basics of data processing, how memory works, what binary means in CS, and how computer software works.

If you’re not familiar with Treehouse yet, simply try their free 7-day trial!

2: CS101 Bootcamp (Udemy)

Learning Computer Science Basics - CS101 Bootcamp Udemy 01

CS101 Bootcamp is another short but powerful beginner-level course on Udemy for learning Computer Science basics.

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 will be sufficient for this short 2-hour course.

At the end, 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.

3: Computer Science 101 (Udemy)

Learning Computer Science Basics - Computer Science 101 Udemy

Computer Science 101 on Udemy is a more thorough, comprehensive CS basics course for beginners.

This is definitely my #1 recommendation for Computer Science fundamentals for beginners.

If you’re looking to master CS theory – which is highly recommended for any programmer – this course is the perfect choice. Once you’re done, you will be familiar with how binary code works and be comfortable with analysing and using algorithms of various kinds.

4: Computer Science E-50 (Harvard College)

Computer Science E-50 of Harvard College is my favourite free CS basics course for beginners.

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: Computer Science E-75 (Harvard College)

Computer Science E-75 by the same professor is another excellent beginner-level course for learning Computer Science basics.

At the time of writing this, the most recent content is a few years old (from 2012). However, the fundamentals for the topics are still accurate.

Take a look at the very first lecture on how HTTP traffic works, for example. It is packed with helpful, useful information for anyone who surfs on the Web.

6: Intro to Computer Science (Udacity)

Learning Computer Science Basics - Intro to Computer Science Udacity

Intro to Computer Science at Udacity is another one of my favourites.

The course focuses on learning computer science basics for beginners and at the same time introduces you to plenty of practical projects using Python.

Some of the problem sets may seem a bit difficult if you’re a beginner.

However, if you get stuck you can check out the forum for some help from fellow students.

How does binary code work? Learn how binary code works in Computer Science with this step-by-step article for beginners

Final Thoughts: Binary Code Explained

I hope you are still with me!

I know this topic is somewhat abstract and it might be difficult to think of a situation where you would need to know how binary works.

When you write code and programs for your computer, you are not dealing with these binary numbers directly, really. However, you will be dealing with what all these 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.

Therefore, knowing how binary code works and what the binary system really means can help you understand how computers work on the inside.

They are the fundamental building block of everything your computer does:

  1. getting input,
  2. storing information,
  3. processing information, and
  4. producing outputs.

So, no matter how complex or sophisticated a computer program or system is, it all comes down just 1’s and 0’s.

Here are a couple of related articles you may find helpful, too:

If you liked this post on binary code and how binary works, drop me a line in the comments below!

P.S. If you found this article helpful, share it with others so that they can learn binary code, too! Thanks!

That’s all for today! Happy coding, catch you later!
– Mikke

Share this post with others:

About Mikke

Hi, I’m Mikke! I’m a blogger, freelance web developer, and online business nerd. Join me here on to learn how to code for free, build a professional portfolio website, launch a tech side hustle, and make money coding. When I’m not blogging, you will find me sipping strong coffee and biking around town in Berlin. Learn how I taught myself tech skills and became a web dev entrepreneur here. And come say hi on Twitter!

Leave a reply:

Learn to code for free - 15 coding tips for beginners – Free ebook