Networking Intro
A computer network is a set of devices that can exchange data with each other. Your laptop and your home router form a network. So do the thousands of servers inside a data centre, and the Internet is a "network of networks" that links millions of them together.
Every time you open a web page, a surprising amount happens in a fraction of a second: your computer finds the server's address, opens a connection, sends a request split into small pieces called packets, and puts the reply back together in the right order. This course takes that process apart, one layer at a time.
What a network is made of
| Part | What it is | Examples |
|---|---|---|
| Nodes (hosts) | Devices that send or receive data | laptops, phones, servers, printers, IoT sensors |
| Links | The physical or wireless path between nodes | copper Ethernet cable, fibre, Wi-Fi radio |
| Network devices | Boxes that move data between links | switches, routers, access points, firewalls |
| Protocols | The agreed rules for how data is formatted and exchanged | Ethernet, IP, TCP, DNS, HTTP |
Protocols are the heart of networking. Two machines built by different companies, running different operating systems, can still talk because both follow the same published rules.
Messages are just bytes
Everything sent over a network is, in the end, a sequence of bytes. A protocol says what those bytes mean. Here is a tiny HTTP request, the text a browser sends when you visit a page, and its size in bytes:
request = (
"GET /index.html HTTP/1.1\r\n"
"Host: example.com\r\n"
"\r\n"
)
data = request.encode("ascii")
print(len(data), "bytes")
print(data[:16])
print(list(data[:4]))47 bytes
b'GET /index.html '
[71, 69, 84, 32]
The numbers 71, 69, 84, 32 are the ASCII codes of G, E, T and a space. A network card does not know or care that this is HTTP: it just moves bytes. Each layer of software adds its own meaning on top.
Note: All examples in this course run in your browser with Python. Browsers do not let a page open raw network connections, so we build and parse real protocol messages as bytes and simulate devices and protocols. Real tools such as
ping,tracerouteanddigare shown with sample output that you can reproduce on your own machine.
Packets: why data is chopped up
Networks do not send a 5 MB photo as one giant blob. Data is split into packets (a few hundred to about 1500 bytes each). Each packet carries a header with addressing information, so it can travel on its own. This has big advantages:
- Many conversations can share the same link, taking turns packet by packet.
- If one packet is lost, only that packet needs to be resent.
- Packets can take different paths around a broken link.
photo_size = 5_000_000 # bytes
payload_per_packet = 1460 # a typical TCP payload on Ethernet
packets = -(-photo_size // payload_per_packet) # ceiling division
print("packets needed:", packets)
print("last packet carries", photo_size - (packets - 1) * payload_per_packet, "bytes")packets needed: 3425
last packet carries 960 bytes
Addresses at different levels
To deliver a packet, the network needs to know where it goes. You will meet several kinds of address in this course:
| Address | Example | Used for |
|---|---|---|
| MAC address | 3c:22:fb:91:0a:7e |
one hop on a local network (Ethernet, Wi-Fi) |
| IP address | 192.168.1.20, 2001:db8::1 |
end-to-end delivery across networks |
| Port number | 443 |
which program on the host gets the data |
| Domain name | www.example.com |
a human-friendly name, translated to an IP by DNS |
Bandwidth and latency
Two numbers describe how "fast" a network is:
- Bandwidth (throughput): how many bits per second the link can carry, for example 100 Mbit/s.
- Latency: how long a single bit takes to get from one end to the other, for example 20 ms.
A common mistake is to mix up bits and bytes. Link speeds are given in bits per second, file sizes in bytes. One byte is 8 bits.
file_bytes = 250_000_000 # a 250 MB download
link_bits_per_s = 100_000_000 # 100 Mbit/s
latency_s = 0.020 # 20 ms one way
transfer = file_bytes * 8 / link_bits_per_s
print(f"transfer time: {transfer:.1f} s")
print(f"plus latency: {transfer + latency_s:.2f} s")
tiny = 500 * 8 / link_bits_per_s
print(f"500-byte message: {tiny * 1000:.2f} ms on the wire, {latency_s * 1000:.0f} ms latency")transfer time: 20.0 s
plus latency: 20.02 s
500-byte message: 0.04 ms on the wire, 20 ms latency
For big files, bandwidth dominates. For small messages (a click, a game move, a DNS lookup), latency dominates. That is why a "faster" plan doesn't always make web browsing feel quicker.
Your first real tool: ping
ping sends a small message to a host and measures how long the reply takes. Try it in a terminal:
ping -c 3 example.comSample output:
PING example.com (93.184.215.14) 56(84) bytes of data.
64 bytes from 93.184.215.14: icmp_seq=1 ttl=56 time=11.8 ms
64 bytes from 93.184.215.14: icmp_seq=2 ttl=56 time=11.5 ms
64 bytes from 93.184.215.14: icmp_seq=3 ttl=56 time=11.9 ms
--- example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 11.5/11.7/11.9/0.2 msAlready you can see several ideas from this lesson: a name (example.com) turned into an IP address, a packet size in bytes, and a round-trip latency in milliseconds. By the end of the course you will be able to build that ping packet yourself, byte by byte.
Test yourself
What does a network protocol define?
- The colour of network cables
- The rules for formatting and exchanging data
- The price of a router
- The speed of the CPU
A link runs at 80 Mbit/s. Ignoring latency, how long does a 10 MB (10,000,000 byte) file take?
- 0.125 s
- 1 s
- 8 s
- 80 s
Why is data split into packets?
- So links can be shared and lost pieces resent individually
- Because cables can only carry one byte at a time
- To make files smaller
- Packets are only used by Wi-Fi