·5 min readComputer Science

How Does a Machine Execute Programs?

A beginner-friendly explanation of how computers process information: from binary and bytes to how text, images, videos, and audio are stored.

To solve problems on a computer, we need to know the language the computer understands and give it specific instructions to follow. But how does that actually work under the hood?

At the most basic level, a computer takes some input, performs instructions on it, and gives an output.

To give it instructions, we have to talk to it in binary, because binary is the only language hardware natively supports.


Wait, What Is Binary?

Binary is simply the language of 0s and 1s. Everything inside a machine is represented using only these two digits.

Each 0 or 1 in binary is called a bit (short for binary digit). So every single 0 or 1 is 1 bit.

Generally, how many bits a computer processes at once depends on the CPU architecture (like 32-bit or 64-bit systems). But to represent bits in a clean, standard manner for humans and systems, we group 8 bits together into 1 byte.

1 Byte = 8 Bits
Example: 01000001

So what can we actually represent with these bits and bytes? Numbers? Text? Images? Audio? How does that work?

Let’s break it down step by step.


The Decimal Number System (Base-10)

Ever since elementary school, we were taught the decimal number system, also called base-10.

Base-10 consists of 10 possible digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

When you see the number 123, you instantly know it is one hundred twenty-three. But why?

In base-10, each digit position represents an increasing power of 10, moving from right to left:

Position:      10^2        10^1        10^0
Value:         100         10          1
Calculation:   (1 * 100) + (2 * 10)  + (3 * 1) = 100 + 20 + 3 = 123

The rightmost digit represents 10^0, the next digit represents 10^1, then 10^2, and so on. That is how the decimal system works.


How Does Binary (Base-2) Work?

Just like decimal has 10 possible values per digit (0 to 9), binary has only 2 possible values per digit: 0 and 1.

Instead of powers of 10, binary numbers are calculated from right to left using powers of 2: 2^0, 2^1, 2^2, 2^3, and so on.

Position:      2^3    2^2    2^1    2^0
Power Value:   8      4      2      1

So how do we write decimal numbers in binary?

  • 0 in decimal = 00 in binary
  • 1 in decimal = 01 in binary (0 * 2^1 + 1 * 2^0)
  • 2 in decimal = 10 in binary (1 * 2^1 + 0 * 2^0)
  • 3 in decimal = 11 in binary (1 * 2^1 + 1 * 2^0)

When writing 2 as 10, the 1 means we used that 2^1 bit, and the 0 means we did not use the 2^0 bit.

By combining bits, you can represent any decimal number.


From Bits to Bytes

For small numbers, a few bits are fine. But when we need to handle larger amounts of information, working with individual bits gets messy.

To organize data cleanly, computer engineers group 8 bits into a byte.

With 8 bits in a single byte, you can make 256 unique combinations (2^8), representing numbers from 0 (00000000) all the way up to 255 (11111111).

A bit is the fundamental unit, while a byte is the practical standard combination we use to store information.


How Computers Store Text

Now, how does a computer store words and text?

Computers don’t know what letters look like. They only understand numbers.

To solve this, we use ASCII (and modern Unicode). Every character on your keyboard is assigned a unique number code.

Wait, how do we know which code is what?

We can look at their decimal and binary values:

Character Decimal Value 8-Bit Binary (Byte)
A 65 01000001
B 66 01000010
C 67 01000011
a 97 01100001
b 98 01100010

Capital letters start at 65 (01000001), and lowercase letters start at 97 (01100001).

Storing the Word “BA”

If you want to store the word “BA”, the computer writes it internally as a stream of bytes:

'B' = 66 = 01000010
'A' = 65 = 01000001

Byte Stream: 01000010 01000001

Internally, it is just two bytes sitting in memory next to each other. Fascinating, isn’t it?

Now, we might not need to think about this every day when writing high-level code, but as computer engineers, we must know how this works.


What About Images, Videos, and Audio?

Once you know how bytes work, representing media is surprisingly intuitive.

Images

Digital images are made of tiny dots called pixels.

For color images, each pixel is represented using RGB (Red, Green, Blue):

  • 1 Byte for Red (value 0 to 255)
  • 1 Byte for Green (value 0 to 255)
  • 1 Byte for Blue (value 0 to 255)
1 Pixel = 3 Bytes (Red + Green + Blue)

So for a raw, uncompressed image, if you have a 3 Megabyte (MB) file, that means the image contains roughly 1 Megapixel (1,000,000 pixels), because each pixel takes 3 bytes:

3,000,000 bytes / 3 bytes per pixel = 1,000,000 pixels (1 Megapixel)

Videos

A video is just a rapid sequence of these images displayed on your screen.

When a video runs at 30 frames per second (FPS), it simply means your screen is showing 30 distinct images every single second.

Audio

Audio works the exact same way. Sound waves are measured (sampled) thousands of times per second, and each measurement is recorded as a numeric byte value. When played back, those numbers tell the speaker how to vibrate to recreate the sound.


Wrapping Up

At the end of the day, everything inside a computer: numbers, text, images, videos, and sounds: boils down to streams of 0s and 1s grouped into bytes.

That’s it folks.