How Computers Work: The Hardware Story Behind the Magic - Part 1

How Computers Work: The Hardware Story Behind the Magic - Part 1

How Hardware Components, Binary Systems, and Logic Gates Work Together to Process and Transform Data

Ibrahim Wael's photo
·

16 min read


Have you ever wondered what’s happening inside your computer when you press a key, click a mouse, or load a webpage?

So let's see how it works and why you need it.

💡
In this blog, I will talk about how the computer works in the hardware section, and inshallah, in the next post, I will talk about how it works in software and how it controls hardware with the operating system, so follow along.

Introduction: Why Understanding Computers Matters for Programmers

Understanding how a computer works is fundamental for a programmer because it provides a strong foundation to write efficient, optimized, and reliable code.

It's like having the latest car in the world but not being able to take advantage of its features because you don't know how it works and sometimes you might damage it. This is the case with a computer that doesn't have a good understanding of how it works from the inside for software engineers.

Some important reasons:

  1. Writing Efficient Code

    Programmers can write more optimized code by understanding how the CPU executes instructions and how memory is managed.

  2. Innovation

    Understanding the fundamentals allows programmers to innovate and push the boundaries of what is possible. They can create new algorithms, develop more efficient data structures, and improve existing technologies.

  3. Ability to Work Across Different Platforms

    Knowledge of computer architecture helps programmers adapt their code for different environments, such as embedded systems, high-performance servers, or mobile devices.

  4. Problem-Solving

    A solid grasp of computer science principles enhances problem-solving skills. Programmers can approach problems methodically and devise solutions that are both effective and efficient.

For programmers, learning how computers work is not just theoretical, it’s practical knowledge that leads to better performance, improved debugging, and the ability to create robust and efficient software.


What is a computer?

In order to know how a computer works, we must first know what a computer is.

A computer is a programmable electronic device that can accept data (input), process it, store it, and produce a result (output). At its core, a computer is designed to solve problems and automate tasks.

From calculating numbers to running complex simulations, computers are capable of performing a wide range of tasks, making them indispensable in modern life.

Computers is not just desktop computer or laptop, there are many types of computers like :

TypeExamplesPurpose
SupercomputersSummit, FugakuHigh-performance scientific tasks
Mainframe ComputersIBM Z-seriesEnterprise data management
Microcomputers (PCs)Desktops, laptops, workstationsPersonal or small business use
Embedded ComputersABS in cars, IoT devicesTask-specific use
Quantum ComputersGoogle Sycamore, IBM QuantumComplex problem solving
Mobile DevicesSmartphones, tabletsPortable personal computing
ServersWeb servers, file serversNetwork services

Now that we know that smartphones and other smart devices are computers, we need to know what makes a computer a computer.

What makes a computer, a computer?

To say about any device a computer should be

  • Programmability

    A computer can follow a set of instructions (a program) to perform a task.

    This makes it flexible and capable of doing many different things depending on the software.

  • Automation

    Once programmed, a computer can execute tasks without requiring manual intervention. It can perform repetitive tasks accurately and tirelessly.

  • Input-Storage-Process-Output Cycle

    A computer operates by taking in data (Input), stores information, processing it (Processing), and delivering results (Output).

After knowing what makes a computer a computer, you need to know how the components help it perform these actions.


Brief history about computer

Before knowing the components of the computer that help it work efficiently, we need to know the generations of computers and how the computer developed because it will help us understand things to come.
But not the history of the computer in the literal sense, so let's start

  1. First Generation: Vacuum Tube Computers (1940s-1950s)
    It’s simply a computer that uses vacuum tubes for logic circuitry.
    • Vacuum Tubes: These were the primary components used for switching and amplification.
    Components:
    ° Cathode: A heated filament that emitted electrons.

    ° Anode: A positively charged plate that attracted electrons from the cathode.

    ° Control Grid: A wire mesh between the cathode and anode that controlled the flow of electrons.

    Characteristics: Large, power-hungry, generated a lot of heat, used punched cards for input and output, and machine language for programming.

  2. Second Generation: Transistor Computers (1950s-1960s)

    Transistors replaced vacuum tubes, making computers smaller, faster, more reliable, and energy-efficient.

    The transistor greatly helped improve the devices at the time and reduced their area, which helped in higher efficiency.

    Characteristics: Smaller, more reliable, less heat generation, used magnetic tape and disks for storage, and assembly language for programming.

  3. Third Generation: Integrated Circuits (ICs)(1960s-1970s)

    An IC combined multiple transistors on a single silicon chip, drastically improving performance and reducing size.

    Characteristics: Even smaller, more powerful, more reliable, used keyboards and monitors for input and output, and high-level programming languages like FORTRAN and COBOL.

  4. Fourth Generation: Microprocessors (1970s-Present)

    • Microprocessors, invented by Intel in 1971 (Intel 4004), integrated the CPU onto a single chip.

    • This innovation made computers smaller, cheaper, and more powerful than ever before.

  1. Fifth Generation: Modern and Emerging Computers (1990s-Present)

    Technology: Artificial Intelligence (AI), Quantum Computing, and IoT

    Characteristics: Focus on AI and machine learning, natural language processing, advanced robotics, and quantum computing for solving complex problems.

