Computer Fundamentals and Introduction to Programming · Lecture Notes

Chapter 1.2: Computer Hardware

Every program written on a computer ultimately runs on physical parts you can touch. The processor executes instructions, memory holds the data in use at that moment, and the storage device keeps data permanently; the keyboard and the screen form the bridge between the user and the machine. These notes explain what each of these parts does, how they communicate with one another, and which numbers to look at when choosing a computer. Most topics are supported by small calculations: the length of a clock cycle from the clock speed, the time a cache saves, the pixel density of a screen, how many seconds a file takes to copy, and how many watts a power supply must deliver. These calculations make it easier to see what the numbers in technical specifications mean.

Learning outcomes

Components
Explain the functions of the basic hardware parts (processor, motherboard, RAM, ROM, graphics card, power supply, case).
Comparison
Distinguish RAM, ROM, HDD, and SSD within the memory hierarchy; show, by counting hits and misses, why a cache speeds things up.
Choosing devices
Choose input and output devices according to their purpose; calculate and interpret values such as resolution, pixel density, refresh rate, and storage speed.
Compatibility
Evaluate whether components fit together in terms of connection, power, physical size, and heat.

1.2.1What is hardware?

When people hear “computer,” most first think of the screen, the keyboard, and the case. These are the visible face of the computer. Inside the case are the processor, the memory modules, the storage device, the power supply, and the motherboard that connects them all. This section draws the general picture of these parts. Each part is treated separately in the following sections.

1.2.1.1Hardware and software

A computer system consists of two layers. The first layer is the physical parts: things you can touch, plug in and unplug, and replace when they break. The second layer is the instructions that tell these parts what to do. The first layer is called hardware, the second software.

Definition 1.2.1

Hardware is all the physical parts of a computer system: the processor, memory, storage devices, motherboard, power supply, case, input and output devices, and the cables that connect them. Software is the programs that determine which operations these parts perform and in what order.

Hardware and software complete each other. Without software, hardware does nothing; even the fastest processor waits when it is given no instructions. Without hardware, software cannot run either, because a physical medium is needed to execute the instructions, hold the data, and show the result. It is like the relationship between a music player and a song: the player is hardware, and the notes of the song are software.

Every task a computer performs consists of five basic steps. Figure 1.2.1 shows these steps and the hardware part that handles each of them:

  • Input devices bring data into the system. A key pressed on the keyboard, a movement of the mouse, and sound reaching the microphone are each an input.
  • The CPU (central processing unit) processes instructions: it adds, compares, and decides.
  • RAM holds the running program and the data in use at that moment. The processor reads data from here and writes results back here.
  • The storage device (SSD or HDD) keeps data permanently. Its contents are preserved even when the computer is switched off.
  • Output devices present the result to the user: an image on the screen, a sound from the speaker, a page from the printer.
Inputkeyboard, mouseCPUControl unitALURegistersOutputscreen, printerRAM (main memory)Storage (SSD)buses
Figure 1.2.1: The flow of data in a computer. Data from the input devices reaches the CPU. Inside the CPU are the control unit, the arithmetic logic unit (ALU), and the registers. The CPU constantly exchanges data with RAM; RAM works in both directions with the storage device. The result is sent to the output devices. The connections between the parts are called buses.

The two-way arrows in Figure 1.2.1 are important. Traffic between the CPU and RAM runs both ways: the processor reads both instructions and data from RAM and writes its results to RAM. Between RAM and storage, too, data flows both ways. When a program is opened, its file is copied from storage to RAM; when a document is saved, the changes are written from RAM to storage. This flow is followed step by step in 1.2.9.1 on a document being opened and saved.

Example 1.2.1

In a calculator program, 12 + 30 is typed and Enter is pressed. The five steps run as follows:

  1. Input. The keyboard turns each key press into a numeric code and sends it to the computer: first 1, 2, then +, 3, 0, and Enter.
  2. Memory. The calculator program is already in RAM. The pressed keys are also written to the program’s variables in RAM.
  3. Processing. When Enter arrives, the CPU executes the program’s addition instruction. It moves the numbers 12 and 30 from RAM into registers, adds them in the ALU, and gets the result 42.
  4. Output. The program sends 42 to the graphics card to be displayed; the monitor shows the result.
  5. Storage. No permanent record is needed in this example. If the program keeps past calculations in a file, the result is also written to the SSD.

As can be seen, even the simplest task requires several hardware parts to work together.

Common mistake

Taking “memory” and “storage” to be the same thing. In everyday speech both may be called “memory,” but their jobs differ. RAM is the temporary space the program uses while running, and it is emptied when the power goes off. Storage (SSD, HDD) is where files stay permanently. In the sentence “the computer has 16 GB of memory and 512 GB of storage,” two separate parts are meant.

1.2.1.2Hardware groups

Computer hardware can be arranged into six groups by function. This grouping helps one quickly see what role a part plays in the system.

Table 1.2.1: Hardware groups and examples.
GroupExamplesFunction
System componentsCPU, motherboard, RAM, GPU, power supply, caseprocesses instructions, connects and powers the parts
Input deviceskeyboard, mouse, microphone, camera, sensorsbring data into the system
Output devicesmonitor, printer, speaker, projectorpresent the result to the user
StorageHDD, SSD, USB flash drive, memory card, optical disckeeps data permanently
Network hardwarenetwork card, switch, router, access pointconnects computers to one another
ConnectionsUSB, HDMI, DisplayPort, audio and network portsphysically connect devices to the system

A few names in network hardware should be explained briefly. A network interface card (NIC) lets the computer connect to a wired or wireless network. A switch is the box that connects the devices on the same local network. A router directs traffic between different networks, for example between a home network and the internet. An access point lets wireless devices join the wired network.

Input deviceskeyboard, mouseSystem componentsCPU · RAM · motherboardGPU · power supply · caseOutput devicesmonitor, printerStorageNetwork hardwareportportConnections (USB, HDMI, network port) attach the devices to the system
Figure 1.2.2: How the hardware groups relate. Input devices give data to the system components; the system components send the result to the output devices. Storage and network hardware work in both directions with the system. Devices are attached to the system through ports.

Figure 1.2.2 summarizes the flow of data between the groups. Input and output devices are one-way: one brings data in, the other sends it out. Storage and network hardware both read and write. A file is read from an SSD, and a file is written to the same SSD. A network card both receives and sends data. This distinction is the basis of the input–output classification in 1.2.8.1.

1.2.2The central processing unit

The processor is the part of the computer that executes instructions. Every line of a program ends up as very simple instructions the processor understands: add two numbers, read a value from memory, compare two values, jump to another instruction depending on the result. The processor’s power comes from being able to execute these simple instructions billions of times per second.

1.2.2.1The processor’s job: fetch, decode, execute

Definition 1.2.2

The central processing unit (CPU), or simply the processor, is the hardware unit that fetches program instructions from memory, decodes what they mean, and executes them. This three-step loop is called the fetch–decode–execute cycle.

The steps of the cycle are as follows:

  1. Fetch. The processor takes the next instruction from memory. A special register keeps track of which instruction is next.
  2. Decode. What the instruction asks for is determined: an addition, a comparison, a read from memory? Which values are to be used?
  3. Execute. The requested operation is performed and the result is written to a register or to memory. Then the cycle starts again with the next instruction.

Three parts inside the processor run this cycle:

  • The arithmetic logic unit (ALU) performs arithmetic operations (addition, subtraction) and logical operations (comparison, “and,” “or”).
  • The control unit manages the order of the instructions and the flow of data. It decides which data goes to the ALU and where the result is written.
  • Registers are very small, very fast storage cells inside the processor. The values the ALU is working on at that moment sit in the registers.
Processor chipCore 1Control · ALUregisters · L1/L2Core 2Control · ALUregisters · L1/L2Core 3Control · ALUregisters · L1/L2Core 4Control · ALUregisters · L1/L2Shared L3 cache
Figure 1.2.3: A four-core processor chip. Each core has its own control unit, ALU, registers, and L1/L2 cache. The L3 cache is shared by all cores.

Today’s processors contain several cores on a single chip (Figure 1.2.3). Each core is a complete processing unit that can run the fetch–decode–execute cycle on its own. The cache (L1, L2, L3) in the figure is fast memory that keeps frequently used data right next to the processor; it is covered in detail in 1.2.4.

No single number determines a processor’s performance. Four factors play a role together: the number of cores, the clock speed (GHz), the size of the cache, and the processor’s architecture, that is, its internal design. Of two processors with the same clock speed, the newer-generation one can be noticeably faster because it does more work in each cycle.

Example 1.2.2

Memory holds the values x = 5 and y = 7. The line z = x + y turns into roughly four simple instructions in the processor. Each instruction runs with a fetch–decode–execute cycle:

InstructionDecode: what is asked?Execute: result
1read x from memory into register R1R1 = 5
2read y from memory into register R2R2 = 7
3add R1 and R2, write to R3 (ALU)R3 = 12
4write R3 to memory, in the place of zz = 12

The ALU does the addition; in the read and write instructions, the control unit moves data between memory and the registers. A single line of addition takes four cycles. These steps can be followed one by one in the Simple CPU simulator.

1.2.2.2Clock speed

Everything inside the processor proceeds to a rhythm. A clock signal sets this rhythm: the signal rises and falls at regular intervals, and at each rise the processor’s circuits advance one step. Think of it as the conductor’s beats in an orchestra; all the instruments play to the same beat.

Definition 1.2.3

Clock speed is the number of cycles the clock signal makes in one second, and it is measured in hertz (Hz). 1 GHz (gigahertz) is 109 cycles per second, that is, 1 billion cycles. The duration of one cycle is called a clock cycle:

duration of one cycle = 1 ÷ clock speed

It is easy to see where this formula comes from. If 3 billion cycles are made per second, 1 second is divided into 3 billion equal parts; each part is 1/3,000,000,000 of a second. For such tiny durations the nanosecond (ns) is used: 1 ns = 10−9 s, one billionth of a second.

Example 1.2.3

How long does one clock cycle take on 3 GHz and 3.2 GHz processors? If the 3.2 GHz processor finished each instruction in 4 cycles on average, how many instructions would it execute per second?

  1. 3 GHz. 3 GHz = 3 × 109 cycles/s. One cycle: 1 ÷ (3 × 109) s = 0.333… × 10−9 s ≈ 0.33 ns.
  2. 3.2 GHz. 1 ÷ (3.2 × 109) s = 0.3125 × 10−9 s = 0.3125 ns.
  3. Number of instructions. 3.2 × 109 cycles are made per second and each instruction takes 4 cycles: 3.2 × 109 ÷ 4 = 0.8 × 109 = 800 million instructions/s.

A comparison shows how short a cycle is: in 0.33 ns even light travels only about 10 cm.

A processor with a higher clock speed is not always faster. A processor’s speed is determined by the clock speed multiplied by the amount of work done in each cycle. New architectures can advance several instructions at once in one cycle. So a new 3 GHz processor can be faster than an old 4 GHz one. Moreover, clock speed is not fixed: when the processor is idle it slows down to save energy, and under load it speeds up as far as temperature allows.

Common mistake

Comparing processors of different generations or different manufacturers by GHz alone. GHz is meaningful when comparing two processors in the same family. Because the work done per cycle differs across architectures, the comparison becomes misleading; measurements taken on a real workload are more reliable.

1.2.2.3Cores

Definition 1.2.4

A core is a unit inside the processor that can execute an independent stream of instructions. A multicore processor can run several instruction streams at the same time.

The sequence of instructions a program executes is called a thread. A single-threaded program executes its instructions in one line; it cannot split this line and distribute it to different cores. A program split into several threads, on the other hand, can use the cores at the same time. A video-conversion program can give different minutes of the film to different cores. Typing a letter in a text editor, however, is not big enough to be split.

Clock (3 GHz)1 cycle ≈ 0.33 ns1 corejob Ajob Bjob Cjob D4 coresjob Ajob Bjob Cjob D4 times shorter (if the jobs are independent)
Figure 1.2.4: The clock signal and cores. At 3 GHz one cycle takes about 0.33 ns. Four independent jobs (A, B, C, D) run one after another on a single core and at the same time on four cores; if the jobs are independent, the total time falls to a quarter.

