Sub topic 2
Classful addressing and why it was replaced
This chapter assumes you can convert between binary and decimal and read dotted-decimal IPv4 notation. You should also know that an address has a network part and a host part. Classful addressing was the original rule for deciding where that split falls. GATE still asks about it directly, and CIDR only makes sense once you see what it replaced.
The idea: the first bits fix the split
In classful addressing, the leading bits of an address say which class it belongs to. The class fixes how many bits identify the network and how many identify the host. No mask travels with the address. Routers infer the split from the address itself.
| Class | Leading bits | First octet | Network bits | Host bits | Usable hosts per network |
|---|---|---|---|---|---|
| A | 0 | 0 to 127 | 8 | 24 | 16,777,214 |
| B | 10 | 128 to 191 | 16 | 16 | 65,534 |
| C | 110 | 192 to 223 | 24 | 8 | 254 |
| D | 1110 | 224 to 239 | none | none | multicast group addresses |
| E | 1111 | 240 to 255 | none | none | reserved for experiments |
The default masks are 255.0.0.0 for class A, 255.255.0.0 for class B and 255.255.255.0 for class C. Classes D and E have no network/host split.
Counting networks and hosts
The usable host count is 2^h − 2, where h is the number of host bits. The two subtracted addresses are the network address (all host bits 0) and the directed broadcast address (all host bits 1).
The number of networks comes from the free network bits. The first bits are fixed by the class, so they do not count.
- Class A has 7 free bits, giving 2^7 = 128 networks. Network 0 is reserved and 127 is loopback, so 126 are usable.
- Class B has 14 free bits, giving 2^14 = 16,384 networks.
- Class C has 21 free bits, giving 2^21 = 2,097,152 networks.
A common error is quoting 2^8 networks for class A. The leading 0 is part of the class, not a free bit.
Checking it in code
import ipaddress
def classify(addr):
first = int(ipaddress.IPv4Address(addr)) >> 24
if first < 128:
return "A", 8
if first < 192:
return "B", 16
if first < 224:
return "C", 24
if first < 240:
return "D", None
return "E", None
for a in ["10.1.2.3", "172.16.0.1", "200.5.5.5", "224.0.0.5", "250.1.1.1"]:
cls, prefix = classify(a)
if prefix is None:
print(a, "class", cls, "has no network/host split")
else:
hosts = 2 ** (32 - prefix) - 2
print(a, "class", cls, "/" + str(prefix), hosts, "usable hosts")The shift >> 24 isolates the first octet. The comparisons mirror the table.
Special addresses inside the classes
- 0.0.0.0 means "this host" or, in a route, the default route.
- 127.0.0.0 to 127.255.255.255 is loopback, so it is not a usable class A network.
- An address with all host bits 1 is a directed broadcast to that network.
- 255.255.255.255 is the limited broadcast, confined to the local link.
Why classful addressing was replaced
The scheme had three structural problems.
- Wasteful block sizes. A class C network holds 254 hosts, and a class B holds 65,534. An organisation with 2,000 hosts was too big for one class C, so it took a class B and left about 63,000 addresses unused. Class B space ran out first, even though most of it sat idle.
- Routing table growth. The alternative to a class B was several class C networks. Each one needed its own routing table entry, because routers could not merge entries without a mask. Backbone tables grew quickly through the early 1990s.
- Rigid structure. Every network had to follow the class boundary. An organisation could not ask for a block of, say, 1,000 addresses.
Subnetting, covered in the next chapter, was a partial fix. It let an organisation split its own class A, B or C network internally. It did nothing for the global shortage or for the routing table size.
The real fix was Classless Inter-Domain Routing (CIDR), introduced in 1993. CIDR drops the class rule and carries an explicit prefix length with each address, so a block can be any power-of-two size and adjacent blocks can be aggregated into one route.
Shortcuts for exam questions
- Identify the class from the first octet. Remember the boundaries 128, 192, 224 and 240.
- Compute the network address by keeping the network octets and zeroing the rest. For 172.16.45.9 (class B), that gives 172.16.0.0.
- Compute the directed broadcast by setting the host bits to 1. For the same address, that gives 172.16.255.255.
- Class A boundaries often catch people out. 127.x.x.x looks like class A but is loopback. 128 is already class B.
Exercise
An address is 195.20.33.77. Name its class, its network address and its directed broadcast address under classful rules. How many usable hosts does that network allow?
Show answer
The first octet 195 lies in 192 to 223, so it is class C with the default mask 255.255.255.0. The network address is 195.20.33.0 and the directed broadcast is 195.20.33.255. Eight host bits give 2^8 − 2 = 254 usable hosts.
Exercise
A company needs 3,000 addresses and receives a class B network under classful allocation. How many addresses go unused, and why did CIDR reduce this kind of waste?
Show answer
A class B network has 2^16 − 2 = 65,534 usable addresses. Using 3,000 leaves 65,534 − 3,000 = 62,534 unused. CIDR lets the company receive a block sized to its need. 3,000 hosts fit in a /20, which has 4,096 addresses, instead of a /16.