Sub topic 2
Class Ranges and Default Masks
Assume you understand that an IPv4 address has four decimal octets and that each octet represents eight bits. This chapter uses powers of two and basic binary notation.
Class ranges and default masks
The original classful addressing scheme divided IPv4 addresses by the first octet.
| Class | First octet | Default mask | Typical use |
|---|---|---|---|
| A | 0–127 | 255.0.0.0 (`/8`) | Very large networks |
| B | 128–191 | 255.255.0.0 (`/16`) | Medium networks |
| C | 192–223 | 255.255.255.0 (`/24`) | Small networks |
| D | 224–239 | No host mask | Multicast |
| E | 240–255 | Reserved | Experimental or reserved use |
For example, 172.16.5.4 is class B because its first octet is 172. Its classful default mask is /16.
Subnet masks and prefix length
A subnet mask separates the network part from the host part. A prefix length writes the number of network bits after a slash. Thus, /16 means that the first 16 bits identify the network, and the remaining 16 bits identify hosts.
The mask 255.255.0.0 has sixteen one bits followed by sixteen zero bits:
11111111.11111111.00000000.00000000Modern networks can use a prefix that does not match the old class. For example, 192.168.1.0/26 uses 26 network bits and 6 host bits.
Network address, broadcast address, and usable hosts
For 192.168.1.0/26, the host portion has six bits, so the subnet contains 2^6 = 64 addresses.
- Network address:
192.168.1.0 - Broadcast address:
192.168.1.63 - Usable host addresses:
192.168.1.1through192.168.1.62 - Usable host count:
64 - 2 = 62
The network address identifies the subnet. The broadcast address reaches all hosts on that subnet.
import ipaddress
network = ipaddress.ip_network("192.168.1.0/26")
print(network.network_address)
print(network.broadcast_address)
print(network.num_addresses - 2)CIDR: why classes were replaced
CIDR, or Classless Inter-Domain Routing, replaced fixed class boundaries with flexible prefixes such as /20, /27, and /30. This prevents the waste caused by giving a small organization an entire class A, B, or C network. CIDR also supports route aggregation, where several adjacent networks can be advertised as one larger prefix.
Special-purpose address ranges
Some ranges have defined roles:
0.0.0.0/8: this network or an unspecified address in several contexts.127.0.0.0/8: loopback, used by a host to address itself.169.254.0.0/16: link-local addresses, commonly assigned when configuration fails.224.0.0.0/4: IPv4 multicast.255.255.255.255: limited broadcast on the local network.
These ranges are not ordinary public unicast addresses.
Exercise
What are the network address, broadcast address, and usable host count for 10.2.4.0/28?
Show answer
There are 16 addresses. The network address is 10.2.4.0, the broadcast address is 10.2.4.15, and there are 14 usable hosts from 10.2.4.1 through 10.2.4.14.