Figure 1.2.4 shows when many cores are useful: the jobs must be independent of one another. If the result of one job is needed as input by another, the second must wait for the first, and two cores cannot work together. Different programs running at the same time (a browser, a music player, an antivirus scanner), on the other hand, are naturally independent; the operating system distributes them across different cores.

Example 1.2.4

There are 7 independent jobs, each taking 5 seconds on a single core. The jobs cannot be split, and a core runs only one job at a time. What is the total time on a 3-core processor?

  1. First 5 seconds. Three jobs are given to the three cores (1, 2, 3). Four jobs wait.
  2. Seconds 5–10. The first three jobs finish and the next three (4, 5, 6) start. One job waits.
  3. Seconds 10–15. Only job 7 is left. One core works and two sit idle.

The total time is 15 s. On a single core it would have taken 7 × 5 = 35 s. The speedup is 35 ÷ 15 ≈ 2.3 times, not 3 times, because two cores are idle in the last round. The general rule: the number of rounds is the number of jobs divided by the number of cores, rounded up (7 ÷ 3 = 2.33 → 3 rounds).

Common mistake

Thinking “8 cores = 8 times the speed.” A single-threaded program uses one core even on an 8-core processor and does not speed up. The number of cores makes a difference only if the work can be split or if many programs run at the same time.

1.2.2.4Processor architectures and instruction sets

Each processor family understands a particular list of instructions. The complete set of instructions a processor understands is called its instruction set. The instruction set is the common language between the processor and software: two processors that understand the same instruction set can run the same machine code. Two instruction sets stand out today:

  • x86-64: Common in desktop, laptop, and server computers. Intel and AMD processors use this instruction set.
  • ARM: Common in phones, tablets, and systems where energy efficiency matters; it is increasingly used in laptops as well. Companies such as Apple, Qualcomm, and MediaTek design ARM-based processors.

RISC-V should be mentioned as a third option. RISC-V is an open instruction set: no license fee is paid to use it. It is therefore becoming more and more common, especially in embedded systems and in research.

Source codethe same programcompile for x86-64compile for ARMx86-64 machine codeARM machine codeIntel, AMDApple, Qualcomm, MediaTekdoes not run directly
Figure 1.2.5: The same source code is compiled separately for two different instruction sets. x86-64 machine code runs on Intel and AMD processors, and ARM machine code on Apple, Qualcomm, and MediaTek processors. Code produced for one instruction set does not run directly on the other.

Figure 1.2.5 shows the difference between the source code a programmer writes and the machine code the processor runs. Source code is the form people read. A compiler translates this code into the machine code of a particular instruction set. If the same program is to run on two architectures, it is compiled twice. This is one reason a phone app does not run directly on a computer.

A brand or model name alone does not determine performance. Even if two processors come from the same manufacturer and have the same instruction set, their generations, power limits, and core designs can differ. A proper comparison is made on the workload to be used: office programs, games, and video processing benefit from different processor features.

1.2.2.5SoC, mobile processors, and NPUs

In a desktop computer, the processor, the graphics card, and the other controllers are mostly separate parts. A phone has no room for that, and battery life matters a great deal. The solution is to put all the units on a single chip.

Definition 1.2.5

A System-on-Chip (SoC) is a design in which the CPU, GPU, memory controller, and other units are gathered on a single chip. A neural processing unit (NPU) is a unit designed to speed up artificial intelligence computations at low power.

SoC: single chipCPUGPUNPUMemory controllerCamera/ISPModem, Wi-Fi
Figure 1.2.6: The components of a SoC: CPU, GPU, NPU, memory controller, camera image processor (ISP), and modem/Wi-Fi are on a single chip.

Having the units on one chip brings two gains. The first is saving space: a part small enough to fit inside a phone or a thin laptop. The second is saving power: data travels between units over short paths, and the energy spent on long connections between separate chips goes down. In most SoCs the RAM is a separate chip, but it is placed very close to the SoC, even inside the same package. The details vary from manufacturer to manufacturer.

The jobs an NPU speeds up are ones we meet often in daily life: recognizing voice commands, reducing noise in a photo, face recognition, instant translation. These jobs contain many small multiplications and additions of the same kind. The CPU can do them too, but the NPU finishes the same job with much less energy.

The energy efficiency of mobile processors is sometimes attributed to the ARM instruction set alone. Yet the efficiency gap comes not only from the instruction set but also from the design: the structure of the cores, the manufacturing technology, and power management also determine the result. This is why ARM-based chips have also begun to be used in laptops.

1.2.3Motherboard, RAM, and ROM

The processor cannot work alone. It reads its instructions and data from a memory, gets its electricity from the power supply, and sends its results to the graphics card and other units. The motherboard provides all these connections. This section covers the motherboard and two kinds of memory: RAM, which holds running programs, and ROM, where the firmware that manages the computer’s startup lives.

1.2.3.1The motherboard

Definition 1.2.6

The motherboard is the main circuit board that joins the components of the computer physically and electrically. The components communicate with one another through buses on the motherboard.

The motherboard can be compared to a city’s road network. The processor is the city center; memory, storage, and the graphics card are different districts. The wider and smoother the roads, the faster traffic flows. On the motherboard there is a separate slot or connection point for each component (Figure 1.2.7).

I/Oport8-pinCPUsocketDIMM (RAM)24-pinPCIe x16 (graphics card)PCIe x1 (expansion)M.2 (SSD)ChipsetSATA
Figure 1.2.7: The layout of the motherboard: CPU socket, DIMM slots for RAM, PCIe x16 slot for the graphics card, PCIe x1 slot for expansion cards, M.2 slot for an SSD, SATA connections, chipset, power inputs (24-pin and 8-pin), and the I/O ports on the rear panel.
Table 1.2.2: Main connection points on the motherboard.
PartFunction
CPU socketThe slot the processor is plugged into. It determines the supported processor family.
DIMM slotsHold the RAM modules.
PCIe slotsGraphics cards and other expansion cards are plugged in.
M.2 and SATAStorage devices (SSD, HDD) are connected.
ChipsetManages data traffic between ports and slots.
24-pin and 8-pinCarry electricity from the power supply to the motherboard and the processor.

The abbreviations in the table often appear in the specifications of computer parts. DIMM (dual inline memory module) is the name of the RAM module in desktop computers. PCIe (PCI Express) is the high-speed bus to which devices such as graphics cards and fast SSDs connect; suffixes such as “x16” and “x4” show how many lanes are used. A lane is one of the parallel channels of the bus; the more lanes, the more data is carried at once. M.2 is the form of slot into which small SSDs plug directly on the motherboard. SATA is the interface over which hard disks and older SSDs are connected by cable.

Another job of the motherboard is to determine compatibility. The CPU socket decides which processor can be fitted, the DIMM slots which generation of RAM can be used, and the chipset how many fast connections are supported at the same time. For this reason, when a computer is assembled part by part, the first decision is usually between the processor and the motherboard. Compatibility is treated as a whole in 1.2.10.1.

1.2.3.2RAM

Definition 1.2.7

RAM (random access memory) is the main memory in which running programs and the data they use are held. It is volatile: its contents are lost when the power goes off. “Random access” means that every memory cell can be reached directly by its address, without waiting in line.

To understand the structure of RAM, it helps to think of it as a very long row of lockers. Each locker has a number, its address, and each locker holds exactly one byte. A byte consists of 8 bits and can hold an integer from 0 to 255. When the processor wants to read a piece of data, it states the address, and memory returns the byte at that address. To reach address 1000 there is no need to walk through the addresses from 0 to 999; every address is reached in the same time.

RAM (8 GB)Operating systemBrowserText editorFreeaddress → contents (byte)1000721001101100210810031081004111100501006171007255
Figure 1.2.8: A moment in 8 GB of RAM. The operating system, the browser, and the text editor occupy separate regions of memory; part of it is free. Looking closer, every byte has an address: at address 1000 sits 72, at 1001 sits 101, at 1002 and 1003 sits 108, and at 1004 sits 111.

The numbers in Figure 1.2.8 were not chosen at random. Text is stored in memory as numbers; each character corresponds to a number. In the widely used ASCII encoding, 72 is “H,” 101 is “e,” 108 is “l,” and 111 is “o.” So the word “Hello” sits at addresses 1000–1004. Memory knows only numbers; whether these numbers are letters, colors, or sound samples is decided by the program that uses them.

Example 1.2.5

How does the value 72 at address 1000 sit in memory as 8 bits? How is the same value written in base 16?

  1. Binary. The place values of 8 bits from left to right are 128, 64, 32, 16, 8, 4, 2, 1. Let us write 72 as a sum of these values: 72 = 64 + 8. The 64 and 8 positions become 1 and the others 0: 01001000.
  2. Check. 0·128 + 1·64 + 0·32 + 0·16 + 1·8 + 0·4 + 0·2 + 0·1 = 64 + 8 = 72.
  3. Hexadecimal. The 8 bits are split into two groups of four: 0100 and 1000. Since 0100 = 4 and 1000 = 8, 72 is written 48 in base 16 (in programming often 0x48).
  4. The largest value. When all eight bits are 1, 11111111 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255; its hexadecimal form is 0xFF. The 255 at address 1007 in Figure 1.2.8 is therefore the largest value a byte can hold.

Four properties of RAM directly affect everyday use of a computer:

  • Volatility: The contents are lost when the power goes off. This is why an unsaved document disappears in a power cut.
  • Fast access: The CPU reaches every address directly. Access to RAM takes about 50–100 ns; this is thousands of times faster than storage devices.
  • Capacity: The size of RAM determines how many programs can comfortably run at the same time. 8–64 GB is common in today’s computers.
  • Compatibility: The generation of the RAM module (DDR4, DDR5), its speed, and the motherboard’s support must match.

What happens when RAM runs out? When there is no room left in RAM, the operating system writes some of the data that has not been used for a while to disk and frees the space. The area on disk used this way is called swap space, or the page file on Windows. When needed, the data is read back from disk. Because the disk is much slower than RAM, the computer slows down noticeably. Even if there is plenty of free space on the disk, nothing changes: the cause of the slowness is not lack of space but the speed of the disk.

Common mistake

Looking only at free disk space on a computer that has slowed down. Even if the storage device is almost empty, when RAM is insufficient the system uses the disk as temporary memory and programs slow down. In this case the remedy is not the disk but more RAM, or running fewer programs at the same time.

1.2.3.3ROM and firmware

When a computer is turned on, RAM is empty. The operating system sits on the disk, but no software yet runs that can read the disk, start the screen, or recognize the keyboard. This “first step” problem is solved by a small piece of software that sits in a permanent memory on the motherboard.

Definition 1.2.8

ROM (read-only memory) is memory whose contents are not lost when the power goes off. Firmware is low-level software that manages the basic behavior of the hardware. In computers the firmware is called the BIOS, or UEFI, the newer standard that has replaced it.

Although the name ROM means “read-only,” today firmware is mostly kept in rewritable flash memory. Flash memory also keeps its contents when the power goes off, but it can be rewritten when necessary. This allows the firmware to be updated.

The startup of a computer proceeds roughly in this order:

  1. The power button is pressed; the processor starts running the UEFI that sits on the flash chip on the motherboard.
  2. UEFI tests and initializes the hardware: RAM, graphics card, keyboard, and storage devices are recognized. This test is called the power-on self-test (POST).
  3. UEFI scans the disks according to the boot order given in the settings and finds the program (the boot loader) that will start the operating system.
  4. The boot loader loads the operating system from disk into RAM and hands control over to it.

A firmware update can be made to recognize a new processor, fix a compatibility problem, or close a security hole. It needs care, however: if the power goes off during the update, the software in the flash memory may be left half-written and the computer may fail to start. So an update is made only when necessary and with uninterrupted power.

Common mistake

Confusing ROM with RAM because their names are similar. RAM is volatile and holds the running programs; its size is measured in gigabytes. ROM (flash) is permanent and holds only the startup software; its size is a few tens of megabytes. The first software that runs when the computer is turned on sits not in RAM but in this permanent memory.

1.2.4The memory hierarchy and the cache

An ideal memory would be very fast, very large, and cheap all at once. There is no such memory. Fast memory technologies are expensive and stay small; large, cheap memories are slow. Computers solve this problem by using several different memories together in layers.

1.2.4.1The memory hierarchy

Definition 1.2.9

