§4.3.2IPv4 Addressing: Subnets and CIDR

Network layer Kurose & Ross pp. 333–338 · ~14 min read

  • interface
  • subnet
  • cidr
  • route aggregation

Where you are

  • Application layer
  • Transport layer
  • Network layer you are here
  • Link layer
  • Physical layer

An address belongs to an interface rather than to a device. The leading bits say which subnet it is on, and how many of them count is written after a slash.

Words you will meet

  • Interface — the boundary between a device and one link. An IP (Internet Protocol) address belongs to an interface, not to a host or router.

  • Subnet — an island of interfaces connected with no router in between.

  • CIDR (Classless Interdomain Routing) — writing a.b.c.d/x, where x says how many leading bits are the network prefix.

  • Prefix — those x leading bits. Every interface on the subnet shares them.

  • Subnet mask — the same information as 32 bits: x ones, then zeros.

  • Route aggregation — advertising one prefix that covers many subnets.

  • Classful addressing — the old scheme, where x could only be 8, 16 or 24.

Why this matters

The book makes an unusually strong claim about this section: “To master IP addressing is to master the Internet’s network layer itself!”

It is right, and the reason is that addressing is where several things you have already met turn out to be the same thing. Longest prefix matching from section 4.2.1 exists because of how addresses are handed out. Forwarding tables stay small because of how addresses are grouped. Chapter 5’s BGP (Border Gateway Protocol) advertises prefixes and nothing else.

The difficulty is that addressing is a story about bits, told in decimal. 200.23.16.0/20 and 200.23.31.255 look unrelated until you write them in binary and see that their first twenty bits are identical. So everything on this page shows both.

An address belongs to an interface

Start with the thing that is easy to get wrong.

A host typically has a single link into the network. The boundary between the host and that physical link is called an interface . A router’s job is to receive a datagram on one link and forward it on another. So a router necessarily has two or more links, and a boundary with each one. It therefore has several interfaces, one per link.

Every host and router interface must have its own IP address. So:

An IP address is technically associated with an interface, rather than with the host or router containing that interface.

Each address is 32 bits — 4 bytes — so there are 2³² ≈ 4 billion of them. They are written in dotted-decimal notation, each byte in decimal, separated by dots. The book’s example: 193.32.216.9 is 11000001 00100000 11011000 00001001.

One address, both notations, with the boundary you can move
the address223.1.1.211011111.00000001.00000001.00000010
the mask255.255.255.011111111.11111111.11111111.00000000
subnet223.1.1.0/2411011111.00000001.00000001.00000000
last address223.1.1.25511011111.00000001.00000001.11111111
addresses in the block
256
usable for interfaces
254
host bits
8

The shaded bits are the network prefix — the 24 bits every interface on this subnet shares. The rest identify one interface within it. Two of the 256 are reserved: 223.1.1.0 names the subnet itself and 223.1.1.255 is its broadcast address, which is why the usable count is 256 − 2.

The book’s own Figure 4.18 address. Drag the prefix slider and watch four things change together: the shaded bits, the subnet, the last address and the host count. Then type 200.23.16.0 and set the prefix to 20.

In plain words

Drag the prefix boundary and four things move together:

  • the shaded bits — the part every interface on this subnet shares;
  • the subnet address — those bits, with the rest set to zero;
  • the last address — those bits, with the rest set to one;
  • the host count — 2 raised to the number of unshaded bits, minus two.

That last “minus two” is the book’s own 2⁸ − 2 = 254. Two addresses in every block are reserved: the subnet address itself, and the broadcast address at the top of the range.

What counts as a subnet

The three hosts in the upper-left of the book’s Figure 4.18, and the router interface they connect to, all have addresses of the form 223.1.1.xxx. They share their leftmost 24 bits. The subnet is 223.1.1.0/24, and any additional host attached to it must also have an address of that form.

Those four interfaces are joined by a network containing no routers — an Ethernet, or a wireless access point. That is the defining property, and the book gives a recipe for finding all of them:

The recipe

To determine the subnets, detach each interface from its host or router, creating islands of isolated networks, with interfaces terminating the end points of the isolated networks. Each of these isolated networks is called a subnet.

Apply it to Figure 4.20 and you get six, not three.

Figure 4.20 — three routers, six subnets
R1R2R3223.1.1.1223.1.1.3223.1.2.1223.1.2.2223.1.3.1223.1.3.2