In fact, many of my photos were not created by AI and now we rely on it for some things, and it saves us a lot of time and effort.


Components of computer

After knowing the history of the computer and how its components have developed until now, we will see some of the important parts of the computer.

Input Components

These devices allow data to enter the computer for processing.

  • Keyboard: For text input (letters, numbers, commands).

Storage Components

These components store data either temporarily or permanently.
Primary Storage (Volatile) ==> (RAM, Cache)
Secondary Storage (Non-Volatile) ==> HDD, SSD
Tertiary/Backup Storage ==> External Drives, Cloud Storage

Processing Components

These components handle the actual computation and logic operations.

  • CPU (Central Processing Unit): The "brain" of the computer, responsible for executing instructions and performing calculations.

  • ALU (Arithmetic Logic Unit): Performs arithmetic and logical operations within the CPU.

  • Control Unit: Directs the flow of data and instructions within the CPU.

  • GPU (Graphics Processing Unit): Specialized processor for rendering graphics and performing parallel processing tasks.

  • Motherboard: The central board connecting the CPU, RAM, storage, and peripherals, allowing communication between components.

Output Components

These devices display or present processed data in readable form.

  • Like Monitor, Printer, Speakers, Headphones, Projectors.

    Each part of the computer has a specific role in the process of input - storage - processing - output, but how these components work together and give us output is what we will see in the next topic.

😵
Now, if you are wondering why we start from what is a computer and then move to computer generations and then to computer components and not directly to the main topic, that is because we have to see the big picture first and then see the details also there are many things that will help us understand the details later in addition to the fact that there is a second part about how the software works and this will help in understanding it more 😁.

How Components Work Together

Computers are more than just a collection of components, they are a carefully orchestrated system where each part works in harmony to do tasks. Let’s explore how the main components help computer to input, storage, processing, and output interact to turn your commands into meaningful results.


Step 1: Input – Sending Data to the Computer

Everything begins with input. When you type on a keyboard, click with a mouse, or speak into a microphone, input devices capture your actions and convert them into data that the computer can understand.

Example:

  • Pressing a key on the keyboard sends a signal (an electrical pulse) to the computer, representing a specific code (e.g., the letter "A").

Step 2: Storage – Holding Data Temporarily or Permanently

Once data enters the computer, it needs to be stored. Depending on the task, this data may go into:

  • RAM (Random Access Memory): Temporary storage where data and instructions are kept while the computer is actively working on them.

  • Storage Drives (HDD/SSD): Permanent storage for files, programs, and operating systems.

RAM is a very important part of the computer components; it acts as temporary storage for the data and instructions that the CPU needs to access quickly. RAM is fast enough to keep up with the CPU’s processing speed, but not as fast as the CPU itself. If the RAM is too slow or not enough, it can cause a bottleneck, where the CPU has to wait for data to be fetched from the slower storage (like hard drives or SSDs), resulting in overall system slowdown.

Step 3: Processing – The CPU and GPU

The CPU (Central Processing Unit) is the brain of the computer. It fetches data from RAM, processes it based on the program's instructions, and sends the results back to storage or output devices.

For specialized tasks like rendering graphics, the GPU (Graphics Processing Unit) takes over, performing parallel calculations at incredible speeds.

Step 4: Output – Presenting Results

After processing, the results are sent to output devices like monitors (to display visuals), speakers (for audio), or printers (for physical copies).