The memory hierarchy is the arrangement of the kinds of memory in a computer into layers by speed and capacity. The upper layers (registers, cache) are fast, small, and expensive; the lower layers (RAM, SSD, HDD) are slow, large, and cheap.

Registers< 1 nshundreds of bytesCache (L1–L3)1–10 nsKB – tens of MBRAM50–100 ns8–64 GBSSD~0.1 ms0.25–4 TBHDD5–10 ms1–20 TBExternal / archivesecondsTB and moreaccess timetypical capacityfaster,more expensivelarger,cheaper
Figure 1.2.9: The memory hierarchy pyramid. Going up, access gets faster, capacity gets smaller, and the cost per byte rises. The values are approximate.
Table 1.2.3: Approximate access times and typical capacities of the memory layers.
LayerAccess timeTypical capacityNon-volatile?
Registers< 1 nshundreds of bytesno
Cache (L1–L3)1–10 nsKB – tens of MBno
RAM50–100 ns8–64 GBno
SSD≈ 0.1 ms0.25–4 TByes
HDD5–10 ms1–20 TByes
External / archivesecondsTB and moreyes

The hierarchy works because programs do not use memory in a disorderly way. Within a short time a program mostly works with the same small set of data: a loop reads the same variables again and again, and an array is walked through in order from start to end. If this small set is kept in the upper layers, the great majority of the processor’s requests are served from the fast layer. The slow layers are visited only rarely.

The last column of the table also shows an important distinction. RAM and the layers above it are volatile; SSD and the layers below it are non-volatile. While working on a document, the changes sit in RAM; only the “Save” command writes them to the non-volatile layer.

1.2.4.2Speed differences between layers

The differences between access times are so large that a special scale is needed to show them on the same line. Figure 1.2.10 uses a logarithmic scale: each grid line on the axis is 1,000 times the previous one (1 ns, 1 µs, 1 ms). That way nanoseconds and milliseconds fit in the same figure.

1 ns1 µs1 msaccess time (logarithmic scale)Register< 1 nsL1 cache1–3 nsL2 cache3–10 nsRAM50–100 nsSSD~0.1 msHDD5–10 ms
Figure 1.2.10: Access times of the memory layers on a logarithmic scale. A register takes less than 1 ns, the L1 cache 1–3 ns, the L2 cache 3–10 ns, RAM 50–100 ns, an SSD about 0.1 ms, and an HDD 5–10 ms.

Remembering how the units relate makes the calculations easier: 1 ms (millisecond) = 1,000 µs (microseconds) = 1,000,000 ns. So 0.1 ms is 100,000 ns.

Example 1.2.6

How many times slower is an SSD than RAM? How many times slower is an HDD than an SSD and than RAM?

  1. SSD versus RAM. SSD ≈ 0.1 ms = 100,000 ns. RAM is 50–100 ns. 100,000 ÷ 100 = 1000, 100,000 ÷ 50 = 2000. An SSD is about 1000–2000 times slower than RAM.
  2. HDD versus SSD. An HDD is 5–10 ms. 5 ÷ 0.1 = 50, 10 ÷ 0.1 = 100. An HDD is 50–100 times slower than an SSD.
  3. HDD versus RAM. 5 ms = 5,000,000 ns and 10 ms = 10,000,000 ns. The smallest ratio is 5,000,000 ÷ 100 = 50,000 and the largest is 10,000,000 ÷ 50 = 200,000. An HDD is 50,000–200,000 times slower than RAM.

Bringing this gap to an everyday scale builds intuition. If a read from RAM took 1 second, a read from an SSD would take about 17–33 minutes, and a read from an HDD between 14 hours and 2.3 days.

These ratios explain why the processor wants to read data not from disk but from RAM, and if possible from the cache. Even RAM is slow compared with one clock cycle of the processor: at 3 GHz a cycle is 0.33 ns, and waiting for a value from RAM takes about 150–300 cycles. The cache exists to reduce this waiting.

1.2.4.3The cache: hits and misses

Definition 1.2.10

The cache is a small, fast memory that keeps copies of frequently used data next to the processor. If the data the processor asks for is found in the cache, this is called a hit; if it is not found, a miss. On a miss the data is fetched from RAM and a copy is written to the cache.

The working rule of the cache is simple. When the processor wants to read an address, it first looks in the cache. If the data is there, it is obtained in about 1 ns. If not, it goes to RAM; this takes about 80 ns. The data coming from RAM is not only handed to the processor but also copied into the cache. Moreover, the neighboring bytes next to the requested byte are brought along with it, because the next request is expected to be, in all likelihood, to a neighboring address.

Figure 1.2.11 shows this rule at four moments on the memory contents of Figure 1.2.8. In this example the cache is filled in blocks of two addresses: 1002–1003, 1004–1005, and so on.

CPUregistersCache (≈1 ns)emptyemptyemptyemptyRAM≈ 80 nstotal time: 0 ns
CPUregistersCache (≈1 ns)1002: 1081003: 108emptyemptyRAM≈ 80 nstotal time: 80 ns
CPUregistersCache (≈1 ns)1002: 1081003: 108emptyemptyRAM≈ 80 nstotal time: 81 ns
CPUregistersCache (≈1 ns)1002: 1081003: 1081004: 1111005: 0RAM≈ 80 nstotal time: 161 ns
Figure 1.2.11: Hit and miss in the cache, four moments from top to bottom. (1) The cache is empty; the CPU asks for address 1003. (2) Miss: 1003 is fetched from RAM in 80 ns and written to the cache together with its neighbor 1002. (3) 1003 is requested again: hit, the value 108 arrives in about 1 ns; total 81 ns. (4) 1004 is requested: it is not in the cache, a miss; the block 1004–1005 is fetched from RAM, and the total becomes 161 ns.
Table 1.2.4: Trace of the three requests in Figure 1.2.11 (hit ≈ 1 ns, miss ≈ 80 ns).
RequestIn the cache?ResultTimeTotalCache after the request
1003 (first)nomiss80 ns80 ns1002, 1003
1003 (again)yeshit1 ns81 ns1002, 1003
1004nomiss80 ns161 ns1002, 1003, 1004, 1005

The three requests took 161 ns with the cache. Without the cache each request would go to RAM and the total would be 3 × 80 = 240 ns. The gain comes from the second request: because the same address was requested again within a short time, there was no need to go to RAM.

Real caches are much larger than this example, but they are limited. When the cache is full, room must be made for a new block. Most caches evict the block that has gone unused for the longest time. In these small examples the question of space is ignored.

1.2.4.4The cache in an array sum: spatial locality

The cache’s bringing neighboring bytes along relies on a very common behavior in programs. When an array (a structure in which values of the same type are laid out one after another in memory) is walked from start to end, each element sits right next to the previous one. Let us count how much time this behavior saves on the sum of an eight-element array. The program is:

sum = 0
for each i = 0, 1, …, 7
    sum = sum + a[i]
// 4-byte integers, 16-byte line

The calculation uses these assumptions: an integer takes 4 bytes; each time, a 16-byte block is brought from RAM into the cache. This block is called a cache line. Since 16 ÷ 4 = 4, four elements fit in one line: a[0]…a[3] are in the first block and a[4]…a[7] in the second. A hit takes about 1 ns and a miss about 80 ns. The values of the array are 3, 1, 4, 1, 5, 9, 2, 6.

RAM3a[0]1a[1]4a[2]1a[3]5a[4]9a[5]2a[6]6a[7]block 0 (16 bytes)block 1 (16 bytes)Cache3141empty lineCPUmiss: 80 ns
RAM3a[0]1a[1]4a[2]1a[3]5a[4]9a[5]2a[6]6a[7]block 0 (16 bytes)block 1 (16 bytes)Cache31415926CPUmiss: 80 ns
RAM3a[0]1a[1]4a[2]1a[3]5a[4]9a[5]2a[6]6a[7]block 0 (16 bytes)block 1 (16 bytes)Cache31415926CPU
Figure 1.2.12: The cache in an array sum. At the top, a[0] has been requested and has missed; the whole of block 0 (a[0]…a[3]) has come into the cache. In the middle, a[4] has been requested and on the second miss block 1 (a[4]…a[7]) has come. At the bottom the loop has finished: both blocks are in the cache.
Table 1.2.5: Trace of the array sum. Each row shows the state after one loop step.
ia[i]BlockResultsumhitmissTime
030miss30180 ns
110hit41181 ns
240hit82182 ns
310hit93183 ns
451miss1432163 ns
591hit2342164 ns
621hit2552165 ns
761hit3162166 ns

Table 1.2.5 gives the result clearly: the sum is 31; of the 8 accesses, 6 are hits and 2 are misses. The time is 2 × 80 + 6 × 1 = 166 ns. Without the cache every access would go to RAM and take 8 × 80 = 640 ns. The cache has sped this loop up about 3.9 times. The average time per access has also fallen to 166 ÷ 8 ≈ 20.8 ns.

Definition 1.2.11

Spatial locality is the tendency of a program that accesses one address to access nearby addresses soon afterward. The cache’s fetching a whole line instead of only the requested byte exploits this tendency.

Example 1.2.7

What would the times be if the same array had 16 elements and were walked in two different ways? (a) The elements are read in order. (b) Only a[0], a[4], a[8], a[12] are read.

  1. (a) In order. The 16 elements spread over 4 blocks. The first element of each block misses and the remaining three hit: 4 misses, 12 hits. The time is 4 × 80 + 12 × 1 = 332 ns. Without a cache it would be 16 × 80 = 1280 ns.
  2. (b) Skipping by four. Each element read is in a different block, and each block is used only once. All 4 of the 4 accesses miss: 4 × 80 = 320 ns. The number of elements read has fallen to a quarter, but the time has hardly shortened at all.

When skipping, the neighboring elements the cache brings in are never used. The time per access is 332 ÷ 16 ≈ 20.8 ns in (a) but 80 ns in (b).

Common mistake

Thinking that as the number of elements read goes down, the time will shrink in the same proportion. In a system with a cache, what mainly determines the time is how many times RAM is visited. A few accesses to scattered addresses can take longer than many accesses to consecutive addresses.

1.2.4.5Multilevel caches: temporal locality

Real processors have several levels instead of a single cache. L1 is the smallest and fastest level and sits inside each core. L2 is larger but a little slower. L3 is the largest and slowest cache level; it is usually shared by all cores (Figure 1.2.3). The processor looks for a piece of data starting from the fastest level:

In L1?  Yes → read, done
In L2?  Yes → copy to L1, read
In L3?  Yes → copy to L2 and L1, read
Fetch from RAM → copy to L3, L2, L1, read

The search spends some time at each level; if the data is not found, it moves to the next level down. So the cost of a miss is the sum of the times of all the levels searched. In the example below, L1 ≈ 1 ns, L2 ≈ 3 ns, L3 ≈ 10 ns, and RAM ≈ 80 ns are assumed. At the start, L1 holds B, L2 holds C, and L3 holds B, C, and D; A is only in RAM. The processor will read addresses A, A, and D in turn.

CPUL1≈ 1 nsBL2≈ 3 nsCL3≈ 10 nsB, C, DRAM≈ 80 nsA, B, C, Deach level is larger and slower than the previous one
CPUL1≈ 1 nsA, BcopiedL2≈ 3 nsA, CcopiedL3≈ 10 nsA, B, C, DcopiedRAM≈ 80 nsA, B, C, Deach level is larger and slower than the previous one
CPUL1≈ 1 nsA, B, DcopiedL2≈ 3 nsA, C, DcopiedL3≈ 10 nsA, B, C, DRAM≈ 80 nsA, B, C, Deach level is larger and slower than the previous one
Figure 1.2.13: A read in a multilevel cache. Top, the initial state. Middle, the state after A has been fetched from RAM: A has been copied to all levels. Bottom, the state after D has been found in L3: D has been copied to L2 and L1.
Table 1.2.6: Trace of the three reads.
RequestSearch pathTimeThen L1 / L2 / L3
Anot in L1 (1) → not in L2 (+3) → not in L3 (+10) → RAM (+80)94 nsA, B / A, C / A, B, C, D
Ain L11 nsunchanged
Dnot in L1 (1) → not in L2 (+3) → in L3 (+10)14 nsA, B, D / A, C, D / A, B, C, D

