This is the chapter people skip and then struggle with in cloud networking for years. Take it slowly and do the exercises by hand.
The Plain Picture#
A phone number like 080-4123-4567: the first part (080) says which city, the rest says which
phone in that city. If you and your friend share the first part, you're in the same city — a local call.
If not, the call has to go through long-distance exchanges.
How long is the "city" part? The phone company decides. Big cities might use a short city code and long local numbers; small towns the opposite.
The Real Names#
Every IP address is split into two parts:
the network part (the "city" — which network the device is on),
the host part (the "phone" — which device inside that network).
A group of addresses sharing the same network part is a network or subnet (sub-network).
Where the split is is written with CIDR notation (Classless Inter-Domain Routing): a slash and the number of network bits.
192.168.1.37/24means: the first 24 bits are the network part; the remaining 8 bits are the host part.The same split can be written as a subnet mask: 1s for network bits, 0s for host bits.
/24=11111111.11111111.11111111.00000000=255.255.255.0.
Why it matters: your computer uses the subnet to decide "is this destination my neighbour (send it directly on the LAN) or not (send it to the router)?" (Chapter 7). And in the cloud, you'll design subnets yourself when you build a VPC (VPC and Networking (coming soon)).
Under the Hood#
Worked example 1 — 192.168.1.37/24#
address 1100 0000 . 1010 1000 . 0000 0001 . 0010 0101 (192.168.1.37)
mask /24 1111 1111 . 1111 1111 . 1111 1111 . 0000 0000 (255.255.255.0)
└──────────── network (24 bits) ────────┘ └ host ┘Network address: keep the network bits, set every host bit to 0 →
192.168.1.0. This is the subnet's name.Broadcast address: network bits, every host bit set to 1 →
192.168.1.255. Sending here reaches everyone on the subnet.Total addresses: 8 host bits → 2⁸ = 256.
Usable for devices: 256 − 2 (network address + broadcast address) = 254:
192.168.1.1to192.168.1.254.
The quick formula#
host bits = 32 − prefix
total addresses = 2^(host bits)
usable devices = total − 2 (network + broadcast addresses can't be used)| CIDR | Mask | Host bits | Total | Usable | Typical use |
|---|---|---|---|---|---|
| /32 | 255.255.255.255 | 0 | 1 | (one exact address) | a single machine in a firewall rule |
| /30 | 255.255.255.252 | 2 | 4 | 2 | a link between two routers |
| /28 | 255.255.255.240 | 4 | 16 | 14 | small cloud subnet |
| /26 | 255.255.255.192 | 6 | 64 | 62 | |
| /24 | 255.255.255.0 | 8 | 256 | 254 | home network, typical cloud subnet |
| /20 | 255.255.240.0 | 12 | 4,096 | 4,094 | |
| /16 | 255.255.0.0 | 16 | 65,536 | 65,534 | typical cloud VPC |
| /8 | 255.0.0.0 | 24 | 16,777,216 | ~16.7 million | |
| /0 | 0.0.0.0 | 32 | all of them | — | "the whole internet" (Ch 7) |
Notice: each step of 1 in the prefix halves or doubles the size. /24 → /25 halves 256 to 128.
Worked example 2 — 192.168.1.37/26: which subnet, and who's a neighbour?#
/26 means 26 network bits, so 6 host bits — only the last byte is split:
last byte of .37 : 00 | 10 0101
↑ ↑
2 network bits 6 host bitsWith 6 host bits, each subnet has 2⁶ = 64 addresses, so the last byte is cut into blocks of 64:
192.168.1.0 – 192.168.1.63 ← .37 is in this block
192.168.1.64 – 192.168.1.127
192.168.1.128 – 192.168.1.191
192.168.1.192 – 192.168.1.255For 192.168.1.37/26:
network address
192.168.1.0, broadcast192.168.1.63,usable
192.168.1.1–192.168.1.62(62 devices).
Is 192.168.1.70 a neighbour of 192.168.1.37/26? .70 is in the block .64–.127, a different
subnet. No — traffic between them must go through a router, even though they "look" close.
Is 192.168.1.50 a neighbour? .50 is in .0–.63. Yes — they can talk directly.
Worked example 3 — splitting a network (what you'll do in AWS)#
You have 10.0.0.0/16 for StudyBuddy's cloud network (65,536 addresses). You want separate subnets for
web servers, app servers and databases, each in two data centres. Give each subnet a /24 (256
addresses):
10.0.0.0/16 ── the whole network ("VPC")
├── 10.0.1.0/24 web servers, data centre A
├── 10.0.2.0/24 web servers, data centre B
├── 10.0.11.0/24 app servers, data centre A
├── 10.0.12.0/24 app servers, data centre B
├── 10.0.21.0/24 databases, data centre A
└── 10.0.22.0/24 databases, data centre BA /16 holds 256 of these /24 subnets (the third byte picks one: 0–255), so there's lots of room to
grow. Subnets inside a network must not overlap.
Cloud providers reserve a few addresses in each subnet for their own use. AWS reserves 5 per subnet
(the network address, the next three, and the last), so a /24 in AWS gives 251 usable addresses, not
254.
Checking "is address X in network Y?" — the general method#
Write both in binary (or just the byte(s) where the prefix ends).
Compare only the first prefix bits.
Same → same subnet. Different → different subnet.
Shortcut when the prefix is a multiple of 8 (/8, /16, /24): just compare whole numbers. 10.0.5.9 is in
10.0.0.0/16 because the first two bytes (10.0) match.
Gotchas
Overlapping ranges are the #1 cloud networking mistake. If your office network and your cloud VPC both use
10.0.0.0/16, you can never connect them directly — every address is ambiguous. Plan ranges up front."Close" addresses may not be neighbours (
.37and.70in /26), and "far" ones may be (10.0.0.5and10.0.255.200are both in10.0.0.0/16). Only the prefix bits matter.Picking a subnet too small is painful: you usually can't resize a cloud subnet later. Kubernetes especially eats IP addresses (every pod gets one — Kubernetes Internals and Extending It (coming soon)).
Check yourself
5 questionsHow many usable addresses in a /27?
Show answerHide answer
32 − 27 = 5 host bits → 2⁵ = 32 total → 30 usable.
What's the network address and broadcast address of 172.16.5.130/25?
Show answerHide answer
/25 splits the last byte into two blocks of 128: .0–.127 and .128–.255. .130 is in the second.
Network 172.16.5.128, broadcast 172.16.5.255.
Are 10.1.2.3/16 and 10.1.200.9 on the same subnet?
Show answerHide answer
Yes — /16 compares only the first two bytes, and both are 10.1.
Are 192.168.10.20/28 and 192.168.10.33 on the same subnet?
Show answerHide answer
/28 = blocks of 16 in the last byte: .16–.31, .32–.47. .20 is in the first, .33 in the second →
No.
You need a subnet for 500 servers. What's the largest prefix number (smallest subnet) that works?
Show answerHide answer
You need ≥ 502 addresses (500 + network + broadcast). 2⁹ = 512 ≥ 502, so 9 host bits → /23. (In AWS, 500 + 5 reserved = 505 ≤ 512, still /23.)