The idea
Classful addressing offered exactly three sizes of network: about 16 million addresses, about 65 thousand, or 256. Nothing in between.
The lecture gives the two failure cases plainly. A network with four hosts gets a whole Class C — 256 addresses, 252 wasted. A network with 257 hosts does not fit in a Class C, so it gets a Class B — 65,536 addresses for 257 machines.
Multiply that across every organisation on the Internet and the address space runs out, not because the addresses were used but because they were allocated and sat idle.
The fix is unglamorous: stop letting the first few bits of the address dictate where the network part ends, and carry the boundary explicitly instead. That is all a subnet mask is — a statement of where the split falls. Once the boundary is free to sit anywhere, allocations can be any power of two, and a four-host site can be given eight addresses instead of 256.
The one operation
How it works
Network address = IP AND mask
A mask is 32 bits: 1 for every network bit, 0 for every host bit. AND the
address with it and every host bit collapses to zero, leaving the network
address.
IP address 11001101.00100000.00100101.00100100 205.16.37.36
Mask 11111111.11111111.11111111.11111000 255.255.255.248
-----
AND result 11001101.00100000.00100101.00100000 205.16.37.32That is the whole mechanism. A router does exactly this on every packet: AND the destination against each route’s mask and see which network address it matches.
The /n notation just counts the leading ones. /29 means 29 one-bits, so
255.255.255.248. There are only ever nine possible final octets, and knowing
them cold turns most subnetting questions into arithmetic you can do in your
head:
| Prefix | Last octet of mask | Host bits | Block size | Usable |
|---|---|---|---|---|
/24 | 0 | 8 | 256 | 254 |
/25 | 128 | 7 | 128 | 126 |
/26 | 192 | 6 | 64 | 62 |
/27 | 224 | 5 | 32 | 30 |
/28 | 240 | 4 | 16 | 14 |
/29 | 248 | 3 | 8 | 6 |
/30 | 252 | 2 | 4 | 2 |
/31 | 254 | 1 | 2 | 2 — see below |
/32 | 255 | 0 | 1 | 1 — see below |
Working an example
Worked example
205.16.37.36/29 — the lecture's own example
A block is granted to a small organisation. One of its addresses is
205.16.37.36/29. Find the first address, the last address, and the total.
Prefix
/29means 3 host bits.32 − 29 = 3, so the block holds2^3 = 8addresses and the mask is255.255.255.248.Find the network address. Blocks of 8 start at multiples of 8:
.32,.40,.48. The address.36sits in the block starting at.32.Formally,
36 AND 248:36 00100100 248 11111000 AND 00100000 = 32Network address
205.16.37.32. This one is not assignable to a host.First host is the next address up:
205.16.37.33.Broadcast is the last in the block:
.32 + 8 − 1 = .39, so205.16.37.39. Also not assignable.Last host is the one below broadcast:
205.16.37.38.Usable count:
2^3 − 2 = 6, which matches.33through.38.
AnswerNetwork .32, hosts .33 to .38, broadcast .39, 6 usable
Worked example
192.168.10.64/28
/28leaves 4 host bits, so the block is2^4 = 16addresses, mask255.255.255.240.64is already a multiple of 16, so it is the network address:192.168.10.64.- First host
192.168.10.65. - Broadcast is
64 + 16 − 1 = 79, so192.168.10.79. - Last host
192.168.10.78. - Usable:
2^4 − 2 = 14.
AnswerNetwork .64, hosts .65 to .78, broadcast .79, 14 usable
Aside
Both of the above are worked in the lecture, and the site’s subnet library is
asserted against all three of its examples in lecture-examples.test.ts. If a
future change ever made the calculator disagree with the unit, that test fails
rather than the site quietly teaching a different answer.
Try it
Type a prefix and watch the bar split. The useful habit to build: before you
read the answer, predict the block size from the prefix. /26 means 6 host
bits, so 64 addresses, so blocks start at .0, .64, .128, .192. Once
that is automatic, most exam questions are done in your head.
Where marks get lost
Where 2^x minus 2 stops working
The rule subtracts the network address and the broadcast address. At the two shortest blocks there is nothing left to subtract from.
/31 — two addresses. Blindly applying the formula gives 2^1 − 2 = 0,
which would make the prefix pointless. RFC 3021 makes it an exception: on a
point-to-point link there is exactly one device at the other end, so a broadcast
address serves no purpose. Both addresses are usable. These are used heavily
on router-to-router links, where a /30 wastes half its four addresses.
/32 — one address. A single host route. One address, nothing subtracted.
A question that hands you a /31 is testing whether you applied the formula or
understood it.
Subnetting versus classless addressing
The lecture treats these as two related ideas and it is worth keeping them apart.
Subnetting is treating subdivisions of a single Class A, B or C network as
networks in their own right. The address now has three parts rather than
two: network, subnet, host. You borrow bits from the host portion, and b
borrowed bits give 2^b subnets.
Classless addressing goes further and drops the class concept altogether.
There is no class; a prefix length n simply states how many bits are network.
The lecture’s example: /28 means the first 28 bits are network and the
remaining 4 give the range, so 128.11.3.16 through 128.11.3.31 form one
block.
One practical note from the lecture worth remembering — the router has to know you are using classless addressing. A router assuming classful rules would infer the boundary from the first octet and get it wrong.
Check yourself
Three to do without the widget:
- What is the network address of
172.16.35.200/27? - How many usable hosts in a
/22? - A point-to-point link between two routers. Which prefix wastes least, and how many usable addresses does it give?
Answers: /27 gives blocks of 32, and 200 falls in the block starting at 192,
so 172.16.35.192. A /22 has 10 host bits: 2^10 − 2 = 1022. And a /31
gives exactly the 2 usable addresses you need, versus a /30 which gives 2 out
of 4.
In the exam
- Given an address and a prefix, produce all five values — network, broadcast, first host, last host, usable count. This is the standard question and it appears in some form every year.
- Show the AND. If the question says “show your working”, write the binary. The mask table above lets you shortcut, but the binary is what earns method marks.
2^x − 2, withxas the host-bit count. State the two subtractions explicitly — network and broadcast.- The
/31exception. Worth knowing precisely; it is the difference between understanding the rule and reciting it. - Why classless exists. The four-host and 257-host examples from the lecture are the shortest way to answer it.
- Know the mask table cold.
/24through/30in particular. It converts a five-minute question into a one-minute one, and exam time is the scarce resource.