The three reads took 94 + 1 + 14 = 109 ns in all. If all three had been read directly from RAM, it would have been 3 × 80 = 240 ns. Two details in the table are important:

  • The first read of A is longer than an uncached read (80 ns): 94 ns. The price of a miss is the time of the levels searched in vain. A cache does not speed up every single read; the gain comes from reusing the same data.
  • D was found in L3: 14 ns. Going to RAM would have taken 94 ns; 94 ÷ 14 ≈ 6.7, so it is about 7 times faster.
Definition 1.2.12

Temporal locality is the tendency of a program that accesses a piece of data to access the same data again within a short time. The second read of A taking 1 ns results from this tendency.

Spatial and temporal locality together explain why the cache is so effective. A loop’s counter variable is read again in every round (temporal locality); the array the loop walks through sits at consecutive addresses (spatial locality). In typical programs the great majority of the processor’s requests are served from the cache.

Example 1.2.8

95% of a program’s memory requests hit in the cache. A hit takes 1 ns, and a miss takes 81 ns, the sum of looking in the cache (1 ns) and fetching from RAM (80 ns). What is the average time of a request?

  1. Of 100 requests, 95 hit: 95 × 1 = 95 ns.
  2. The remaining 5 miss: 5 × 81 = 405 ns.
  3. The total is 95 + 405 = 500 ns; the average per request is 500 ÷ 100 = 5 ns.

Without a cache each request would take 80 ns. Even a 5% miss rate dominates the time: more than 4 of the 5 ns come from misses. A small increase in the hit rate therefore brings a big gain.

1.2.5Graphics card, connections, and sound

The processor computes the result, but other units are needed to turn this result into an image on the screen or a sound from the speaker. This section covers the graphics processing unit that produces the image, the ports that connect devices to the computer, and the sound card that converts sound to numbers and numbers to sound.

1.2.5.1The graphics processing unit

Definition 1.2.13

A graphics processing unit (GPU) is a processor designed to carry out many similar operations at the same time. It takes its name from the job of computing the colors of millions of pixels. The card that carries the GPU is also called the graphics card.

Producing an image on a screen means repeating the same calculation for a large number of pixels. A screen with a resolution of 1920 × 1080 has 1920 × 1080 = 2,073,600 pixels. If 60 frames are to be shown per second, more than 124 million pixel colors must be computed every second. Each of these calculations is simple and independent of the others. For such a job, thousands of simple cores suit better than a few powerful ones.

corecorecorecoreCPU: a few powerful coresGPU: thousands of simple cores do the same operation in parallel
Figure 1.2.14: A CPU consists of a few powerful cores; in a GPU, thousands of simple cores do the same operation in parallel.

Figure 1.2.14 summarizes the difference between the two kinds of processor. A CPU’s cores are suited to carrying out complex and varied jobs quickly: make a decision, open a file, finish one calculation and move to another job. A GPU’s cores are individually weak, but thousands of them execute the same instruction on different data at the same time. It is like everyone in a classroom solving their own problem at once: much faster than a single teacher solving all the problems one after another.

GPUs come in two forms:

  • An integrated GPU is in the same package as the processor and shares the system memory (RAM). It uses little power and adds no extra cost; it is enough for office work, watching video, and light games.
  • A discrete GPU is a separate card. It has its own processor and its own video memory (VRAM). It is more powerful, but uses more power and produces more heat.

The parallel computing power of GPUs is no longer limited to graphics. Video processing, scientific computing, and especially the training of artificial intelligence models also involve many independent multiplications and additions of the same kind. When choosing a GPU, the workload, the amount of VRAM, power consumption, cooling, and whether the software to be used supports that GPU are considered together.

Common mistake

Thinking that a GPU can take the place of a CPU. A GPU is fast only at many jobs of the same kind that can be split up. Jobs such as running the operating system or carrying out a program’s step-by-step decisions stay on the CPU. The two processors complement each other.

1.2.5.2Video connections

The image the graphics card produces is carried to the monitor by a cable. The type of cable and port determines the resolution and refresh rate that can be carried, and whether sound goes over the same cable too.

Table 1.2.7: Common video connections.
ConnectionSignal carriedCommon use
HDMIdigital video and audiomonitors, televisions, projectors
DisplayPortdigital video and audiocomputer monitors
USB-Cvideo, data, and power depending on the modellaptops and mobile devices
VGAanalog videoolder screens and projectors
HDMIdigitalDisplayPortdigitalUSB-Cdigital (depending on the model)VGAanalog, 15 pinsConnector faces (schematic)
Figure 1.2.15: The faces of video connectors (schematic). HDMI has a trapezoid with cut lower corners; DisplayPort has only one corner cut; USB-C is oval and symmetric; VGA is an analog connector with 15 pins.

The difference between analog and digital signals matters here. A digital connection carries the color of each pixel as a number; the receiver reads these numbers as they are. An analog connection (VGA) carries colors as continuously varying voltages. As the cable gets longer or electrical noise around it grows, these voltages get distorted and blur and ghosting appear in the image. For this reason VGA is used today only for compatibility with older devices.

The shapes in Figure 1.2.15 also explain why connectors cannot be plugged into the wrong port. The cut corners ensure that the connector fits in only one orientation. USB-C, being symmetric both ways, has no wrong-way problem.

1.2.5.3USB and other ports

USB (Universal Serial Bus) is the common interface to which many devices, from keyboards to external disks, connect. The key to understanding USB is to tell two separate concepts apart: the connector shape and the version.

USB-Aplugs in one way onlyUSB-Creversible, data+power+videoHDMIvideo + audioRJ-45wired network (Ethernet)3.5 mmanalog audio
Figure 1.2.16: Common ports. USB-A plugs in one way only; USB-C is reversible and can carry data, power, and video; HDMI carries video and audio; RJ-45 is the wired network (Ethernet) port; the 3.5 mm jack carries analog audio.

The connector shape is the shape of the plug: type A (wide, rectangular) or type C (small, oval). The version is the standard that determines the speed at which data is carried. Table 1.2.8 shows the main versions and their top speeds.

Table 1.2.8: USB versions and their highest theoretical speeds.
USB versionTop speedTypical use
USB 2.0480 Mbit/skeyboard, mouse
USB 3.2 Gen 1 (formerly USB 3.0)5 Gbit/sexternal disk
USB 3.2 Gen 210 Gbit/sfast external SSD
USB420 or 40 Gbit/sUSB-C; display, docking station
Thunderbolt 440 Gbit/sUSB-C; display, docking station

The speeds in the table are in bits. File sizes, on the other hand, are mostly given in bytes. In units, a lowercase “b” stands for bit and an uppercase “B” for byte: 480 Mbit/s and 480 MB/s are very different speeds. Because a byte is 8 bits, a speed in bits is converted to bytes by dividing by 8.

Example 1.2.9

A 5 GB (5000 MB) file is copied at the highest theoretical speed. How many seconds does it take with USB 2.0 and with USB 3.2 Gen 2?

  1. USB 2.0. 480 Mbit/s ÷ 8 = 60 MB/s. Time = size ÷ speed = 5000 ÷ 60 ≈ 83.3 s.
  2. USB 3.2 Gen 2. 10 Gbit/s = 10,000 Mbit/s; ÷ 8 = 1250 MB/s. Time = 5000 ÷ 1250 = 4 s.

For the same file the difference is about 21 times. Real speeds are lower than the theoretical values, because the protocol’s own control data, the speed of the disk, and the quality of the cable also affect the result.

Common mistake

Thinking that every USB-C port has the same speed and can output video. USB-C is only a connector shape. One USB-C port on a laptop may run at USB 2.0 speed (480 Mbit/s) while another is USB4 (40 Gbit/s). Video output and charging support also vary by port; this information is in the device’s specifications or in the symbols next to the port.

1.2.5.4The sound card

Sound is pressure waves in the air. A microphone turns these waves into a continuously varying electric voltage; this is called an analog signal. A computer, however, works only with numbers. The job of the sound card is to translate between these two worlds.

Definition 1.2.14

The ADC (analog-to-digital converter) measures the analog signal at regular intervals and turns each measurement into a number. Each measurement is called a sample, and the number of measurements per second is the sampling rate. The DAC (digital-to-analog converter) turns the numbers back into the electric signal that drives the speaker.

analog signal (microphone)ADCsamples: 0, 5, 7, 4, -1, -4…DACspeaker
Figure 1.2.17: The analog signal from the microphone is sampled in the ADC and turned into numbers (0, 5, 7, 4, −1, −4, …). During playback the DAC turns these numbers back into a signal, and the speaker produces the sound.

The higher the sampling rate, the more accurately the sound is recorded. On music CDs the sampling rate is 44,100 samples per second (44.1 kHz). Each sample is stored in 16 bits, that is, 2 bytes. A stereo recording has two separate channels, left and right.

Example 1.2.10

A sound recording is made as a single channel (mono), at 48,000 samples/s and 16 bits per sample. How many bytes does a 30-second uncompressed recording take? How many MiB is that?

  1. One second. 48,000 samples × 2 bytes × 1 channel = 96,000 bytes.
  2. 30 seconds. 96,000 × 30 = 2,880,000 bytes.
  3. Converting to MiB. 1 MiB = 1024 × 1024 = 1,048,576 bytes. 2,880,000 ÷ 1,048,576 ≈ 2.75 MiB.

If the same recording were stereo, the size would double. Compression formats such as MP3 shrink this size about tenfold by discarding details the ear does not notice.

Most motherboards include an audio unit that is sufficient for everyday use: the headphone and microphone jacks are on the rear panel of the motherboard or on the front of the case. Where recording quality matters, when several microphones must be connected, or for professional music work, an external sound card is used. External cards contain a better ADC and DAC; they also sit away from the electrical noise inside the computer.

1.2.6Case, cooling, and power supply

However powerful a computer’s components are, it will not work efficiently if it is not properly powered and cooled. The case and the power supply are the parts most likely to be overlooked, yet they directly affect the stability of the system.

1.2.6.1Case and cooling

Every component inside the computer turns almost all of the electrical energy it uses into heat. A processor drawing 125 W behaves like a small 125 W heater. If this heat is not carried away, the temperature rises quickly.

CPUheatsinkGraphics cardPower supplycoolairhotair
Figure 1.2.18: Airflow inside the case. Cool air enters at the front, passes over the processor heatsink and the graphics card; the warmed air leaves at the back and the top.

The case has four jobs:

  • Protection: It protects the components from impact, dust, and static electricity that can come from touch.
  • Airflow: Cool air enters at the front and hot air leaves at the back or the top (Figure 1.2.18). Because hot air rises, an exit at the top supports the natural flow.
  • Form factor: The size and internal layout of the case determine which motherboard and power supply sizes will fit. Common motherboard sizes are ATX and the smaller mATX.
  • Cable layout: Bundling the cables does not obstruct airflow and makes maintenance easier.

A heatsink is placed on top of the processor. The heatsink takes heat from the processor and spreads it over metal fins with a large surface; a fan blows air between the fins. In more powerful systems liquid cooling is used: the heat is transferred to a liquid, and the liquid is cooled in a radiator with fans.

Definition 1.2.15

Thermal throttling is the processor’s automatic lowering of its clock speed when its temperature approaches the safe limit. This reduces the heat produced and protects the chip, but performance falls too.

Thermal throttling is a protective mechanism; it prevents the processor from being damaged. But if it happens often, it shows that the cooling is insufficient. This is one of the common reasons a dust-clogged laptop slows down over time. High temperature can also shorten the life of components in the long run.

1.2.6.2The power supply

Definition 1.2.16

The power supply unit (PSU) is the unit that converts the alternating current (AC) of the mains into the direct current (DC) voltages the computer components use.

The electricity from the wall socket is, in Türkiye, alternating current at 230 V and 50 Hz: the direction of the voltage reverses back and forth 50 times a second. The computer’s circuits, on the other hand, need steady, low voltages whose direction does not change. The power supply makes this conversion and produces different voltages for different components (Figure 1.2.19).

Mains: 230 V ACPower supplyAC → DC+12 VCPU, graphics card, fans+5 VUSB, SATA drives+3.3 VM.2, motherboard circuits
Figure 1.2.19: The power supply converts the 230 V AC of the mains into three DC voltages: +12 V powers the processor, the graphics card, and the fans; +5 V powers USB and SATA drives; +3.3 V powers M.2 devices and the motherboard circuits.

