The two questions cover finding the subnets in a small network, the four DHCP messages a laptop exchanges to get an address, how many addresses a CIDR block holds and where it starts and ends, and which route wins when a customer takes its block to a new ISP.
The circles are routers R1 and R2. Each thick vertical line is a LAN (a switch, or a shared wire), and the grey boxes are hosts on it. Every label is the IP address of one interface, the point where a device meets a wire, and it sits next to the interface it names. That is why each router carries two labels: an IP address names an interface, not a whole device §4.3.2.
A subnet is a set of interfaces that can reach each other without passing through a router. The book's recipe for finding them is to detach every interface from its host or router and count the islands of wire that are left. With a /24 mask, the first three bytes are the subnet part, so every interface on one island shares them, and the subnet's address is those three bytes followed by 0.
Two routers connect two LANs. Each label is the IP address of one interface, and every subnet uses a /24 mask.
List the address of every subnet in this network, in a.b.c.d/24 form.
A laptop joins R2's LAN. The DHCP server runs in router R2, at 150.10.2.1. Clients use UDP port 68 and servers use port 67. The server offers the laptop 150.10.2.57.
Fill in the rest of the exchange. The discover row is done for you.
| Message | Source IP : port | Destination IP : port | yiaddr ("your address") |
|---|---|---|---|
| discover | 0.0.0.0 : 68 | 255.255.255.255 : 67 | 0.0.0.0 |
| offer | |||
| request | |||
| ACK |
The laptop sends the request from 0.0.0.0, even though it has been offered 150.10.2.57. Why?
The server knows which address it is giving the laptop. Why does it send the offer and ACK to 255.255.255.255 instead of to 150.10.2.57?
1150.10.1.0/24, 150.10.2.0/24, 150.10.21.0/24
There are three subnets. Two are the LANs: R1's interface 150.10.1.1 and its two hosts share one wire, and R2's interface 150.10.2.1 and its two hosts share the other. The third is the link between the routers. R1's 150.10.21.1 and R2's 150.10.21.2 reach each other without passing through a router, so they form a subnet of just two interfaces §4.3.2.
If you answered two subnets, you counted only the LANs. The router-to-router link is easy to miss because no hosts sit on it, but once you detach the interfaces it is an island like the other two.
If you listed 150.10.1.1 or 150.10.21.1, you gave an interface address. A subnet's address keeps the subnet part (here the first three bytes) and sets the host part to 0.
2Every message is a broadcast
| Message | Source IP : port | Destination IP : port | yiaddr |
|---|---|---|---|
| discover | 0.0.0.0 : 68 | 255.255.255.255 : 67 | 0.0.0.0 |
| offer | 150.10.2.1 : 67 | 255.255.255.255 : 68 | 150.10.2.57 |
| request | 0.0.0.0 : 68 | 255.255.255.255 : 67 | 150.10.2.57 |
| ACK | 150.10.2.1 : 67 | 255.255.255.255 : 68 | 150.10.2.57 |
Each vertical line is one machine, with time running downward. Each arrow is one message, drawn from its sender to the machine whose DHCP program receives it. It slopes down because the message takes time to arrive. Above each arrow is the message's number and name, the address it carries in yiaddr, and its source and destination as IP:port. The dashed line on the left marks how long the laptop has no address of its own.
Reading down the picture: the laptop sends both of its messages from 0.0.0.0, and the server addresses both of its replies to the broadcast address. Nothing in the exchange is ever sent to 150.10.2.57.
The destination port names the receiver's role. Messages from the client go to port 67, where servers listen, and messages from the server go to port 68, where clients listen. yiaddr is the address being discussed: 0.0.0.0 in the discover, because the laptop has nothing to ask about yet, and 150.10.2.57 from the offer onward §4.3.2.
If you put 150.10.2.57 as the source of the request, or as the destination of the offer or ACK, see parts 3 and 4: the laptop does not own that address yet.
If you swapped the ports on the server's messages, you may have read the ports as belonging to the message rather than to the program. The server always sends from its own port, 67, to the client's port, 68.
3An offer is not an assignment
The offer only proposes 150.10.2.57. The address becomes the laptop's when the server's ACK arrives. Until then the laptop has no address it may use, so it sends from 0.0.0.0, the address a machine uses when it has none.
4The laptop does not have 150.10.2.57 yet
A machine accepts a datagram sent to a specific IP address only if that address is its own. Before the ACK, the laptop would discard a datagram sent to 150.10.2.57. A datagram to 255.255.255.255 reaches every machine on the LAN, and the laptop's DHCP program, listening on port 68, receives it. The laptop knows the reply is meant for it because every DHCP message carries a transaction ID that matches the request it answers.
The worksheet's LAN had one DHCP server. A LAN can have more than one, and nothing about the four messages changes, but more machines take part. Two rules decide who receives each message. A datagram to 255.255.255.255 reaches every machine on the LAN, but only a program listening on its destination port receives it. And a machine accepts a datagram sent to a specific IP address only if that address is its own.
This is why DHCP uses four messages where TCP's handshake uses three §3.5.6. The first two let the laptop find out which servers exist and what each would give it, and no server has committed to anything yet. The last two let the laptop choose one, and let that server commit. If every server committed an address at the OFFER, a single laptop would hold an address from every server, and an OFFER lost on the way would hold an address that nobody uses until its lease ran out. The two extra messages are cheap: they cross only the local LAN, once per lease.
§4.3.2 IPv4 Addressing · video · knowledge checks · practice problems
Figures after the authors' Chapter 4 slides, copyright © 1996–2025 J.F. Kurose and K.W. Ross.
GW CSCI 4431/6431 Computer Networks · Addressing and DHCP Worksheet
| Prefix length | Third-byte values covered | Addresses |
|---|---|---|
| /16 | 256 (all) | 65,536 |
| /17 | 128 | 32,768 |
| /18 | 64 | 16,384 |
| /19 | 32 | 8,192 |
| /20 | 16 | 4,096 |
| /21 | 8 | 2,048 |
| /22 | 4 | 1,024 |
| /23 | 2 | 512 |
| /24 | 1 | 256 |
Each row is one prefix length /x. The middle column counts how many different values the third byte takes inside the block, and the last column counts every address in the block §4.3.2.
For any prefix /x
Drag the slider to change the prefix length, or type a different address. The explorer shows the first and last address of the block in binary and in dotted decimal, and works out the three rules above for the prefix you chose.
First address
Last address
An IPv4 address is 32 bits, written as four bytes of 8 bits each. Counting from the left, the first byte is bits 1–8, the second is bits 9–16, the third is bits 17–24 and the fourth is bits 25–32. A prefix /x fixes the first x bits. Every bit after them is free: it can be 0 or 1, and each combination of free bits is a different address in the block. Each free bit doubles the number of combinations, so 32 − x free bits give 232−x addresses.
For a prefix /x between /16 and /24, the prefix ends inside the third byte (or, for /24, exactly at its end). Since Table 1 only considers prefix lengths from /16 to /24, the first two bytes are always fixed, and the fourth byte is always entirely free, taking all 28 = 256 values. Of the third byte's 8 bits, the first x − 16 are fixed and the remaining 24 − x are free, so the third byte takes 224−x values. That is why the last column of Table 1 is always the middle column times 256.
A /24 therefore covers exactly one third-byte value: all 8 of the third byte's bits are inside the prefix, so none is free, and only the fourth byte varies. A /20 ends 4 bits into the third byte and leaves 4 free, so the third byte takes 24 = 16 values. Each row up Table 1 shortens the prefix by one bit, which frees one more bit and doubles both counts.
The block starts at the third byte written in the prefix and covers 224−x consecutive values. 10.1.64.0/18 covers 64 values starting at 64: third bytes 64 to 127, so 10.1.64.0 to 10.1.127.255. The table also works backwards. To describe a range of third bytes as one entry, count the values and find that count in the middle column: third bytes 96 to 103 are 8 values, so the entry is 10.1.96.0/21. That only works because 96 is a multiple of 8 (rule 3). No single /21 can start at 100.
Table 1 stops at /16 and /24, but 232−x holds for every prefix. A prefix longer than /24 splits the fourth byte instead (a /25 holds 27 = 128 addresses, half of one third-byte value), and one shorter than /16 splits the second byte.
Fly-By-Night-ISP holds 200.23.16.0/20. It gives Organization 1 the block 200.23.18.0/23.
How many addresses are in Organization 1's block? What are its first and last addresses?
Addresses: First: Last:
Organization 1 now moves to ISPs-R-Us, which holds 199.31.0.0/16. Organization 1 keeps its addresses.
What does each ISP now advertise to the rest of the Internet?
Fly-By-Night-ISP:
ISPs-R-Us:
A core router installs both ISPs' advertisements. To which ISP does it forward a datagram for 200.23.19.5? For 200.23.20.5? Why?
200.23.19.5 → 200.23.20.5 →
1512 addresses: 200.23.18.0 to 200.23.19.255
Table 1's /23 row gives 2 third-byte values and 512 addresses. The block starts at
the third byte in its prefix, 18, so it covers third bytes 18 and 19, every fourth
byte included. In binary, 18 is 0001001|0: the /23 fixes the first 7
bits of the third byte, and the free last bit makes 18 (00010010) or 19
(00010011). Some answers give 510 usable hosts, because the first
address names the subnet and the last is its broadcast address.
If you answered 256 or a last address of 200.23.18.255, you read the block as a /24, one third-byte value. A /23 has one more free bit, so it is twice as large.
If you gave a first address of 200.23.16.0, you started from the ISP's /20 rather than from Organization 1's own prefix. The block starts at the third byte written in its own prefix.
2Fly-By-Night: 200.23.16.0/20 · ISPs-R-Us: 199.31.0.0/16 and 200.23.18.0/23
Fly-By-Night-ISP changes nothing. Its /20 still contains Organization 1's addresses, but it does not need to carve them out. ISPs-R-Us adds a second, more specific advertisement for Organization 1's block alongside its own /16, and longest prefix match does the rest (part 3).
If Fly-By-Night stops advertising its /20, the other seven organizations in that block become unreachable. If it splits the /20 into smaller blocks that leave out 200.23.18.0/23, routing still works, but every router on the Internet now has to hold several entries where one did. Hierarchical addressing exists to avoid that.
If ISPs-R-Us advertises only 199.31.0.0/16, nothing points to Organization 1 through its new ISP, because Organization 1's addresses do not start with 199.31.
3200.23.19.5 → ISPs-R-Us · 200.23.20.5 → Fly-By-Night-ISP
The number line is the third byte of the address, from 15 to 32; all of these addresses start 200.23. Each shaded bar is one advertisement, drawn over the third-byte values it covers, with Table 1 giving the length: the /20 covers 16 values from 16 and the /23 covers 2 from 18. The two dots are the destinations: third bytes 19 and 20.
19 sits under both bars, and 20 sits under only the long one.
200.23.19.5 matches both 200.23.16.0/20 and 200.23.18.0/23. A router that has more than one matching entry uses the longest prefix §4.2.1, so the /23 wins and the datagram goes to ISPs-R-Us. 200.23.20.5 has third byte 20, just past the /23's 18 and 19, so only the /20 matches. This is the longest prefix match from Week 8, written in CIDR's slash notation instead of as bit strings.
If you sent 200.23.19.5 to Fly-By-Night-ISP because the address came from its block, you used ownership instead of the forwarding rule. A router knows nothing about who handed out a block. It compares the destination with its entries and takes the longest match.
§4.3.2 IPv4 Addressing; §4.2.1 Input Port Processing and Destination-Based Forwarding · video · knowledge checks · practice problems
GW CSCI 4431/6431 Computer Networks · Addressing and DHCP Worksheet