Sub topic 4
The original classful scheme
This chapter assumes you can read an IPv4 address as four decimal octets and know that each octet is 8 bits. It also assumes you can convert between binary and decimal. Both were covered in the earlier chapters.
Why classes existed
An IPv4 address has a network part and a host part. Early routers needed a way to find the boundary between them. In the original design (RFC 791, 1981), the boundary was not stored anywhere. It was implied by the first bits of the address.
Addresses were sorted into five classes, A to E. A router looked at the leading bits, picked the class, and knew how many bits named the network.
How the leading bits pick the class
The class is a property of the first few bits of the first octet. Reading them from the left:
| Class | Leading bits | First octet | Network bits | Host bits | Purpose |
|---|---|---|---|---|---|
| A | 0 | 0-127 | 8 | 24 | Very large networks |
| B | 10 | 128-191 | 16 | 16 | Medium networks |
| C | 110 | 192-223 | 24 | 8 | Small networks |
| D | 1110 | 224-239 | none | none | Multicast |
| E | 1111 | 240-255 | none | none | Reserved |
Classes D and E have no network/host split. Class D addresses name groups of receivers, and class E was set aside for future use.
Checking the class in code
Because the leading bits map to fixed decimal ranges, the first octet alone is enough.
def ipv4_class(address):
first = int(address.split(".")[0])
if first < 128:
return "A"
if first < 192:
return "B"
if first < 224:
return "C"
if first < 240:
return "D"
return "E"
print(ipv4_class("10.1.2.3")) # A
print(ipv4_class("172.16.5.4")) # B
print(ipv4_class("192.168.0.1")) # C
print(ipv4_class("224.0.0.5")) # DTake 172.16.5.4. Its first octet is 172, which is 10101100 in binary. The leading bits 10 make it class B. The first 16 bits (172.16) are the network and the last 16 bits (5.4) are the host.
What the split meant for sizes
The fixed split gave only three network sizes:
- Class A: 126 usable networks, each with up to 16,777,214 hosts.
- Class B: 16,384 networks, each with up to 65,534 hosts.
- Class C: 2,097,152 networks, each with up to 254 hosts.
The host counts subtract two addresses, which a later chapter explains. Class A loses two network numbers because 0.0.0.0/8 and 127.0.0.0/8 are special.
Common errors
- Treating the class as a label you can pick. The class comes from the address itself. You cannot make
192.168.1.0a class B network by wanting to. - Forgetting that class is only the default boundary. Modern networks use explicit masks, so the class tells you the historical boundary and may not match the real one. The next chapters cover this.
- Assuming class D and E hosts exist. Neither class is assigned to ordinary hosts.
Why it was replaced
The three sizes fit real needs badly. A company with 300 hosts did not fit in a class C network (254 hosts). It needed a class B network and wasted most of its 65,534 addresses. Multiplied across thousands of organizations, this exhausted the class B space quickly. Routing tables also grew. This pressure led to subnet masks and CIDR, which let the boundary sit at any bit position.
Exercise
A host has the address 130.5.9.200. Which class is it, how many bits identify its network under the classful scheme, and what is its network part?
Show answer
The first octet is 130, which is in 128-191, so it is class B. Class B uses 16 network bits, so the network part is 130.5 and the host part is 9.200.
Exercise
Why can't a company with 300 hosts use a single class C network?
Show answer
A class C network has 8 host bits, which allows at most 254 usable hosts. 300 hosts need more, so the company would have needed a class B network and wasted most of its 65,534 addresses.