Four criteria are considered when choosing a power supply:

  • Capacity (W): The highest power the supply can deliver. It must meet the total need of the components with a safe margin.
  • Efficiency: How much of the power drawn from the mains reaches the components. The rest turns into heat.
  • Connections: The motherboard (24-pin), processor (8-pin), graphics card, and storage cables must suit the system.
  • Protection: In case of overcurrent, overvoltage, and short circuit, the power supply must protect itself and the components.
Example 1.2.11

In a system the processor draws 125 W, the graphics card 220 W, and the other components 75 W. A 30% safety margin is to be left. Models of 450, 550, 650, and 750 W are on the market. Which is chosen?

  1. Total need. 125 + 220 + 75 = 420 W.
  2. Need with the margin added. A 30% margin means multiplying the need by 1.3: 420 × 1.3 = 546 W.
  3. Choosing the model. The smallest model that is not below 546 W is 550 W.

There are two reasons for leaving a margin. Components can draw more than the stated power for brief moments. Also, power supplies get hotter and less efficient when they run very close to their limits.

Example 1.2.12

A power supply with 90% efficiency delivers 500 W to the components. How much power does it draw from the mains? How much turns into heat?

  1. Since efficiency = delivered power ÷ drawn power, the drawn power = 500 ÷ 0.90 ≈ 555.6 W.
  2. The part that turns into heat = 555.6 − 500 ≈ 55.6 W.

At the same load, an 80%-efficient power supply would draw 500 ÷ 0.80 = 625 W; the part turning into heat would be 125 W. An efficient power supply reduces both the electricity bill and the heat inside the case.

Common mistake

Taking a power supply’s watt rating to be the power the computer draws continuously. A 650 W power supply draws around 200 W if the system asks for only 200 W. The watt rating is an upper limit, not continuous consumption.

1.2.7Input devices

A computer receives information from the outside world through input devices. The keyboard and the mouse are the most familiar examples; but a phone’s location sensor, a smartwatch’s heart-rate monitor, or a temperature sensor in a factory are input devices too.

1.2.7.1Kinds of input devices

Definition 1.2.17

An input device is a device that converts information from the user or the environment into digital data the computer can process and passes it to the system.

Table 1.2.9: Main input devices and the information they take in.
DeviceInformation taken in
Keyboardtext, numbers, and commands
Mouse, touchpadpointing, selecting, and movement
Microphonesound
Camera, scannerimages and documents
Game controlleraxis, button, and motion information
Sensormeasurement of temperature, position, light, or motion

All input devices share one step: a physical quantity is turned into a number. A key press on the keyboard becomes a key code, sound at the microphone becomes samples (1.2.5.4), and light at the camera becomes three color values for each pixel. The computer processes these numbers; it does not know they were once sound or light.

Note the word “scanner.” Here it means the device that turns a paper document into an image. A web browser is also a program that can be used to read pages on the internet, but it is software, not an input device.

1.2.7.2The keyboard

The keyboard is the basic tool for entering text. Its keys are divided into regions by function (Figure 1.2.20):

  • Alphanumeric keys enter letters, digits, and punctuation marks.
  • Function keys (F1–F12) take on special tasks depending on the application; for example, in many programs F1 opens help.
  • Modifier keys (Ctrl, Alt, Shift, the Windows key) type nothing on their own; pressed together with other keys they form shortcuts.
  • Arrow keys move the cursor; the numeric keypad makes it easier to enter many digits.
EscF1F2F3F4F5F6F7F8F9F10F11F12ShiftShiftCtrlWinAltAltGrCtrlalphanumeric keys + spacearrow keysnumeric keypad← function keys
Figure 1.2.20: The regions of the keyboard: function keys at the top, the alphanumeric section and modifier keys (Shift, Ctrl, Win, Alt, AltGr) in the middle, arrow keys and the numeric keypad on the right.

When editing text, the most frequently used keys are Enter, Backspace, and Delete. Enter confirms an entry or moves to a new line. Backspace deletes the character to the left of the cursor, and Delete deletes the character to the right of the cursor. If some text is selected, both delete the whole selection. Frequently used shortcuts are these:

Table 1.2.10: Common keyboard shortcuts.
ShortcutFunction
Ctrl + CCopy
Ctrl + XCut
Ctrl + VPaste
Ctrl + ZUndo
Alt + TabSwitch between open applications

The copy and cut commands put the selected text into a temporary area called the clipboard. Paste inserts the clipboard’s contents where the cursor is; the clipboard does not change in the process. So the same content can be pasted many times in a row.

Example 1.2.13

A text box contains “Ders” (Turkish for “lesson”) and the cursor is at the end of the text. The clipboard is empty. The following operations are performed in order: select all the text and press Ctrl + C; clear the selection and put the cursor at the end; Ctrl + V; Backspace; Ctrl + Z. What are the text and the clipboard after each step? (The position of the cursor is shown with ▏.)

StepOperationTextClipboard
0startDers▏empty
1select all, Ctrl + CDers (selected)Ders
2clear the selection, cursor to the endDers▏Ders
3Ctrl + VDersDers▏Ders
4BackspaceDersDer▏Ders
5Ctrl + ZDersDers▏Ders

Ctrl + C does not change the text; it only fills the clipboard. Backspace deletes the “s” to the left of the cursor. Ctrl + Z undoes the last operation, that is, the deletion. The clipboard stays “Ders” throughout.

Common mistake

Thinking that Delete and Backspace delete the same character. When the cursor is at the end of the text, Delete deletes nothing, because there is no character to the right of the cursor. Backspace deletes the last character.

1.2.7.3The mouse and pointing devices

The mouse is a pointing device used to steer the cursor on the screen. The optical sensor underneath photographs the surface thousands of times per second and, by comparing consecutive images, calculates how far and in which direction it has moved. Two numbers stand out in a mouse’s technical specifications.

Definition 1.2.18

DPI (dots per inch) is the number of steps the mouse reports to the computer when it moves 1 inch (2.54 cm). The polling rate is how many times per second the mouse sends its position, and it is measured in Hz.

1 inch = 2.54 cm800 DPI800 pixels1600 DPI1600 pixelspath of the cursor when the operating system’s speed setting is 1:1
Figure 1.2.21: When the mouse moves 1 inch, an 800 DPI mouse reports 800 steps and a 1600 DPI mouse reports 1600. With the operating system’s speed setting at 1:1, the cursor moves that many pixels.
Example 1.2.14

A 1600 DPI mouse is slid 3 inches (about 7.6 cm) on the desk. The speed setting is 1:1. How many pixels does the cursor move? If the mouse’s polling rate is 500 Hz, how often, in ms, is the position sent?

  1. Number of steps. 1600 steps/inch × 3 inches = 4800 steps. Since the speed setting is 1:1, the cursor moves 4800 pixels; this is more than twice the width of a screen that is 1920 pixels wide.
  2. Polling interval. 500 transmissions per second: 1000 ms ÷ 500 = once every 2 ms. For a 1000 Hz mouse this falls to 1 ms.

A high DPI is not always better. At a very high DPI even the slightest hand tremor moves the cursor several pixels; precise work becomes harder. A suitable value is chosen according to the screen’s resolution and the user’s habits. The mouse’s buttons and wheel also do jobs such as selecting, opening the context menu, and scrolling the page.

There are also pointing devices that are alternatives to the mouse: the touchpad on laptops, the stylus for drawing, the trackball that works with a ball turned by hand, and the touch screen, which is touched directly. The touch screen, as will be seen in the next section, is also an output device.

1.2.8Output devices

Output devices turn the digital result a computer produces into a form people can perceive: light, sound, ink on paper, or vibration.

1.2.8.1Output devices and their classification

Definition 1.2.19

An output device is a device that presents the data a computer produces to the user as an image, sound, print, or movement.

Table 1.2.11: Main output devices.
DeviceOutput produced
Monitortext, images, and video
Printera copy of the digital document on paper
Speaker, headphonessound
Projectoran image projected onto a large surface
Haptic feedbackvibration or force
Multifunction deviceinput and output together (e.g., a printer with a scanner)

The only criterion that decides whether a device is input or output is the direction of the data flow. If data flows toward the computer, the device is an input device; if it flows toward the user, it is an output device. In some devices data flows both ways (Figure 1.2.22).

INPUTOUTPUTdata enters the computerthe result goes out to the userKeyboardMouseMicrophoneCameraScannerSensorMonitorPrinterSpeakerProjectorHeadphonesBOTHTouch screenHeadset with microphoneMultifunction printerVibrating game controllerNetwork card, storage
Figure 1.2.22: Input devices, output devices, and devices that are both. The touch screen, headset with microphone, multifunction printer, vibrating game controller, network card, and storage devices work in both directions.
Example 1.2.15

Which group do a webcam, a smartwatch screen (touch), a printer, an external SSD, and a game steering wheel (with force feedback) belong to?

  • Webcam: gives images to the computer → input.
  • Smartwatch screen: takes touch, shows images → both.
  • Printer: puts the document on paper → output (for a printer that only prints).
  • External SSD: both read and written → both.
  • Game steering wheel: sends the turning angle and returns the bumps of the road to the wheel as force → both.

1.2.8.2The monitor: resolution, size, and aspect ratio

A monitor forms an image by dividing the screen surface into millions of small dots. Each of these dots is called a pixel. Four basic values appear in a monitor’s specifications:

  • Resolution: the number of horizontal and vertical pixels; for example 1920 × 1080.
  • Screen size: the length of the diagonal, measured in inches; for example 24 inches.
  • Pixel density: how many pixels fall on one inch (1.2.8.3).
  • Aspect ratio: the ratio of the screen’s width to its height; for example 16:9.
24 inches1920 pixels108016:9Pixels along the diagonal:√(1920² + 1080²) ≈ 2203 pixelsPixel density:2203 ÷ 24 ≈ 92 PPIThe same 1920 × 1080 on a 15.6-inch laptop ≈ 141 PPI
Figure 1.2.23: A 24-inch, 16:9 monitor: 1920 pixels wide and 1080 pixels high. The number of pixels along the diagonal is √(1920² + 1080²) ≈ 2203; the pixel density is 2203 ÷ 24 ≈ 92 PPI. The same resolution on a 15.6-inch laptop gives about 141 PPI.

The aspect ratio of a 1920 × 1080 resolution is 16:9, because 1920 ÷ 1080 = 16 ÷ 9 ≈ 1.78. Because the screen size is given as a diagonal, the width and height are not written directly; but they can be calculated from the aspect ratio.

Example 1.2.16

How many cm wide and high is the screen of a 24-inch, 16:9 monitor?

  1. The diagonal of the ratio. If the width is taken as 16 units and the height as 9 units, by the Pythagorean theorem the diagonal is √(16² + 9²) = √(256 + 81) = √337 ≈ 18.36 units.
  2. How many inches is one unit? Since the diagonal is 24 inches, 1 unit = 24 ÷ 18.36 ≈ 1.307 inches.
  3. Width and height. The width is 16 × 1.307 ≈ 20.92 inches and the height is 9 × 1.307 ≈ 11.77 inches.
  4. Converting to centimeters. 1 inch = 2.54 cm: width ≈ 20.92 × 2.54 ≈ 53.1 cm, height ≈ 11.77 × 2.54 ≈ 29.9 cm.

1.2.8.3Pixel density

The same resolution looks sharper on a small screen. The reason is that the same number of pixels is fitted into a smaller area. As pixels get smaller, the eye cannot tell them apart one by one, and edges look smoother (Figure 1.2.24).

8 × 8 = 64 pixels24 × 24 = 576 pixels1 pixel = red + green + blue
Figure 1.2.24: The same circle on grids of 8 × 8 = 64 and 24 × 24 = 576 pixels. As the number of pixels increases, the edges look smoother. Each pixel consists of three subpixels: red, green, and blue.

The three-color bar under the figure shows an important detail: a pixel actually consists of three small light sources. Every color is obtained by adjusting the brightness of the red, green, and blue subpixels. If all three are fully bright, it looks white; if all three are dim, black.

Definition 1.2.20

Pixel density is the number of pixels per inch of the screen’s length and is measured in PPI (pixels per inch). It is calculated along the diagonal:

PPI = √(horizontal pixels² + vertical pixels²) ÷ diagonal (inches)

The logic of the formula is this: the length of the diagonal is known in inches; how many pixels lie along the diagonal is found with the Pythagorean theorem. Dividing the second by the first gives the number of pixels per inch.