Drag any device to rearrange the picture. Hover a link to see its rate, delay and length.

Detach every interface from its host or router and count the islands. The three at the edges are obvious; the three point-to-point links between routers are the ones people miss.

Read this diagram as text
  • wired link
  • wired link
  • wired link
  • wired link
  • wired link
  • wired link
  • wired link
  • wired link
  • wired link

Three are the obvious ones, each joining a router to a pair of hosts: 223.1.1.0/24, 223.1.2.0/24, 223.1.3.0/24.

The other three are the point-to-point links between the routers: 223.1.9.0/24 joining R1 to R2, 223.1.8.0/24 joining R2 to R3, and 223.1.7.0/24 joining R3 to R1.

Those three are what people miss, and missing them is the point of the exercise. A subnet is not “a network with hosts on it”. It is any island left when you detach the interfaces — and a wire between two routers is an island with exactly two interfaces on it.

CIDR

The Internet’s address assignment strategy is classless interdomain routing CIDR (Classless Interdomain Routing) , pronounced “cider” [RFC 4632].

The 32-bit address is split in two and written a.b.c.d/x. The x most significant bits are the network prefix. An organisation is typically assigned a block of contiguous addresses sharing a common prefix, so every device inside it shares those x bits.

The payoff is stated plainly, and it is the reason the Internet scales:

When a router outside the organisation forwards a datagram whose destination is inside it, only the leading x bits need be considered.

One forwarding-table entry of the form a.b.c.d/x suffices for every destination in the whole organisation. The remaining 32 − x bits distinguish devices within it, and are considered only by routers inside — where they may have a further subnetting structure of their own.

Prefixes nest

Suppose the first 21 bits of a.b.c.d/21 are an organisation’s prefix, common to every device it owns. The remaining 11 bits identify a specific host.

The organisation may then use some of those 11 bits for its own subnetting, so that a.b.c.d/24 names one subnet inside it. Nothing outside notices — the outside world still sees one /21.

This nesting is why the same notation describes both “the block an organisation holds” and “one Ethernet inside a building”. They are the same kind of object at different scales.

Route aggregation

Figures 4.21 and 4.22 — one advertisement for eight organisations, and then a complication
1 — The ISP splits its block eight waysstep 1 of 6
the ISP holds 200.23.16.0/20 — 4,096 addressesOrg 0 — 200.23.16.0/23Org 1 — 200.23.18.0/23Org 2 — 200.23.20.0/23⋮ through Org 7 — 200.23.30.0/23

Each organisation gets a /23: 512 addresses, 510 of them usable. The eight blocks are contiguous and share the ISP’s first 20 bits, which is the entire point of allocating them this way.

Why address blocks are handed out hierarchically, and what happens when one organisation moves without renumbering.

Read all steps as text
  1. 1 — The ISP splits its block eight waysEach organisation gets a /23: 512 addresses, 510 of them usable. The eight blocks are contiguous and share the ISP’s first 20 bits, which is the entire point of allocating them this way.
  2. 2 — The ISP advertises one prefix to the world"Send me anything with addresses beginning 200.23.16.0/20." The rest of the Internet never learns that eight organisations live inside it, and needs exactly one forwarding-table entry for all of them.
  3. 3 — This is route aggregation, and it is why the tables stay smallA single entry of the form a.b.c.d/x forwards packets to any destination inside the organisation. Section 5.4 shows BGP relying on it. Without aggregation, every routing table on the planet would carry eight entries here instead of one — and the Internet has rather more than eight organisations.
  4. 4 — Now Organization 1 changes providerFly-By-Night-ISP acquires ISPs-R-Us, and Organization 1 connects through the subsidiary instead. But its addresses — 200.23.18.0/23 — are inside Fly-By-Night’s block, not inside ISPs-R-Us’s 199.31.0.0/16.
  5. 5 — ISPs-R-Us advertises the more specific prefix"Send me anything beginning 199.31.0.0/16 or 200.23.18.0/23." Both providers now advertise a prefix covering Organization 1’s addresses — but ISPs-R-Us’s is 23 bits and Fly-By-Night’s is 20.
  6. 6 — Longest prefix matching does the restEvery router in the world already applies the rule from §4.2.1: when two entries match, take the longer. Traffic for Organization 1 goes to ISPs-R-Us; everything else in the /20 still goes to Fly-By-Night. Nobody renumbered anything, and no special mechanism was needed — the forwarding rule was already enough.

