Networks and addresses: from your device to the world
Lesson 1 of 3
1Networks and addresses: from your device to the world
The big pictureEvery photo you send is cut into small packets, each carrying a sender and receiver address, hopping between routers until it arrives, then reassembled.
What the picture shows: The packet hops device to device. Each router reads only the destination address and picks the next hop; nobody knows the whole route.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
Think of the post: your letter is in an envelope with your address and the recipient's. Your local post office does not know the recipient's house, but it knows which office is closer, so it sends it on. The internet works the same; the envelope is a "packet" and the address an "IP".
The TCP/IP model has four layers: link (Ethernet/Wi-Fi), internet (IP routes packets between networks), transport (TCP is reliable and ordered via a three-way handshake and retransmission; UDP has no guarantees and is faster), and application (HTTP, DNS). IPv4 addresses are 32 bits, IPv6 128 bits, and NAT makes all your home devices appear under one public address.
Before You Start
🔌How a computer works
You know everything in a computer is bits.
The Core Idea
1The IP address: a device's house number
Every connected device has an address, such as 192.168.1.20 inside your home or 142.250.74.46 on the internet. A private address (often starting 192.168 or 10.) is invisible from outside; the router translates between it and the public one.
import ipaddress
for text in ["192.168.1.20", "10.0.0.5", "142.250.74.46"]:
ip = ipaddress.ip_address(text)
print(text, "private" if ip.is_private else "public")2Packets and routers
Data does not travel in one piece. It is split into packets (usually under 1500 bytes), and each may take a different road. A router reads the destination and forwards the packet to the next hop. The traceroute command (tracert on Windows) shows you the hops.
3The port: the flat number inside the building
The IP gets you to the machine, but it runs many programs. The port says which one: 443 for HTTPS sites, 22 for SSH, 5432 for a PostgreSQL database. That is why you see addresses like localhost:3000.
4TCP versus UDP
TCP is like a phone call: it starts with a handshake, numbers the packets and resends lost ones, so everything arrives in order. Websites and email use it. UDP is like a loudspeaker: it sends without checking; faster, but packets can be lost. Video calls and games use it, where delay hurts more than a lost frame.
Worked example
Problem: you opened https://example.com in a browser. What address, port and protocol? Answer: the name becomes an IP address (next lesson), and https means port 443 over TCP. The request packets pass your router and your ISP until they reach the server.
from urllib.parse import urlsplit
DEFAULT = {"http": 80, "https": 443}
for url in ["https://example.com/docs", "http://localhost:3000/api"]:
parts = urlsplit(url)
print(parts.hostname, parts.port or DEFAULT[parts.scheme], parts.scheme)Myth vs Reality
| Myth | Reality |
|---|---|
| The internet is the web. | The web is one application on the internet, alongside email, games and video calls. |
| A packet follows a fixed road. | Each router decides on the spot; packets may arrive by different roads and in a different order, and TCP reorders them. |
Test your understanding
Which number picks the program inside a machine?
The IP gets you to the machine; the port gets you to the program listening on it.
A fast multiplayer game prefers losing a frame to lagging. Which transport fits?
UDP never waits for a resend, so a lost packet does not stall it.
What is the default port for HTTPS?
80 is plain HTTP; 443 is HTTPS.
Quick review cards
Check Your Understanding
Why can nobody outside your home see 192.168.1.20?
Because it is private. The router swaps it for its public address through NAT, so all home devices appear as one.
What does TCP do when a packet is lost?
It notices no acknowledgement came back, resends it, and orders the packets before handing them to the program.
What does localhost:3000 mean?
Your own machine (address 127.0.0.1) and the program listening on port 3000, often a development server.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Official docs1
Done with this lesson?
Sign in to save your progress.