Example 1.2.17

What is the PPI of a 27-inch, 3840 × 2160 (4K) monitor? How much denser is it than a 2560 × 1440 monitor of the same size?

  1. Diagonal pixels of 4K. 3840² = 14,745,600 and 2160² = 4,665,600. The total is 19,411,200; its square root ≈ 4405.8.
  2. 4K PPI. 4405.8 ÷ 27 ≈ 163.2 PPI.
  3. Diagonal pixels of 2560 × 1440. 2560² + 1440² = 6,553,600 + 2,073,600 = 8,627,200; its square root ≈ 2937.2.
  4. 2560 × 1440 PPI. 2937.2 ÷ 27 ≈ 108.8 PPI.

At the same size the 4K screen is about 1.5 times denser. The difference in the number of pixels is larger: 3840 × 2160 = 8,294,400 pixels is 2.25 times 2560 × 1440 = 3,686,400 pixels. So a 4K screen also taxes the graphics card more.

Common mistake

Treating resolution alone as a measure of sharpness. A 32-inch 4K monitor is about 138 PPI; a 14-inch 1920 × 1080 laptop is about 157 PPI. The laptop screen with the lower resolution looks sharper. What determines sharpness is the pixel density that resolution and size give together; viewing distance also plays a part.

1.2.8.4Refresh rate and response time

Motion on the screen actually consists of still frames shown one after another. If the frames change fast enough, the eye perceives them as continuous motion. Several properties determine how well a monitor shows motion:

Table 1.2.12: Motion and image properties of a monitor.
PropertyWhat it means
Refresh rateHow many times per second the screen is refreshed; measured in Hz.
Response timeThe time a pixel takes to change from one color to another.
BrightnessThe screen’s light output (cd/m²).
Color accuracyHow close the colors shown are to the target values.
Viewing angleHow well the image holds up when viewed from the side.

A screen with a refresh rate of 60 Hz refreshes its image 60 times per second. The time a frame stays on the screen is the inverse of the refresh rate: 1000 ms ÷ 60 ≈ 16.7 ms. As the refresh rate rises, this time shortens and motion looks smoother (Figure 1.2.25).

60 Hz16.7 ms144 Hz6.9 ms0 ms50 ms
Figure 1.2.25: In 50 ms a 60 Hz screen shows 3 new frames and a 144 Hz screen shows 7. The duration of a frame is 16.7 ms at 60 Hz and 6.9 ms at 144 Hz.
Example 1.2.18

On 60, 144, and 240 Hz screens, how many ms does a frame stay on the screen? How many new frames does each show in 50 ms?

Refresh rateFrame duration (1000 ÷ Hz)Frames in 50 ms (50 ÷ duration)
60 Hz≈ 16.7 ms3
144 Hz≈ 6.9 ms7.2 → 7 full frames
240 Hz≈ 4.2 ms12

Even if a screen’s refresh rate is high, there is no gain if the graphics card cannot produce that many frames. For a 144 Hz monitor to be useful, the game or application must be able to produce close to 144 frames per second.

Response time measures something else: how long a pixel takes to reach a new color after it is told to. On a screen with a long response time, a faint trail remains behind fast-moving objects. The two properties complement each other: the refresh rate determines how often new frames arrive, and the response time determines how cleanly each frame is drawn.

Common mistake

Taking refresh rate and response time to be the same thing. On a 144 Hz screen the frame duration is 6.9 ms; but the same screen’s response time may be 1 ms or 5 ms. One measures the number of frames per second, the other the speed at which a pixel changes color.

1.2.8.5Panel technologies: LCD and OLED

How a monitor produces its light determines the image’s contrast, colors, and viewing angle. Two main technologies are used today: LCD and OLED.

LCD (IPS, VA, TN)Polarizer + glassColor filter (R G B)Liquid crystal (adjusts the light)PolarizerBacklight (LED)black: light is blocked, but the backlight is always onOLEDGlassOrganic light-emitting layerControl circuit (TFT)black pixel = fully switched-off pixel
Figure 1.2.26: LCD and OLED layers. In an LCD there is an always-on backlight (LED) at the bottom; light passes through the polarizer, the liquid crystal, and the color filter. For black, the liquid crystal tries to block the light, but the backlight stays on. In an OLED each pixel produces its own light; a black pixel is fully off.

In an LCD (liquid-crystal display) panel, a backlight produces the light. The liquid crystal layer in front of it works like a small shutter that adjusts the amount of light passing through for each subpixel. A color filter gives the passing light its red, green, or blue color. To show black, the shutter closes; but the shutter cannot block the light completely and some leaks through. This is why an LCD’s black looks dark gray in a dark room.

An OLED (organic light-emitting diode) panel has no backlight. Each pixel produces its own light. A black pixel is completely off; it emits no light at all. So an OLED’s contrast is very high and black is truly black.

LCD panels themselves come in several types. IPS, VA, and TN are types of LCD; the difference between them lies in how the liquid crystals are arranged:

Table 1.2.13: Panel technologies.
PanelStrengthsWeaknesses
IPS (LCD)wide viewing angle, balanced colorsmedium black level
VA (LCD)high contrast, deep blacksnarrower viewing angle than IPS
TN (LCD)low response timelimited viewing angle and colors
OLEDeach pixel produces its own light, very high contrastusually more expensive

The panel is chosen according to the purpose of use. For office work and design, color accuracy and viewing angle matter; this is why IPS is common. For watching films in a dark room, contrast stands out; VA and OLED are strong here. In competitive games, response time and refresh rate are decisive. The budget is a separate limit on every choice.

1.2.8.6Printers, sound, and projectors

Printers transfer a digital document to paper. Two technologies are common today (Figure 1.2.27):

  • An inkjet printer sprays microscopic ink droplets onto the paper through tiny nozzles in its head. It is common for color documents and photo printing.
  • A laser printer uses a laser beam to form a pattern of electric charge on a rotating drum. Powdered pigment (toner) sticks to this pattern, is transferred to the paper, and is fixed to the paper with heat. It can be fast and economical for high-volume text printing.
Inkjetheadmicroscopic droplets onto the paperLaserlasercharge patterndrum+ tonertransferto paperfixingwith heatfast for high-volume, text-heavy printing
Figure 1.2.27: An inkjet printer sprays droplets onto the paper. In a laser printer a laser forms a charge pattern on the drum; toner sticks to this pattern, is transferred to the paper, and is fixed with heat.

Speakers and headphones turn the analog signal from the sound card’s DAC, or data from a digital connection such as USB or Bluetooth, into sound. With a digital connection, the DAC is inside the speaker or the headphones.

A projector casts the image onto a screen or a wall. Three values stand out when choosing one: brightness, resolution, and throw distance. Brightness must be high for the image to be visible in a well-lit classroom. Throw distance shows how far from the screen the projector must be placed for a given image size.

1.2.9Storage

Everything in RAM is lost when the computer is switched off. A separate unit is needed to keep documents, photographs, programs, and the operating system permanently. This section covers storage devices, the speed differences between them, and what those differences mean in everyday use.

Definition 1.2.21

A storage device is non-volatile memory, that is, memory that keeps data even when the power is cut. Its main types are the hard disk (HDD), the solid-state drive (SSD), the USB flash drive, the memory card, and the optical disc.

1.2.9.1A document’s journey between components

The best way to see storage’s place in the system is to follow an everyday task. A document called report.docx is opened, edited, and saved. During this, data travels among the mouse, the SSD, RAM, the processor, and the screen (Figure 1.2.28).

MouseSSDRAMCPU + cacheScreenpermanenttemporaryContents:report.docx (old)report.docx—program + document are copied
MouseSSDRAMCPU + cacheScreenpermanenttemporaryContents:report.docx (old)report.docx (changed)document appearsimage
MouseSSDRAMCPU + cacheScreenpermanenttemporaryContents:report.docx (current)report.docx (changed)document appearssave
Figure 1.2.28: Opening and saving a document, three moments. At the top, the program and the document are copied from the SSD to RAM. In the middle, the document has been edited: the copy in RAM has changed, the copy on the SSD is still old; the result appears on the screen. At the bottom, “Save” writes the changes from RAM to the SSD and the copy on the SSD is updated.
Table 1.2.14: Steps of opening, editing, and saving a document.
StepWhat happens?Document on the SSDDocument in RAM
1The user double-clicks report.docx; the mouse passes this event to the computer (input).old—
2The operating system finds the program and document files on the SSD.old—
3The program and the document are copied from the SSD to RAM.oldold (copy)
4The CPU brings instructions from RAM into the cache and registers and processes them (fetch–decode–execute).oldbeing edited
5The result goes through the graphics card to the monitor; the user sees the document and edits it (output).oldchanged
6With “Save,” the changes are written from RAM to the SSD.currentchanged

Step 3 of the table shows an important fact: the CPU does not run the program directly from the SSD. The program is first copied to RAM; the processor fetches instructions from RAM through the cache. The SSD is too slow for the processor to put up with the wait (1.2.4.2). The read path therefore follows the order SSD → RAM → cache → registers; saving goes in the direction RAM → SSD.

In steps 4 and 5 there are two different versions of the document: the edited copy in RAM and the old copy on the SSD. If the power goes off at this point, the changes in RAM are lost and the old version on the SSD remains. This is why many programs save automatically at regular intervals.

Common mistake

Thinking that the document seen on the screen sits on the disk in the same state. The image on the screen reflects the copy in RAM. Until it is saved, the file on the disk is in its old state.

1.2.9.2HDD and SSD

The two main storage technologies in computers store data in completely different ways.

Definition 1.2.22

A hard disk drive (HDD) is a storage device that keeps data on rotating magnetic platters. Data is read and written by a read–write head at the end of an arm. An SSD (solid-state drive) stores data in flash memory chips that have no moving parts.

HDDplatter (5400–7200 rpm)headarmtrackSSD (M.2)connectorControl-lerDRAMNANDNANDNANDflash memory chipsno moving parts
Figure 1.2.29: On the left, the inside of an HDD: the platter spinning at 5400–7200 rpm, the tracks on the platter, the arm, and the head. On the right, an M.2 SSD: the controller, the DRAM used as a cache, and the NAND flash memory chips. An SSD has no moving parts.

Reading data on an HDD is a mechanical job. The head must move to the right track (one of the concentric rings on the platter), and then the sector to be read (a small piece of the track) must rotate around under the head. These two movements take milliseconds. In an SSD, the controller reads data from several flash chips at the same time; access is on the order of microseconds.

Table 1.2.15: Comparison of HDD and SSD.
PropertyHDDSSD
Technologyrotating magnetic diskflash memory
Speedlowerhigher
Shock resistancemore sensitive because of the mechanical partsno moving parts
Cost per capacityusually lowerusually higher
Common usearchives and high capacityoperating system and applications

A common arrangement follows from this comparison. The operating system and programs are put on an SSD so that they open quickly. Large but rarely used data such as photo archives and backups are kept on the cheaper HDD. In laptops, almost only SSDs are used because of their shock resistance, low power consumption, and silence.

1.2.9.3SATA and NVMe

The speed of an SSD does not depend only on the flash chips; the path by which the SSD is connected to the computer is also decisive. Two interfaces are common.

Table 1.2.16: SATA SSD and NVMe SSD.
PropertySATA SSDNVMe SSD
InterfaceSATA (an older interface designed for hard disks)the NVMe protocol over PCIe
Typical sequential readabout 550 MB/s (the SATA III limit)a few GB/s (depending on the PCIe version and the number of lanes)
Parallelisma single command queuemany parallel queues; low latency
Form2.5-inch case or M.2mostly M.2 (U.2 in some servers)
SATA SSDSATA controller≈ 550 MB/s limitNVMe SSDPCIe x4 lanes: a few GB/sCPU
Figure 1.2.30: The data of a SATA SSD passes through the SATA controller and is limited to about 550 MB/s. An NVMe SSD, on the other hand, is connected directly to the processor with four PCIe lanes and can transfer a few GB per second.

SATA was designed for the speed of spinning disks. SSDs soon exceeded this limit: the theoretical limit of SATA III is 6 Gbit/s; when the bits reserved for data encoding are subtracted, this comes to about 600 MB/s. This is why SATA SSDs stay around 550 MB/s in practice. NVMe (Non-Volatile Memory Express) is a protocol designed directly for flash memory and uses PCIe lanes.