Longest prefix matching, doing real work

Step 6 is worth pausing on, because it is the first time the rule from section 4.2.1 earns its keep.

Two providers advertise prefixes that both cover Organization 1’s addresses. Fly-By-Night says 200.23.16.0/20; ISPs-R-Us says 200.23.18.0/23. Every router in the world resolves the conflict the same way, with no coordination and no new mechanism: take the longer prefix.

Longest prefix matching, in bits
looking up
11001000.00010111.00010010.00101100
prefixbitsmatches?interface
200.23.16.0/2020yesFly-By-Night-ISP
200.23.18.0/2323yesISPs-R-Us← longest match wins
199.31.0.0/1616noISPs-R-Us
0.0.0.0/00yesdefault route

3 of 4 entries match. The router takes 200.23.18.0/23 because it is the longest — the most specific rule, written with the most knowledge about this particular address. This is the entry that lets Organization 1 keep its addresses after moving to a different provider.

Figure 4.22’s situation. Type 200.23.20.7 to see the same table send an address to the other provider — one entry stops matching, and the answer changes.

Type 200.23.20.7 into the destination box. That address is inside Fly-By-Night’s /20 but outside ISPs-R-Us’s /23, so one entry stops matching and the answer changes — without anything in the table being edited.

This is why longest prefix matching is not an implementation detail. It is what lets an organisation change provider without renumbering a single machine.

What CIDR replaced

Before CIDR, the network portion could only be 8, 16 or 24 bits — class A, B and C. The requirement that it be exactly 1, 2 or 3 bytes turned out to be serious trouble.

Why classful addressing had to go
ClassPrefixFor an organisation with 2,000 hosts

Cells marked ⓘ have an explanation — click to read it. Sortable columns have a ↕ in the heading.

Before CIDR the prefix could only be 8, 16 or 24 bits. An organisation with 2,000 hosts had no size that fitted.

A misprint in the class B figure

The book gives a class B subnet’s capacity as 65,634 hosts in one sentence, and as 65,534 two sentences later.

65,534 is correct: 2¹⁶ = 65,536, minus the two reserved addresses. The first figure is a typo, and the second one is the one the argument uses.

The waste, in numbers

An organisation with 2,000 hosts under classful addressing:

  • a /24 gives 254 — far too few;
  • a /16 gives 65,534 — so that is what they were given.

More than 63,000 addresses were then locked up where no other organisation could use them. Do that a few thousand times and the class B space is gone, which is exactly what happened.

With CIDR the same organisation takes a /21: 2,048 addresses, 2,046 usable. The waste falls from 63,000 to 46.

Set the playground above to a /21 and read the numbers off it.

One more address worth knowing

255.255.255.255 is the IP broadcast address. A datagram sent to it is delivered to all hosts on the same subnet. Routers may optionally forward it into neighbouring subnets, although they usually do not.

Keep it in mind — section 4.3.2-dhcp is about a host that needs an address and does not have one yet, and this is the address it shouts at.

Check yourself

Check yourself

0 of 7 answered
  1. 1.What does an IP address actually belong to?

  2. 2.predictFigure 4.20 has three routers joined by point-to-point links, each also serving two hosts. How many subnets?

    Apply the recipe: detach every interface and count the islands.

  3. 3.predictHow many usable interface addresses does a /26 block contain?

    Count the host bits, then subtract the reserved ones.

  4. 4.predictFly-By-Night advertises 200.23.16.0/20; ISPs-R-Us advertises 200.23.18.0/23. Where does a datagram for 200.23.18.44 go?

  5. 5.Why does route aggregation matter?

  6. 6.predictAn organisation with 2,000 hosts under classful addressing. What did it get, and what did that cost?

  7. 7.The book gives a class B subnet's capacity as 65,634 in one sentence and 65,534 in another. Which is right?

What to remember

  • An IP address belongs to an interface, not a device. A router has one per link.
  • A subnet is an island left when you detach every interface. Figure 4.20 has six, and three of them are wires between routers. a.b.c.d/x means the leading x bits are the network prefix, shared by every interface on the subnet.
  • Longest prefix matching lets an organisation change provider without renumbering. The new provider advertises a longer, more specific prefix, and the existing forwarding rule does the rest.