Input, Output and Networks
Trace a keypress from switch to screen, learn how buses, interrupts and ports connect devices, and see how packets carry data across the internet.
Welcome back!
Step 1 of 13Learn
The life of a keypress
You press the letter K. Here's what happens, in about the time it takes a camera shutter to click:
- Inside the keyboard, the key closes a circuit. The keyboard's own small processor detects which key it was and turns it into a scan code, a number.
- The keyboard sends that number over USB or Bluetooth to the computer.
- The USB controller raises an interrupt, a signal that tells the CPU: stop what you're doing for a moment, something needs attention.
- The CPU saves its place and runs the keyboard driver, which reads the scan code and hands it to the operating system.
- The OS translates the scan code into the character k (using your keyboard layout) and delivers it to the app that has focus.
- The app updates its text, and asks the graphics system to redraw that part of the window.
- The GPU renders the new pixels into a frame, and the display shows it at its next refresh, 60 or more times per second.
Seven layers of hardware and software cooperate, and you see the letter appear without thinking about any of them.
Step 2 of 13Diagram
The life of a keypress
Tap a shape with to see more.
- Key closes a circuit
- Scan code sent over USB
- Interrupt to the CPU
- Driver and OS
Turn the scan code into a character and pass it to the app in focus.
- App updates
- Pixels change on screen
Step 3 of 13Learn
Interrupts vs. polling
A CPU can learn about events in two ways.
Polling means asking over and over: any key pressed? any key pressed? any key pressed? It's simple, but it wastes cycles when nothing is happening, and if the CPU checks too rarely it can miss or delay events.
Interrupts flip this around. The device signals the CPU only when something happens. The CPU finishes its current instruction, saves its state, runs a short interrupt handler and then returns exactly where it left off. This lets a processor ignore a quiet keyboard completely, yet respond within microseconds when a key is pressed.
Interrupts come from many sources: a network card receiving a packet, a disk finishing a read, a timer ticking. The timer interrupt is especially important: it fires many times per second and lets the operating system take the CPU back from a running program to give another program a turn.
For big transfers, devices also use direct memory access (DMA): the disk or network card copies data straight into RAM and only interrupts the CPU once the whole block has arrived, instead of once per byte.
Step 4 of 13Practice · True or false
With interrupts, the CPU must keep checking the keyboard in a loop to find out whether a key was pressed.
Step 5 of 13Compare
Polling vs interrupts
| Aspect | Polling | Interrupts |
|---|---|---|
| Who starts it | The CPU keeps asking | The device signals |
| When idle | Wastes cycles checking | CPU does other work |
| Good for | Very simple or very busy devices | Keyboards, network cards, disks |
Step 6 of 13Learn
Buses and ports
Parts of a computer exchange data over buses, sets of connections that carry bits between components. Some key links in a modern PC:
- The memory bus connects the CPU to RAM. It needs enormous bandwidth, tens of gigabytes per second.
- PCI Express (PCIe) connects high-speed devices such as graphics cards and NVMe SSDs. It uses lanes; a graphics card often uses 16 lanes, an SSD 4.
- USB connects external devices: keyboards, drives, phones. USB-C is the connector shape; the speed depends on which USB version the port supports.
- SATA connects older SSDs and hard drives.
Bandwidth matters because a device can only be as fast as its connection. A fast NVMe SSD on PCIe can read several gigabytes per second, while the same type of flash memory on an older SATA connection is capped at around 550 MB per second.
Not everything is wired. Wi-Fi and Bluetooth carry bits on radio waves, and a phone's cellular modem does the same over longer distances.
Step 7 of 13Practice · Match the pairs
Match each connection to its most typical use.
Tap an answer, then tap the place where it belongs (or drag it there).
- PCI Express
- Memory bus
- USB
- Bluetooth
Step 8 of 13Note
Step 9 of 13Chart
Typical ping times
Step 10 of 13Learn
Networks: computers talking in packets
A network lets computers exchange bits with each other. The internet is a network of networks, linking billions of devices.
Data doesn't travel as one continuous stream. It is chopped into packets, often around 1,500 bytes each. Every packet carries a header with the source and destination IP addresses, a bit like an envelope. Routers along the way read the destination and pass each packet one hop closer. Packets from the same file may take different routes and arrive out of order.
Protocols are the agreed rules that make this work, stacked in layers:
- IP gets packets from one address to another, with no guarantee they arrive.
- TCP numbers the packets, puts them back in order, and re-sends any that were lost, so you get a perfect copy of the file.
- DNS translates names like example.com into IP addresses.
- HTTP and HTTPS carry web pages; HTTPS adds encryption so others on the network can't read or alter them.
When you open a web page, your computer runs through DNS, TCP and HTTPS in a fraction of a second, exchanging dozens of packets before the first pixel appears.
Step 11 of 13Note
Step 12 of 13Practice · Work it out
A 15,000-byte image is sent over a network that carries 1,500 bytes of data per packet. How many packets are needed?
Step 13 of 13Practice · What would you do?
What would you do?
Sam is downloading a large game over a 300 Mbps connection, but an online match on the same connection feels laggy because actions register late. A friend says the fix is to upgrade to 1 Gbps. What should Sam understand?
Lesson complete!