Example 1.2.19

A PCIe lane carries about 0.985 GB per second in PCIe 3.0, and this value doubles with each new generation. What is the theoretical limit of a four-lane (x4) NVMe SSD in each generation?

  1. PCIe 3.0 x4. 4 × 0.985 ≈ 3.94 GB/s.
  2. PCIe 4.0 x4. Per lane 2 × 0.985 ≈ 1.97 GB/s; 4 × 1.97 ≈ 7.88 GB/s.
  3. PCIe 5.0 x4. Per lane 2 × 1.97 ≈ 3.94 GB/s; 4 × 3.94 ≈ 15.75 GB/s.

Compared with SATA’s limit of 0.6 GB/s, a PCIe 4.0 x4 connection is about 13 times wider. Real SSDs can approach these limits but cannot exceed them.

Common mistake

Thinking M.2 is a protocol and that every M.2 SSD will run at NVMe speed. M.2 is only a form factor, that is, the shape of the card and its slot. An M.2 slot may support SATA, NVMe, or both; which is supported is written in the motherboard manual. A SATA SSD in the M.2 form stays at the 550 MB/s limit.

1.2.9.4Reading a sector on an HDD

To see why an HDD is slow, let us follow the reading of a single sector step by step. The platter spins at 7200 revolutions per minute. The sector to be read and the read–write head are initially in different places. The access time consists of three parts (Figure 1.2.31).

platter (spinning)read–write arm and headAccess time = seek + rotation + transferSeek time ≈ 5 msthe head moves to the target trackRotational latency ≈ 4.2 ms7200 rpm: on average half a turnTransfer ≈ 0.03 ms4 KB ÷ 150 MB/sTotal ≈ 9.2 ms
Figure 1.2.31: Reading a sector on an HDD. The head first moves to the target track (seek, ≈ 5 ms); then it waits for the sector to rotate under the head (rotational latency, ≈ 4.2 ms); finally the data is read (transfer, ≈ 0.03 ms). Total ≈ 9.2 ms.
Definition 1.2.23

The access time of a sector on an HDD is the sum of three parts:

access time = seek time + rotational latency + transfer time

Seek time is the time the arm takes to bring the head to the target track. Rotational latency is the time expected for the sector to rotate under the head; on average, half a turn is assumed. Transfer time is the time to read the data while the sector passes under the head.

Example 1.2.20

On an HDD spinning at 7200 rpm, the average seek time is 5 ms and the transfer rate is 150 MB/s. What is the average access time of a 4 KB sector? (Take 1 MB = 1000 KB.)

  1. Seek. The arm brings the head to the target track: 5 ms.
  2. One full turn. 1 minute = 60,000 ms. 60,000 ÷ 7200 ≈ 8.33 ms per turn.
  3. Rotational latency. On average the sector is half a turn away: 8.33 ÷ 2 ≈ 4.17 ms (about 4.2 ms).
  4. Transfer. 4 KB = 0.004 MB. 0.004 ÷ 150 ≈ 0.0000267 s ≈ 0.03 ms.
  5. Total. 5 + 4.17 + 0.03 ≈ 9.2 ms.

Of the total, 9.17 ms is mechanical waiting; the actual reading is 0.03 ms. The waiting is more than 300 times the reading.

This calculation explains why an HDD is acceptable for large, single-piece files but very slow for many small files. A large file is stored in sectors lying one after another on the platter: the head positions itself once and the data is read continuously. Each of 100 small files, however, is in a separate place. The wait for seek and rotation is lived again for each file: 100 × 9.2 ms = 920 ms, almost a second. The same job takes 100 × 0.1 = 10 ms on an SSD with an access time of about 0.1 ms.

Common mistake

Taking the full-turn time as the rotational latency. The sector may be right in front of the head or a full turn away. On average, half a turn is waited; this is why the turn time is divided by 2.

1.2.9.5Copy time and capacity units

The time to copy a large file can be estimated from the storage device’s sequential read speed. Sequential reading is reading data continuously from blocks that lie one after another; for large files this speed is decisive.

time = file size ÷ transfer rate

HDD150 MB/s≈ 66.7 sSATA SSD550 MB/s≈ 18.2 sNVMe SSD (PCIe 4.0)5000 MB/s≈ 2.0 stime = size ÷ speed (10,000 MB ÷ MB/s)
Figure 1.2.32: Copy time of a 10 GB (10,000 MB) file: HDD (150 MB/s) ≈ 66.7 s, SATA SSD (550 MB/s) ≈ 18.2 s, NVMe SSD (PCIe 4.0, 5000 MB/s) ≈ 2.0 s.
Example 1.2.21

A 10 GB video file is read from three different devices. What are the times?

  1. Unit conversion. With the base manufacturers use, 10 GB = 10,000 MB.
  2. HDD. 10,000 ÷ 150 ≈ 66.7 s.
  3. SATA SSD. 10,000 ÷ 550 ≈ 18.2 s.
  4. NVMe SSD. 10,000 ÷ 5000 = 2.0 s.

These values hold for large, single-piece files. With many small files an HDD slows down much more because of head movement (1.2.9.4). Copying needs both reading and writing: the time depends on the slower of the source and target devices and on the connection between them (USB, network); data flows at the speed of the slowest link in this chain.

There are two separate conventions for capacity units, and this difference often causes confusion. Disk manufacturers use the decimal base with SI prefixes: 1 GB = 1000 MB = 109 bytes. Operating systems often compute capacity with a base of 1024: 1 GiB (gibibyte) = 1024 MiB = 230 = 1,073,741,824 bytes. The trouble is that some operating systems display this second value as “GB” instead of “GiB.”

Example 1.2.22

How many GB does a disk labeled “1 TB” on the box show in the operating system?

  1. The manufacturer’s value. 1 TB = 1012 = 1,000,000,000,000 bytes.
  2. Converting to base 1024. 1 GiB = 230 = 1,073,741,824 bytes. 1012 ÷ 1,073,741,824 ≈ 931.3 GiB.

If the operating system displays this value as “931 GB,” the disk looks about 7% “smaller.” The byte count is the same; only the unit changes. By the same calculation, a 500 GB disk shows as ≈ 465.7 GiB and a 256 GB SSD as ≈ 238.4 GiB.

1.2.9.6Portable and archival storage

Besides the disk inside the computer, there are other storage options for carrying, backing up, or sharing data.

Table 1.2.17: Portable and archival storage options.
OptionUse and characteristics
USB flash driveEasy to carry; there is a risk of loss and physical damage.
SD cardCommon in cameras and mobile devices.
Optical discUsed for software distribution and in certain archival scenarios.
External diskOffers high capacity for backup and moving data.
Network storageGives several users on the local network central access to files.
Cloud storageProvides synchronization and sharing over the internet.
ComputerUSB flash driveSD cardExternal diskOptical discdirectly (USB, card reader)Network storageCloud storagelocal networkinternet
Figure 1.2.33: The computer connects directly (by USB or a card reader) to USB flash drives, SD cards, external disks, and optical discs; it reaches network storage over the local network and cloud storage over the internet.

The most important use of these options is backup. If a file has only one copy, a failing disk, a stolen computer, or an accidental deletion destroys that file permanently. A common recommendation is to keep at least three copies of important data, on at least two different media, and to keep one of these copies in another place (for example in the cloud).

1.2.10System design

Choosing good parts one by one is not enough to get a good computer. The parts must fit one another, must not limit one another, and must serve the purpose of use. This section collects the criteria for evaluating a system as a whole.

1.2.10.1Component compatibility

Definition 1.2.24

Compatibility is the ability of components to work together without trouble in physical, electrical, logical, and software terms.

Table 1.2.18: Kinds of compatibility.
KindWhat is checked
PhysicalThe sizes of the case, motherboard, and cards must fit one another.
ElectricalThe power supply’s capacity and connections must be sufficient.
LogicalThe processor socket, the memory generation, and the chipset must be supported.
ConnectionPort, cable, and protocol versions must be compatible.
ThermalThe cooling system must handle the heat load of the processor and the GPU.
SoftwareOperating system and driver support must be available.
MotherboardCPUsocket + chipsetRAMDDR4 / DDR5 slotCasesize (ATX, mATX)Graphics cardPCIe slotPower supply: enough watts + cablesHeatsink ↔ CPU heat load · Operating system ↔ drivers
Figure 1.2.34: Compatibility checks gather around the motherboard: CPU with the socket and chipset, RAM with the DDR4/DDR5 slot, the case with the motherboard size (ATX, mATX), the graphics card with the PCIe slot. In addition, the power supply must provide enough watts and cables, the heatsink must handle the processor’s heat load, and drivers must exist for the operating system.

The motherboard is at the center of the compatibility check (Figure 1.2.34). When a computer is assembled part by part, the checks are made roughly in a certain order. First the processor and a motherboard with a matching socket are chosen. Then the RAM generation the motherboard supports is determined. Next one checks whether the motherboard and the graphics card fit in the case. Last, the power and cooling needs of the whole system are calculated.

Example 1.2.23

A student has chosen an ATX-size motherboard that supports DDR5. The motherboard’s M.2 slot supports only SATA. The student’s other chosen parts are two DDR4 RAM modules, an NVMe SSD, and an mATX-size case. What problems are there?

  1. RAM. DDR4 and DDR5 modules are physically different; a DDR4 module does not fit a DDR5 slot. The RAM must be changed to DDR5.
  2. SSD. If the M.2 slot supports only SATA, an NVMe SSD will not work in this slot. Either a SATA M.2 SSD must be chosen or a slot that supports NVMe must be used.
  3. Case. An mATX case does not take the larger ATX motherboard. The case must be ATX; the reverse (an mATX motherboard in an ATX case) is fine.

None of the three problems is about the quality of the individual parts; all of them are compatibility problems.

1.2.10.2DDR5 and current standards

Computer hardware is updated with new standards every few years. Which standard a part supports determines both its speed and its compatibility with the other parts.

Table 1.2.19: Changes in current standards.
StandardWhat changed?What to watch for
DDR4 → DDR5Bandwidth and the speed range increase; DDR5 modules start at higher speeds. Power management is on the module itself; each module has two independent subchannels.Physically different: a DDR4 module does not fit a DDR5 slot (and vice versa).
PCIe 3 → 4 → 5Bandwidth per lane roughly doubles with each generation.The slot is backward compatible; the speed is set by the slower of the slot and the device.
USB 3.2 → USB4USB-C connector, 20/40 Gbit/s, and Thunderbolt compatibility; USB4 Version 2.0 defines even higher speeds.Not every USB-C port supports these speeds.
Wi-Fi 6 → 76 GHz band (introduced with 6E), channel width up to 320 MHz, multi-link operation (MLO).Both the router and the device must support it.

Some of the terms in the table should be explained. Bandwidth is the amount of data a connection can carry per unit of time. Backward compatible means that a new standard can also work with old devices. The channel width in Wi-Fi is the range of frequencies the wireless transmission uses; a wide channel means more data carried at once. MLO (Multi-Link Operation) is a device’s using several frequency bands at the same time.

Example 1.2.24

A PCIe 4.0 x4 NVMe SSD is plugged into a PCIe 3.0 x4 M.2 slot. Does the SSD work? What is the theoretical top speed?

  1. Operation. PCIe is backward compatible; the SSD works.
  2. Speed. The speed is set by the slower of the slot and the device: PCIe 3.0. By the calculation in Example 1.2.19, the 3.0 x4 limit is ≈ 3.94 GB/s. Even if the SSD’s own limit is 7 GB/s, in this slot it reaches at most about 3.9 GB/s.
Common mistake

Thinking that DDR generations are backward compatible like PCIe. PCIe cards work in the slots of different generations, but the notches of DDR4 and DDR5 modules are in different places, and they cannot be physically plugged into each other’s slots.

1.2.10.3Choosing by purpose

There is no “best” computer for every user; there is the computer best suited to the purpose of use. When the budget is limited, money is directed to the components the job needs most.

Table 1.2.20: Priority components by use.
UsePriority components
Office and educationbalanced CPU, enough RAM, SSD, ergonomic screen
GamingGPU, CPU, cooling, high-refresh-rate screen
Content creationmulticore CPU, GPU, RAM, color accuracy, fast storage
Data analysisRAM capacity, CPU/GPU, fast storage
Portable usebattery, weight, screen, connections, energy efficiency

