IPv4 Addressing and Subnetting
Move the boundary between network and host bits, and watch subnets double as hosts halve.
Skip to the animationSubnetting moves the boundary between the network and host parts of an IPv4 address, trading host addresses for a larger number of smaller, separately routed networks.
The address, and the prefix
An IPv4 address is 32 bits. The dotted-decimal notation exists only because 32 binary digits are unreadable — the dots carry no meaning. The prefix length /n says how many leading bits identify the network; the rest identify a host within it.
| Prefix | Mask | Block size | Addresses | Usable hosts |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 16 | 14 |
| /30 | 255.255.255.252 | 4 | 4 | 2 |
Two addresses are always reserved: all host bits zero is the network address, all host bits one is the broadcast. Hence 2ⁿ − 2 usable hosts, and hence /30 for point-to-point links — exactly two usable addresses.
The vocabulary
- Protocol data unit
- What the thing is called at each layer: segment at transport, packet at network, frame at link. Different names for the same bytes with different amounts of header wrapped round them.
- Encapsulation
- A layer treats everything it receives from above as opaque payload and prepends its own header. It never looks inside, which is precisely what makes layers replaceable.
- Peer layers
- A layer only ever meaningfully talks to the same layer at the other end. TCP at one end reads the header TCP at the other end wrote, and nothing in between touches it.
- Propagation vs transmission delay
- Propagation is how long a bit takes to travel the distance — set by physics. Transmission is how long it takes to push all the bits out — set by bandwidth. Only the second improves when you buy a faster link.
- Round-trip time (RTT)
- Send to reply. Every acknowledgement-based protocol is ultimately paced by this, which is why the interesting question is always how much you can send before one arrives.
Working the questions
- 1Block size = 256 − the last non-zero octet of the mask. For /26 that is 256 − 192 = 64.
- 2Subnet boundaries are multiples of the block size: 0, 64, 128, 192.
- 3Which subnet is an address in? Find the largest multiple of the block size not exceeding it. 100 falls in the 64 block.
- 4Network address = that multiple. Broadcast = the next multiple minus one. So 64 and 127.
- 5Usable range is everything between them: 65 to 126.
Formally the router does the same thing by ANDing the address with the mask, which zeroes the host bits. The block-size shortcut is the same computation done in decimal.
The trade, and why bother
Every borrowed bit doubles the subnets and halves the hosts per subnet, and the usable total shrinks because each new subnet loses its own network and broadcast addresses. One /24 gives 254 hosts; four /26s give 248 between them.
- Broadcast containment — a broadcast reaches every host in its subnet, so one flat network of hundreds of machines wastes bandwidth on traffic nobody wants.
- Security boundaries — a router sits between subnets and can filter what crosses.
- Route aggregation — one routing entry covers a whole prefix instead of every host.
Classful addressing and CIDR
Originally the boundary could only fall at /8, /16 or /24 — classes A, B and C. An organisation needing 300 addresses had to take a class B of 65,534 and waste almost all of it, which is a large part of why IPv4 addresses ran short.
CIDR allows any prefix length, which is what makes /26 meaningful. It also permits supernetting: advertising several adjacent prefixes as one shorter prefix, which is what keeps the global routing table from growing without bound.
The numbers you will be asked for
- Subnets from borrowed bits
2^b
b bits borrowed from the host part.
- Usable hosts
2^h − 2
h host bits, less the network and broadcast addresses.
- Block size
256 − last mask octet
The spacing between consecutive subnet boundaries.
- Host bits from prefix
32 − prefix
For IPv6, 128 − prefix.
Advantages and disadvantages
Advantages
- Confines broadcast traffic to a small group of machines.
- Gives a natural place to enforce security policy, since a router sits between subnets.
- CIDR lets an allocation match the actual requirement instead of a fixed class.
Disadvantages
- Each subnet costs two addresses, so splitting wastes some of the space.
- Fixed-size subnetting wastes more; VLSM fixes that at the cost of complexity.
- Getting the boundary wrong is easy and produces failures that look like anything but an addressing bug.
Watch it work
Check yourself
question 1 / 4
One question at a time. Pick an answer to see why it is right or wrong, then move on — there is no score to keep and nothing is saved.