This cycle continuously loops, ensuring the computer performs tasks effectively. But how does the computer handle the actual data? That’s where binary comes in.


All this cycle work in buses to exchange information call system bus.

System Bus :

The system bus is a set of physical and logical pathways (wires or circuits) used for transferring data between the CPU, memory (RAM), input/output devices, and other components of the computer.

  • Data Bus: Transfers the actual data.

  • Address Bus: Carries the addresses of where the data should be read from or written to.

  • Control Bus: Sends control signals to coordinate operations between the CPU, memory, and other components


How computer deal with data (binary system)?

Computers process and store information using electrical signals (Binary).
These signals are either:

  • High voltage (1)

  • Low voltage (0)

This simplicity makes binary ideal for digital systems, as it translates directly into the physical state of hardware.

Binary Units of Data

The binary system builds everything in computers using combinations of bits (binary digits).

  • 1 bit: The smallest unit, representing 0 or 1.

  • 8 bits: Form a byte, which can represent a character like "A" or "B."

  • Larger Units: Kilobytes (KB), Megabytes (MB), Gigabytes (GB), etc., represent more data.

you may say that how only o and 1 is fundamental of computer system, but it’s not only 0,1 ,it make combinations of 0’s and 1’s .

I will take a closer look at the binary system in number system .

I make this example for simplification :

Only take the 1's bit, because 0 * n = 0

Why Binary?

Why Do Computers Use Binary?

Binary is used because it is simple and reliable. Electronic components, like transistors, can easily represent two states: on (1) and off (0). This simplicity reduces the chances of errors and makes it easier to design and build complex circuits.

Number system

There are many number systems like

Binary (Base 2)

  • Used by Computers: All data in computers is stored and processed in binary.

  • Digits: Only 2 digits, 0 and 1.

  • Example: Binary 1011 → Decimal (1×2³) + (0×2²) + (1×2¹) + (1×2⁰) = 11

Decimal (Base 10)

  • Used by Humans: The most familiar number system, based on 10 digits (0–9).

  • Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

Octal (Base 8)
  • Used in Early Computing: Compact way to represent binary numbers before hexadecimal became popular.

  • Digits: 0–7.

  • Example:

    • Binary 110010 is 62 in octal.
Hexadecimal (Base 16)
  • Used by Programmers: A shorthand way to write binary numbers, often seen in memory addresses or color codes.

  • Digits: 0–9 and letters A–F (where A = 10, B = 11, ..., F = 15).

  • Example:

    • Binary 11111111 is FF in hexadecimal.

Encoding Data - text (ASCII, Unicode) and images (pixels, RGB)

Encoding Data: Turning Information into Binary

To store, process, and transmit information, computers need to encode all types of data like text, images, audio, and more into binary form. Let’s explore how this encoding works for text and images, two of the most fundamental types of data.

We know that binary can represent numbers as we explain before but what about text and other types ?

Encoding Text: ASCII and Unicode

Text encoding converts characters (like letters, numbers, and symbols) into a format that computers can process. Two widely used systems are ASCII and Unicode.

ASCII and Unicode: The Same but Different

Both ASCII and Unicode are character encoding systems, meaning they map characters (like letters, numbers, and symbols) to numeric values that computers can understand. However, they differ in their range, purpose, and implementation.

  1. ASCII (American Standard Code for Information Interchange)