The logic of the table rests on what was explained in the earlier sections. Office work is lightweight and single-threaded; many cores or a powerful GPU make little difference, but an SSD makes programs open quickly. In games every frame is drawn on the GPU, so the graphics card is decisive; a high-refresh-rate screen is useful only if the GPU can produce enough frames. Content-creation jobs such as video editing can be split up; they benefit directly from many cores and fast storage. Programs that process large datasets want to keep the data in RAM; if RAM is not enough, the system uses the disk and slows down noticeably.

Example 1.2.25

There are two options for the same budget. (A) A powerful discrete GPU, 8 GB of RAM, and a 1 TB HDD. (B) An integrated GPU, 16 GB of RAM, and a 512 GB NVMe SSD. Which suits a student who takes lecture notes, does research on the internet, and keeps several programs open at the same time?

  1. Workload. Text editing, the browser, and office programs put little load on the GPU; an integrated GPU is enough.
  2. RAM. Having many browser tabs and programs open at once needs RAM. With 8 GB the system may start using swap space; 16 GB is more comfortable.
  3. Storage. Startup of the operating system and programs depends on storage speed. An NVMe SSD is much faster than an HDD (1.2.9.5).

B is more suitable for this use. Option A is strong for gaming, but in this student’s daily tasks it would feel slower because of the slow disk and little RAM.

1.2.11Summary

  • Hardware is the physical parts of a computer; software tells these parts what to do. Every task consists of the steps input, processing, memory, storage, and output.
  • The CPU processes instructions in the fetch–decode–execute cycle. The ALU calculates, the control unit manages the flow, and the registers hold the current values. The duration of a clock cycle is 1 ÷ clock speed (≈ 0.33 ns at 3 GHz). Performance is determined by clock speed, number of cores, cache, and architecture together; “8 cores = 8 times the speed” is not true.
  • x86-64 is common in desktops and servers and ARM in mobile devices; RISC-V is an open instruction set. A SoC gathers the CPU, GPU, NPU, and controllers on a single chip.
  • The motherboard connects the components and determines compatibility (socket, DIMM, PCIe, M.2, SATA, chipset). RAM is temporary and fast; every byte has an address. The UEFI in ROM/flash initializes the hardware at startup and loads the operating system.
  • In the memory hierarchy, going up, speed increases and capacity decreases: register < 1 ns, cache 1–10 ns, RAM 50–100 ns, SSD ≈ 0.1 ms, HDD 5–10 ms. An SSD is 1000–2000 times slower than RAM; an HDD is 50–100 times slower than an SSD.
  • In the cache, finding the data is a hit (≈ 1 ns) and not finding it is a miss (≈ 80 ns); on a miss the whole cache line is fetched. Sequential access exploits spatial locality, and repeated access to the same data exploits temporal locality. Summing an 8-element array takes 166 ns with a cache and 640 ns without.
  • A GPU works in parallel with thousands of simple cores; an integrated GPU shares RAM, while a discrete GPU has its own VRAM. HDMI and DisplayPort carry digital video, VGA analog. In USB, the connector shape and the version (speed) are separate; a speed in bits is divided by 8 to convert to bytes.
  • In the sound card, the ADC samples analog sound into numbers and the DAC turns numbers back into a signal. Recording size = sampling rate × sample size × channels × duration.
  • The case provides airflow; an overheating processor slows down by thermal throttling. The power supply converts AC to DC; its capacity is chosen above the total need with a safe margin (420 W × 1.3 = 546 W → 550 W).
  • Whether a device is input or output is determined by the direction of the data flow; the touch screen, storage, and network card work in both directions.
  • PPI = √(horizontal² + vertical²) ÷ diagonal; resolution and size together determine sharpness. Frame duration = 1000 ÷ Hz in ms; refresh rate and response time measure different things. An LCD uses a backlight; in an OLED each pixel produces its own light.
  • The CPU runs the program from RAM, not from the SSD; unsaved changes are in RAM. HDD access = seek + rotational latency (half a turn) + transfer, and takes milliseconds. NVMe exceeds SATA’s ≈ 550 MB/s limit over PCIe; M.2 is a form factor, not a protocol. 1 TB = 1012 bytes ≈ 931.3 GiB.
  • In system design, compatibility is checked in physical, electrical, logical, connection, thermal, and software terms. PCIe is backward compatible, DDR4 and DDR5 are not. Components are prioritized by purpose of use.
Table 1.2.21: Main calculations used in these notes.
CalculationFormulaExample
Clock cycle1 ÷ clock speed3.2 GHz → 0.3125 ns
Time with a cachemisses × 80 + hits × 1 (ns)2 misses, 6 hits → 166 ns
Bits → bytesMbit/s ÷ 8 = MB/s480 Mbit/s → 60 MB/s
Sound recordingsamples/s × bytes × channels × s48,000 × 2 × 1 × 30 = 2,880,000 bytes
Power supplytotal × 1.3, model above420 W → 546 W → 550 W
Pixel density√(w² + h²) ÷ diagonal1920 × 1080, 24 inches → ≈ 91.8 PPI
Frame duration1000 ÷ Hz (ms)144 Hz → ≈ 6.9 ms
HDD accessseek + half a turn + transfer5 + 4.17 + 0.03 ≈ 9.2 ms
Copyingsize ÷ speed10,000 MB ÷ 550 MB/s ≈ 18.2 s
GB → GiBbytes ÷ 2301 TB → ≈ 931.3 GiB

1.2.12Key terms

  • hardware
  • central processing unit (CPU)
  • core
  • clock speed
  • clock cycle
  • thread
  • instruction set
  • System-on-Chip (SoC)
  • neural processing unit (NPU)
  • motherboard
  • chipset
  • slot
  • lane (PCIe)
  • random access memory (RAM)
  • volatile / non-volatile
  • swap space
  • read-only memory (ROM)
  • firmware
  • BIOS / UEFI
  • power-on self-test (POST)
  • memory hierarchy
  • cache
  • cache hit / miss
  • cache line
  • spatial locality
  • temporal locality
  • graphics processing unit (GPU)
  • video memory (VRAM)
  • ADC / DAC
  • thermal throttling
  • power supply unit (PSU)
  • input / output device
  • pointing device
  • polling rate
  • resolution
  • pixel density (PPI)
  • aspect ratio
  • refresh rate
  • response time
  • backlight
  • hard disk drive (HDD)
  • solid-state drive (SSD)
  • platter
  • seek time
  • rotational latency
  • sequential read
  • backup
  • compatibility
  • bandwidth
  • backward compatible

1.2.13Test Yourself

  1. How long does one clock cycle take on a 2.5 GHz processor? If each instruction takes 5 cycles on average, how many instructions does the processor execute per second?

    Answer

    One cycle is 1 ÷ (2.5 × 109) s = 0.4 × 10−9 s = 0.4 ns. 2.5 × 109 cycles are made per second and each instruction takes 5 cycles: 2.5 × 109 ÷ 5 = 500 million instructions/s.

  2. Ten independent, indivisible jobs, each taking 3 seconds on a single core, are run on a 4-core processor. What are the total time and the speedup over a single core?

    Answer

    The number of rounds is 10 ÷ 4 = 2.5 rounded up: 3 rounds. In the first two rounds 4 jobs run each, in the last round 2. The total time is 3 × 3 = 9 s. On a single core it would have taken 10 × 3 = 30 s; the speedup is 30 ÷ 9 ≈ 3.3 times, not 4.

  3. An array of 12 integers (4 bytes each) is summed in order. The cache line is 32 bytes, the cache starts empty; a hit takes 1 ns and a miss 80 ns. How many misses occur and what is the total time?

    Answer

    One line holds 32 ÷ 4 = 8 elements. a[0]…a[7] are in the first block and a[8]…a[11] in the second. There is a miss at a[0] and a[8], and the remaining 10 accesses hit: 2 × 80 + 10 × 1 = 170 ns. Without a cache it would have taken 12 × 80 = 960 ns.

  4. L1 ≈ 1 ns, L2 ≈ 3 ns, L3 ≈ 10 ns, RAM ≈ 80 ns. At the start, L1 holds A, L2 holds B, and L3 holds B and C. The processor reads C, B, C in turn; data that is found is copied to the upper levels. How long does each read take?

    Answer

    C: not in L1 (1), not in L2 (+3), in L3 (+10) → 14 ns; C is copied to L2 and L1. B: not in L1 (1), in L2 (+3) → 4 ns; B is copied to L1. C: now in L1 → 1 ns. The total is 19 ns; if all had been read from RAM it would have been 240 ns.

  5. A 1-minute uncompressed recording is made in stereo at 48,000 samples/s and 24 bits (3 bytes) per sample. How many bytes and about how many MiB does it take?

    Answer

    Per second 48,000 × 3 × 2 = 288,000 bytes; in 60 seconds 288,000 × 60 = 17,280,000 bytes. 17,280,000 ÷ 1,048,576 ≈ 16.5 MiB.

  6. What is the PPI of a 15.6-inch laptop screen with a resolution of 2560 × 1440? If this screen is 165 Hz, how many ms does a frame stay on the screen?

    Answer

    √(2560² + 1440²) = √8,627,200 ≈ 2937.2; 2937.2 ÷ 15.6 ≈ 188.3 PPI. The frame duration is 1000 ÷ 165 ≈ 6.1 ms.

  7. An HDD spinning at 5400 rpm has an average seek time of 12 ms and a transfer rate of 120 MB/s. What is the average access time of a 4 KB sector? (1 MB = 1000 KB)

    Answer

    One turn is 60,000 ÷ 5400 ≈ 11.11 ms; the rotational latency, half a turn, is ≈ 5.56 ms. The transfer is 0.004 MB ÷ 120 MB/s ≈ 0.033 ms. The total is 12 + 5.56 + 0.03 ≈ 17.6 ms.

  8. About how many GiB does a disk labeled “2 TB” on the box show in an operating system that computes with base 1024?

    Answer

    2 TB = 2 × 1012 bytes. 2 × 1012 ÷ 230 ≈ 1862.6 GiB. The byte count is the same; the difference comes only from the unit.

  9. In a system the processor draws 65 W, the graphics card 160 W, and the other components 50 W. A 30% margin is to be left; models of 300, 400, 450, and 550 W are available. Which is chosen?

    Answer

    The total is 65 + 160 + 50 = 275 W; with the margin 275 × 1.3 = 357.5 W. The smallest model that does not fall below this is 400 W.

  10. A program file sits on the SSD. When the program is opened and a calculation is done, through which devices, in which order, does the data pass? What happens when the result is saved?

    Answer

    The program is copied from the SSD to RAM; the CPU brings instructions and data from RAM into the cache and from there into the registers and processes them: SSD → RAM → cache → registers. The result goes through the graphics card to the monitor. When saved, the data is written from RAM to the SSD; until it is saved, the changes are only in RAM.

1.2.14Further reading

  • C. Petzold, Code: The Hidden Language of Computer Hardware and Software (2nd ed., 2022): starting from binary numbers and logic gates, it explains step by step how a processor is built, without requiring background knowledge.
  • D. A. Patterson and J. L. Hennessy, Computer Organization and Design RISC-V Edition (2nd ed., 2020), Chapters 1 and 5: treat in detail how performance is calculated from clock speed and instruction count, the memory hierarchy, and cache design.
  • R. E. Bryant and D. R. O’Hallaron, Computer Systems: A Programmer’s Perspective (3rd ed., 2015), Chapter 6: covers storage technologies, the calculation of HDD access time, and the effect of locality on program speed from the programmer’s viewpoint.

1.2.15References

  1. D. A. Patterson, J. L. Hennessy, Computer Organization and Design RISC-V Edition: The Hardware/Software Interface, 2nd ed., Morgan Kaufmann, 2020.
  2. W. Stallings, Computer Organization and Architecture, 11th ed., Pearson, 2019.
  3. R. E. Bryant, D. R. O’Hallaron, Computer Systems: A Programmer’s Perspective, 3rd ed., Pearson, 2015.
  4. C. Petzold, Code: The Hidden Language of Computer Hardware and Software, 2nd ed., Microsoft Press, 2022.
  5. Technical standards of PCI-SIG (PCI Express), USB-IF (USB), VESA (DisplayPort), and JEDEC (DDR memory).