When we write a program, we usually think in terms of variables, functions, control structures, objects, databases, and algorithms. The higher the level of the language we use, the farther away the hardware responsible for executing our code seems to be.

Consider an extremely simple instruction in C:

x = x + 1;

For a programmer, its meaning is immediate: take the value stored in x, add one, and store the new result.

The processor, however, does not execute this expression directly.

Between the code we write and the electronic circuit that actually performs the operation, there are several layers of abstraction. The compiler transforms the program into instructions suitable for the processor architecture. Those instructions are encoded numerically. Internal circuits interpret those codes, move data between registers, and perform arithmetic operations.

Going deeper, we find logic gates.

Below them, transistors.

And at the physical level, electrical signals.

Understanding these layers helps remove some of the apparent magic from computing. A modern computer is extraordinarily complex, but many of its fundamental mechanisms emerge from combinations of relatively simple components and rules.

A Bit Is Not a Tiny Zero or One

We usually learn that computers work with 0 and 1. That is correct at the logical level, but it can lead to a misleading idea of what actually exists inside the machine.

Physically, there are no numerical zeros and ones traveling through the circuits.

What actually exist are physical quantities, such as electrical voltages, which circuits are designed to interpret according to certain ranges.

In a simplified model, we can imagine:

low voltage range  → logical state 0
high voltage range → logical state 1

The exact values depend on the technology being used and are not important for our discussion. The key point is different: 0 and 1 are abstract representations of distinct physical states.

This abstraction is extremely powerful.

Instead of constantly analyzing voltages, currents, capacitances, and semiconductor properties, we can move one level up and work with only two states:

0
1

Each unit capable of representing one of these two states is called a bit, short for binary digit.

A single bit can represent two possibilities.

Two bits can represent four:

00
01
10
11

Three bits can represent eight:

000
001
010
011
100
101
110
111

In general, n bits can represent 2ⁿ different combinations.

With eight bits, for example, there are 256 possible combinations.

These combinations can be used to represent numbers, characters, instructions, colors, memory addresses, and countless other forms of information.

But we still need to explain how a circuit can manipulate these states.

This is where transistors come in.

The Transistor as a Fundamental Building Block

A transistor is a semiconductor device capable of controlling the flow of electric current.

For an introduction to digital computing, a useful way to think about it is as a component in which one signal can control the behavior of another electrical path.

This property makes it possible to build circuits that respond predictably to their inputs.

By itself, a transistor performs relatively simple functions. Its importance appears when we begin combining many of them.

A group of transistors can be arranged to implement a logical operation.

Several of these circuits can then be combined to build larger circuits.

Those circuits can form adders, registers, arithmetic units, memory structures, and eventually complete processors.

There is therefore a progression:

transistors
     ↓
logic gates
     ↓
digital circuits
     ↓
functional units
     ↓
processor

Complexity emerges mainly through composition.

This principle appears constantly in computing: relatively simple components are organized into increasingly sophisticated structures.

From Electronics to Logic

When we stop looking at individual transistors and start analyzing the logical behavior of the circuits built from them, we enter the domain of logic gates.

A logic gate receives one or more binary values and produces an output according to a specific logical function.

Among the fundamental operations are:

NOT
AND
OR
XOR

The NOT operation, for example, inverts a value:

A | NOT A
--+------
0 |   1
1 |   0

An AND gate produces 1 only when both inputs are 1:

A B | A AND B
----+--------
0 0 |    0
0 1 |    0
1 0 |    0
1 1 |    1

The OR gate produces 1 when at least one input is 1:

A B | A OR B
----+-------
0 0 |   0
0 1 |   1
1 0 |   1
1 1 |   1

These tables are called truth tables.

Once again, it is important to distinguish between two levels.

The truth table describes logical behavior.

The transistors and their connections provide a physical implementation of that behavior.

This separation allows us to study digital circuits without constantly returning to semiconductor physics.

From Logic Gates to Arithmetic Operations

Perhaps one of the most interesting points appears when we realize that gates operating only with 0 and 1 can be used to build mathematical operations.

Consider the simplest possible addition of two bits.

There are four cases:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10

The last case is especially important.

In binary:

1 + 1 = 10

This means the result contains:

sum bit = 0
carry   = 1

Now observe the XOR operation:

A B | XOR
----+----
0 0 |  0
0 1 |  1
1 0 |  1
1 1 |  0

It matches the sum bit exactly.

Meanwhile, AND gives us:

A B | AND
----+----
0 0 |  0
0 1 |  0
1 0 |  0
1 1 |  1

This corresponds to the carry.

By combining an XOR gate and an AND gate, we can therefore build a circuit known as a half adder.

        A ─────┬──── XOR ───→ Sum
               │
        B ─────┘

        A ─────┬──── AND ───→ Carry
               │
        B ─────┘

Additional circuitry allows us to account for a carry coming from a previous position. This gives rise to a full adder.

Several full adders can then be connected together to add numbers made of multiple bits.

An operation such as:

0101
+
0011

can therefore be performed by a set of circuits operating on each binary position.

What we write in software simply as:

a + b

ultimately requires hardware capable of performing an equivalent operation.

Computing Is Not Only About Calculation

If a computer were made only of circuits that immediately transformed inputs into outputs, its capabilities would be quite limited.

We also need to be able to preserve information.

Some circuits are called combinational circuits. Their output depends essentially on their current inputs.

We can represent them like this:

input
  ↓
circuit
  ↓
output

Other circuits can maintain state.

In that case, their behavior can depend both on the current input and on what happened previously.

current input
      +
previous state
      ↓
   circuit
      ↓
new state

