What a network is
A network is a set of devices connected so they can talk to each other. Your home WiFi is one: the laptop, phone, smart TV and printer, all joined through the home router.
Wide by design - scroll it sideways.
Devices on the same network reach each other directly. When you print a Kadé invoice, the laptop sends it straight to the printer. Reaching anything outside, like api.kade.lk, means leaving the network through the router. Chapter 4 shows how the laptop decides which case it is in.
Hosts
A host is any single device on a network that has its own IP address. The home network above has five hosts: the four devices and the router itself (192.168.1.1). In the cloud, kade-api and kade-db are hosts on kade-vpc.
Each host needs a unique address on its network, so data is delivered to exactly the right one. If two devices end up with the same address (an IP conflict), both start losing their connections.
How devices get their IP: DHCP
You never type these addresses in. When a device joins, the router hands it one using DHCP (Dynamic Host Configuration Protocol). It takes four messages, often remembered as DORA:
Dashed amber = broadcast (sent to every device). The laptop has no address yet, so it can only shout. Leases are renewed quietly, usually at half the lease time.
Wide by design - scroll it sideways.
The Offer carries more than an address. It gives the laptop everything it needs to use the network, and every item shows up again later in the course:
| Setting | Value | Used for |
|---|---|---|
| IP address | 192.168.1.23 | The laptop's own addresschapter 2 |
| Subnet mask | 255.255.255.0 | Telling "same network" from "somewhere else"chapter 4 |
| Default gateway | 192.168.1.1 | Where to send anything not on this networkthe router's MAC in chapter 1's frame |
| DNS server | 192.168.1.1 | Who to ask for names like api.kade.lkthe router passes questions on to the ISP's resolver |
| Lease time | 24 hours | How long the address is the laptop'sthen it must renew |
The router keeps a table of who has which address. It matches devices by MAC address:
| Device | MAC | IP | Type |
|---|---|---|---|
| Laptop | a4:83:e7:2b:91:0c | 192.168.1.23 | Dynamiclease ends in 17 h |
| Phone | 5e:1a:0b:c3:77:e2 | 192.168.1.40 | Dynamiclease ends in 9 h |
| Smart TV | 90:0f:3d:12:a8:4b | 192.168.1.52 | Dynamiclease ends in 22 h |
| Printer | 00:1b:a9:44:7c:21 | 192.168.1.60 | Reservedalways gets .60 |
LAN and WAN
The home network is a LAN (Local Area Network): devices in one place, on one network. Everything beyond it, the ISP and the wider internet, is the WAN (Wide Area Network). Most of networking is about how a device on your LAN reaches something out on the WAN.
The router stands on both sides and has two addresses. The ISP gives it the WAN address, also with DHCP. The internet only ever sees 203.0.113.45, never 192.168.1.x.
Wide by design - scroll it sideways.
CIDR notation
To describe a whole network we need a way to name a range of addresses. CIDR (Classless Inter-Domain Routing) does it in one short line: an IP, a slash, and a number. The home network is 192.168.1.0/24.
- network part: 24 bits
- host part: 8 bits
192.168.1.0 is 11000000 10101000 00000001 00000000 in binary. The first 24 bits are the network part and the last 8 the host part.
- The /24 is how many bits, counted from the left, form the network part. The rest are the host part.
- The .0 address is the network address: the name of the network as a whole. Keep the network bits and set every host bit to 0, and you get it:
192.168.1.0. Routes and firewall rules use it to mean "this whole network". It is never given to a device. - The .255 address is the broadcast address: set every host bit to 1 instead. A message sent to it reaches every device on this network. It is not given to a device either.
You will also meet the same split written a second way, as a subnet mask. For a /24 it is 255.255.255.0: 24 ones, then 8 zeros, written like an address. It is what your laptop got from DHCP (above). Chapter 4 shows how a device uses it to decide where to send each packet.
In 192.168.1.0/24, the first 24 bits (three octets: 8 + 8 + 8) are the network part. They are the same for every device on the network. The last 8 bits (the last octet) are the host part, different for each device:
| Laptop | 192.168.1.23 | same network, host 23 |
| Phone | 192.168.1.40 | same network, host 40 |
| Printer (new) | 192.168.1.60 | plugged in today: network part unchanged, only the host part is new |
How many hosts fit
The number of host bits decides how many addresses the network has. With 8 host bits (a /24), there are 28 = 256 addresses. Two of them are reserved (network and broadcast), which leaves 254 for devices, and the router takes one of those.
Reading CIDR ranges
A smaller number after the slash means fewer network bits, more host bits and a bigger network.
| CIDR | Network bits | Host bits | Addresses | Example |
|---|---|---|---|---|
| /32 | 32 | 0 | 1 | One exact address. A firewall rule for "only my home": 203.0.113.45/32 |
| /28 | 28 | 4 | 16 | A tiny subnet |
| /24 | 24 | 8 | 256 | Home LAN 192.168.1.0/24, sn-app 10.10.1.0/24 |
| /20 | 20 | 12 | 4,096 | Size of the subnets GCP creates for you in "auto mode" VPCs |
| /16 | 16 | 16 | 65,536 | kade-vpc 10.10.0.0/16 |
| /8 | 8 | 24 | 16,777,216 | The whole private range 10.0.0.0/8 |
| /0 | 0 | 32 | 4,294,967,296 | 0.0.0.0/0: every address, "the entire internet". Seen in routes and "allow from anywhere" rules. |
CIDR in the cloud
CIDR is used everywhere in cloud work. When kade-vpc was created, its range was chosen with CIDR: 10.10.0.0/16. That range holds 256 blocks of /24, and Kadé uses two of them as subnets:
- sn-app 10.10.1.0/24
- sn-data 10.10.2.0/24
- free: 254 more /24 blocks (10.10.0.0, 10.10.3.0 … 10.10.255.0)
Each square is one /24 block inside kade-vpc’s /16. A /16 has 16 host bits; using 8 of them for the block number gives 28 = 256 blocks.
Subnets inside one VPC must not overlap. GCP also keeps 4 addresses in every subnet for itself, not 2:
| sn-app address | Kept for |
|---|---|
| 10.10.1.0 | The network address |
| 10.10.1.1 | The default gateway for VMs in this subnet |
| 10.10.1.254 | Reserved by Google for future use |
| 10.10.1.255 | The broadcast address |
Type any range. The calculator shows its network address, the same range as a subnet mask, its broadcast address, and how many addresses are left for devices: at home, and in a GCP subnet, where 4 are kept.
- Network address
- 10.10.1.0
- Subnet mask
- 255.255.255.0
- First usable
- 10.10.1.1
- Last usable
- 10.10.1.254
- Broadcast address
- 10.10.1.255
- Total addresses
- 256 (2^8)
- Usable on a normal network
- 254
- Usable in a GCP subnet
- 252
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | Network | Devices connected so they can talk directly | network |
| 2 | Host | One device with its own IP on a network | host, IP conflict |
| 3 | DHCP | Router hands out IP, mask, gateway, DNS and a lease in 4 messages | DORA, lease, reservation, static IP |
| 4 | LAN / WAN | Your local network vs everything beyond it; the router sits on both | LAN, WAN |
| 5 | CIDR | IP/prefix: prefix bits are the network part, the rest the host part | CIDR, network address, broadcast address |
| 6 | Size | 2(32 − prefix) addresses, minus 2 for devices (minus 4 in GCP) | |
| 7 | Reading ranges | Smaller prefix = bigger network; /32 is one address, /0 is all of them | |
| 8 | Cloud | VPCs and subnets are CIDR ranges and must not overlap | VPC, subnet |
Try it yourself
The DHCP answer your laptop got
- What to look for:
yiaddr(your IP),router,subnet_mask,domain_name_server,lease_time. - Runs on: macOS · Windows: ipconfig /all · Linux: nmcli device show
- From section: 3. How devices get their IP: DHCP
ipconfig getpacket en0Run DHCP again
- What to look for: Usually the same IP comes back: the router remembers your MAC.
- Runs on: macOS · Windows: ipconfig /release then ipconfig /renew
- From section: 3. How devices get their IP: DHCP
sudo ipconfig set en0 DHCPOther hosts your laptop has talked to on the LAN
- What to look for: Their IPs and MACs, all in 192.168.1.x.
- From section: 2. Hosts
arp -aYour IP with its prefix
- What to look for:
192.168.1.23/24and the worddynamic(from DHCP). - Runs on: Linux
- From section: 5. CIDR notation
ip -4 addrSize and broadcast of a range
- What to look for:
256 192.168.1.255 - From section: 6. How many hosts fit
python3 -c "import ipaddress as i; n=i.ip_network('192.168.1.0/24'); print(n.num_addresses, n.broadcast_address)"A VPC's subnets and their ranges
- What to look for: The RANGE column is CIDR.
- From section: 8. CIDR in the cloud
gcloud compute networks subnets list --network=kade-vpc