Models & addressing
Networking is how one machine finds and talks to another. Several of your videos follow one app as it grows from a single server into a cloud system; this first chapter covers the basics every step builds on: layers, addresses and how a packet leaves your local network.
Layers: the OSI and TCP/IP models
Sending data is split into layers, each solving one problem and relying on the layer below. The OSI model has 7:
- Physical: cables, Wi-Fi radio, electrical signals.
- Data link: getting a frame to the next device on the same local network, using MAC addresses (Ethernet, Wi-Fi, switches).
- Network: getting packets across many networks using IP addresses and routers.
- Transport: delivering data to the right program on the machine, reliably (TCP) or quickly (UDP), using ports.
- Session: opening, managing and closing conversations.
- Presentation: formatting, compression and encryption of the data.
- Application: what the program actually speaks: HTTP, DNS, SSH, SMTP.
In practice people use the simpler 4-layer TCP/IP model (Link, Internet, Transport, Application), which folds the top three OSI layers into one. The layer numbers are still used as shorthand: a "layer 4 load balancer" works with IPs and ports, a "layer 7" one understands HTTP.
Each layer wraps the data from the layer above with its own header, like envelopes inside envelopes:
MAC addresses and switches
Every network card has a MAC address burned in (like 3c:22:fb:1a:9e:01). It only matters on the local network. A switch connects the devices of one local network and learns which MAC address sits on which port, so it can pass frames only to the right device. ARP is how a machine finds the MAC address that belongs to a local IP address.
IP addresses
An IP address identifies a device across networks. IPv4 addresses are 32 bits written as four numbers from 0 to 255 (192.168.1.10), about 4.3 billion in total, which isn't enough for the modern internet. IPv6 uses 128 bits written in hex (2001:db8::1) and has practically unlimited addresses.
Some ranges are reserved as private (RFC 1918): 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. They're used inside homes, offices and cloud networks and are never routed on the public internet, so millions of networks can reuse them. A public IP is unique on the internet. 127.0.0.1 (localhost) always means "this machine".
Addresses are handed out either by hand (static, typical for servers, so their address never changes) or automatically by a DHCP server, which is what your laptop gets when it joins Wi-Fi.
Subnets and CIDR
A subnet is a block of addresses that belong to one network. CIDR notation writes it as an address plus a slash number: the number says how many bits, from the left, are the network part. The rest are for hosts.
192.168.1.0/24: the first 24 bits (192.168.1) are fixed, the last 8 bits vary, so 28 = 256 addresses (192.168.1.0 to 192.168.1.255). The same as subnet mask255.255.255.0.10.0.0.0/16: 16 bits vary, so 65,536 addresses. A typical size for a whole cloud network.10.0.1.0/28: 4 bits vary, so 16 addresses. Bigger slash number, smaller network.
Two addresses in each subnet are special (the network address and the broadcast address), and clouds reserve a few more, so a /24 gives you slightly fewer than 256 usable hosts.
Routers and the default gateway
If the destination is in your own subnet, your machine delivers directly. Otherwise it sends the packet to its default gateway, the router for its network. A router connects networks and forwards each packet one hop closer to its destination using its routing table. Small networks use static routes typed in by hand; large ones share routes automatically with routing protocols: OSPF inside an organisation, and BGP between the big networks that make up the internet.
Your home router also does NAT (network address translation): all your private devices go out to the internet sharing its one public IP, and it remembers which reply belongs to which device.