This ability lies behind components such as latches, flip-flops, and registers.

With them, the computer stops merely transforming signals instantly and gains the ability to preserve information from one moment to the next.

And that is essential for executing programs.

Registers: Small Storage Areas Inside the CPU

Inside a processor there are small storage units called registers.

They can temporarily hold values that are being used by CPU operations.

Imagine that we need to calculate:

result = a + b;

In an extremely simplified model, the processor could:

1. obtain the value of a
2. place a in a register
3. obtain the value of b
4. place b in another register
5. send both values to the addition unit
6. store the result

A real CPU may perform these tasks in a considerably more sophisticated way, but this model is enough to help us understand its basic structure.

Now we can begin to see something important:

storage + logic = computation

We need to represent data, preserve state, and apply transformations to it.

The ALU: Where Logic and Arithmetic Meet

A classic processor component is the Arithmetic Logic Unit, usually called the ALU.

It is responsible for performing various operations on binary values, such as:

addition
subtraction
AND
OR
XOR
comparisons
bit shifts

We should not imagine the ALU as one giant logic gate.

It is itself made of many smaller circuits.

Once again, composition appears:

transistors
     ↓
gates
     ↓
small circuits
     ↓
larger circuits
     ↓
ALU

The same principle applies to other parts of the processor.

How Does the Processor Know Which Operation to Perform?

So far, we know that the CPU contains circuits capable of performing operations.

But something must determine:

add these values
move this data
compare these numbers
access this memory location
jump to another instruction

This is where machine instructions come in.

Each processor architecture defines a set of operations that the hardware knows how to execute. This set is called an ISA, or Instruction Set Architecture.

An instruction may determine, for example, that a certain value should be added to another.

In a symbolic assembly representation, we might imagine something like:

add eax, 1

The processor, however, does not receive the characters:

a d d   e a x ,   1

Assembly is once again an abstraction designed for humans.

Each instruction has a specific binary encoding that the CPU can interpret.

So we can continue descending through the layers:

C code
   ↓
assembly
   ↓
machine code
   ↓
bits
   ↓
digital circuits

The Computer Does Not Literally “Understand” Bits Either

Here we encounter an important subtlety.

We often say:

The computer understands zeros and ones.

As an introductory explanation, this is useful.

But physically, that is not exactly what happens.

The processor does not look at the graphical symbol:

1

and conclude that it means something.

The symbols 0 and 1 are our way of representing binary states.

Inside the circuit, there are physical signals. The architecture is designed so that certain combinations of those signals produce specific behaviors.

A more precise statement would therefore be:

Digital hardware operates on physical states that we abstract as binary values.

This distinction between representation and physical realization appears throughout computing.

Fetch, Decode, Execute

In a conceptual description of a CPU, we can think of program execution as a cycle:

FETCH
retrieve an instruction
        ↓
DECODE
determine what it means
        ↓
EXECUTE
perform the operation
        ↓
next instruction

First, the CPU obtains an instruction from memory.

Then the circuits responsible for decoding determine which operation that sequence represents.

Next, the appropriate processor units perform the operation.

This model is a simplification. Modern processors use techniques such as pipelining, speculative execution, multiple execution units, out-of-order execution, and several levels of cache.

Even so, the fetch → decode → execute model remains extremely useful for understanding the fundamental behavior of a CPU.

Returning to Our x = x + 1

Now we can return to the expression from the beginning:

x = x + 1;

At the C language level, this looks like a single operation.

But we can imagine a sequence of abstractions:

x = x + 1
     ↓
compiler
     ↓
architecture instructions
     ↓
machine code
     ↓
internal CPU signals
     ↓
registers + ALU + control
     ↓
logic gates
     ↓
transistors
     ↓
electrical phenomena

It is important to note that this sequence does not mean there is a simple one-to-one translation from a line of C into a single machine instruction or into a fixed set of transistors.

Compilers may optimize code. Different architectures have different instruction sets. Modern processors may internally break some instructions into smaller operations.

The diagram is useful because it shows the layers of abstraction involved.

Software and Hardware Are Not Separate Worlds

Programmers work with abstractions every day.

A variable does not have to be treated as a set of physical storage cells.

An addition operation does not need to be rebuilt from logic gates every time.

A function does not require us to think about the electrical details of the processor.

That is precisely the advantage of abstraction.

Each layer hides the details of the one below it and provides new concepts to the layer above.

We can visualize this progression:

Physics
  ↓
Electronics
  ↓
Digital logic
  ↓
Computer architecture
  ↓
Machine code
  ↓
Assembly
  ↓
Languages such as C
  ↓
Software

The higher we go, the more we can think about complex problems without carrying all the details of the lower layers.

But the lower layers are still there.

Every piece of software must, at some point, be realized by a physical machine.

Conclusion

A modern computer contains billions of transistors and architectural mechanisms far more sophisticated than we can explore in a single introduction.

Even so, understanding its fundamental principles changes the way we look at software.

A bit stops being merely a zero or one and becomes an abstraction of physical states.

A logic gate stops being just a symbol in a truth table and becomes a behavior implemented electronically.

An addition operation stops being only the + operator and becomes connected to circuits capable of performing binary arithmetic.

An instruction stops being merely a word in assembly and becomes an encoding that triggers specific behaviors inside the processor.

And a language such as C can be understood as a layer that allows us to control the machine without dealing directly with every physical implementation detail.

In the end, one of the most fascinating ideas in computing may be this:

systems capable of executing extremely complex programs are built from combinations of relatively simple fundamental mechanisms.

Understanding those foundations does not mean abandoning modern abstractions.

It means understanding what those abstractions were built on.