A character encoding standard that uses 7 bits to represent 128 characters.
These include: Uppercase and lowercase letters (A-Z, a-z), Numbers (0-9),
Basic symbols (!, @, #, etc.).

Example:

  • The letter "A" is encoded as 01000001 in binary.

  • The symbol "@" is encoded as 01000000.

Limitations:
ASCII can only represent 128 characters, which is insufficient for non-English languages or special symbols.

  1. Unicode : A more comprehensive encoding standard that can represent over 1 million characters from nearly every writing system worldwide.

    Unicode assigns a unique code point to each character and uses multiple encoding formats, such as:

    • UTF-8: A variable-length encoding that uses 1 to 4 bytes per character.

    • UTF-16: Uses 2 or 4 bytes per character.

Encoding Images: Pixels and RGB

Images are represented as a grid of tiny blocks called pixels. Each pixel is assigned a specific color, which is stored in binary form.

  1. Pixels and Resolution
    • Pixels: The smallest unit of an image. An image's quality depends on its resolution, measured in pixels (e.g., 1920x1080).

    • Binary Representation: Each pixel's color is encoded in binary.

  1. RGB Color Model
    • What It Is: RGB stands for Red, Green, and Blue, the three primary colors of light used to create all other colors, I think every programmer who deals with colors knows RGB, especially web developers.

    • How It Works: Each color channel (R, G, B) is assigned a value between 0 and 255 (1 byte each), representing the intensity of that color.

Now we know how a computer reads images but how does it store them?

Storing Image Data
  • Bitmap Images: Store color information for each pixel individually, leading to larger file sizes.

  • Compressed Formats (JPEG, PNG): Use algorithms to reduce file size by identifying patterns in pixel data.

Why Encoding Matters

  • Encoding ensures compatibility between devices and systems.

  • It allows computers to store and transmit data efficiently.

  • Standards like Unicode enable global communication and multimedia representation.

Now that we understand binary and number systems, it’s time to explore how computers use logic gates to perform tasks. Logic gates, combined into circuits, are the foundation of a computer's ability to process data and execute instructions.


Circuits & Logic gates

Logic gates are simple electronic circuits that take one or more binary inputs (0 or 1) and produce a binary output based on a logical operation. They are the core components of digital circuits and enable computers to make decisions, perform calculations, and process data.

  • Input: One or more binary values (0 or 1).

  • Output: A single binary value (0 or 1), determined by the gate's logic.

🖥
I will talk about digital engineering as soon as possible and of course the details of logic gates and their importance.

What Are Circuits?

A pathway that allows electricity to flow, enabling the computer to perform various functions. These circuits are made up of electronic components like resistors, capacitors, transistors, and diodes. They are etched onto silicon chips to create integrated circuits (ICs), which are the building blocks of modern computers.

  • Electric Signals: Computers process data by manipulating electrical signals (high voltage = 1, low voltage = 0).

  • Two Types of Circuits:

    • Analog Circuits: Handle continuous signals (used in older devices like radios).

    • Digital Circuits: Handle discrete signals (binary) and are the foundation of modern computers.

💡
We are talking about digital circuits not analog circuits.

How Do Logic Gates Work?

Each logic gate operates based on a specific Boolean function (AND, OR, NOT, etc.). Boolean logic works with binary states:

  • 0 = OFF

  • 1 = ON

Types of logic gates and their functions:

Logic gates are gates that take input and the output be like the logic of it as truth table represented.

Truth Table: is a mathematical table used to represent the outputs of a logical operation, or a Boolean function based on all possible combinations of inputs.

So, truth table represent all possible combinations of inputs as all gates except NOT gate have 4 Probability but NOT have only 1 input which is convert the input status, so it’s have only 2 combinations.

How Circuits and Logic Gates Work Together

  • Logic gates are combined to form logic circuits, which execute specific tasks

  • These circuits are arranged in hierarchical structures to form the Arithmetic Logic Unit (ALU) in the CPU, which performs all mathematical and logical operations.

Example:
A simple circuit using an AND gate and a NOT gate can implement a basic decision like "Turn on the fan only if the room is NOT cold and someone is present."

Here the fan not turn on until room is NOT cold and someone is present .
which mean both conditions must be 1 .

Real-World Applications of Logic Gates

  • Addition and Subtraction: Binary addition is performed using circuits called adders, which combine AND, OR, and XOR gates.

    using logic gates to make summation by making a combination of logic gates to make adder circuit .

    This is a picture of the logic circuit and its truth table.

  • Decision Making: Logic gates help determine whether conditions are met in programs.
    Use it in our life and in if conditions for programmer 😆.

Circuits and logic gates are the invisible workers of a computer, converting binary instructions into actions. Understanding how these components function provides insight into the magic behind computations, from simple operations like toggling a light switch to complex tasks like running an operating system.

conclusion

Understanding how computers work helps us see how simple principles, like the binary system and logic gates, create the powerful machines we use every day. Each component input, processing, storage, and output works together to turn data into results.

For programmers, knowing how computers handle data and perform tasks makes it easier to write better code, debug problems, and create innovative solutions. By learning the basics, we gain the tools to make the most of what computers can do.

In the next part of this series, we’ll explore the software side, focusing on operating systems and how they connect hardware to the programs we use every day.

Stay tuned for Part 2, where we unravel the magic behind software and how it powers the modern computing experience!

References