Learn / Networking Fundamentals / Addressing
IP Addresses & Subnets
First Bit is still up for grabs: be the first to finish this room.
Every scan result, firewall rule and log line you'll ever read is full of IP addresses. By the end of this room you'll be able to look at an address with a slash on the end and work out its network, its broadcast address and how many machines can live next to it, without a calculator.
Task 1 Anatomy of an IPv4 address
An IPv4 address is a 32-bit number. Nobody reads 32 ones and zeros, so we split it into four 8-bit chunks called octets and write each one in decimal, separated by dots:
192 .168 .10 .37
11000000 10101000 00001010 00100101
Eight bits can count from 00000000 to 11111111, so each octet runs from 0 to 255. An address like 192.168.10.300 isn't valid: 300 doesn't fit in an octet.
Task 2 The network part and the host part
Every address has two parts: the network part (which network the machine is on) and the host part (which machine on that network). The number after the slash, the prefix length, says how many bits, counted from the left, belong to the network.
In 192.168.10.37/24, the first 24 bits (192.168.10) are the network and the last 8 bits (.37) are the host.
Two addresses in every network are reserved:
- Network address: all host bits set to 0. It names the network itself:
192.168.10.0. - Broadcast address: all host bits set to 1. It means "everyone on this network":
192.168.10.255.
With 8 host bits there are 2^8 = 256 addresses. Take away those two and you get the usable host addresses: .1 to .254.
Task 3 Smaller networks
A longer prefix means fewer host bits and a smaller network. A /26 leaves 6 host bits: 2^6 = 64 addresses per network, 62 of them usable.
The subnet mask is the prefix written as an address: network bits are 1s, host bits are 0s.
| Prefix | Mask | Addresses | Usable |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /28 | 255.255.255.240 | 16 | 14 |
To find the network an address belongs to, work in the last octet. A /26 cuts it into blocks of 64: 0–63, 64–127, 128–191, 192–255. Find the block your host number falls in: its first number is the network address, and its last is the broadcast.
Worked example, 172.16.5.200/28: a /28 cuts the octet into blocks of 16. 200 falls in 192–207, so the network is 172.16.5.192, the broadcast is 172.16.5.207, and hosts run from .193 to .206.
Task 4 Private ranges
Some address ranges are reserved for private networks: homes, offices, labs. They're never routed on the public internet, which is why millions of home networks can all use 192.168.1.x at the same time.
| Range | Covers |
|---|---|
10.0.0.0/8 |
10.0.0.0 – 10.255.255.255 |
172.16.0.0/12 |
172.16.0.0 – 172.31.255.255 |
192.168.0.0/16 |
192.168.0.0 – 192.168.255.255 |
Watch the middle one: it's a /12, so it covers 172.16 through 172.31 and no further. 172.40.1.1 looks private but is a public address. Getting this wrong in a firewall rule is a classic mistake.