Sub topic 1
IPv4 Addresses: Structure and Notation
Prerequisites
This chapter assumes you can convert between binary and decimal, and that you know what a router and a host are. You should also be comfortable with powers of two.
IPv4 addresses: structure and notation
An IPv4 address is a 32-bit number. Writers split it into four 8-bit groups, called octets, and write each as a decimal number from 0 to 255. This is dotted-decimal notation. For example, 192.168.1.10 is 11000000.10101000.00000001.00001010 in binary.
Classful addressing and why it was replaced
Early IPv4 fixed the network size by class. Class A used the first 8 bits for the network, Class B used 16, and Class C used 24. Classes wasted addresses. A site with 300 hosts needed a Class B block with 65,534 usable addresses. CIDR replaced classes.
Subnetting and subnet masks
A subnet mask marks which bits name the network. The mask 255.255.255.0 means the first 24 bits are the network part. The network address is the address AND the mask. The broadcast address sets every host bit to 1. A subnet with h host bits has 2^h − 2 usable hosts.
CIDR and prefix notation
CIDR (Classless Inter-Domain Routing) writes the mask as a slash and the count of network bits. 192.168.1.0/24 has 24 network bits and 8 host bits. The prefix length replaces the fixed class.
import ipaddress
net = ipaddress.ip_network("192.168.1.0/26")
print("network:", net.network_address)
print("broadcast:", net.broadcast_address)
print("usable hosts:", net.num_addresses - 2)This prints network 192.168.1.0, broadcast 192.168.1.63, and 62 usable hosts.
Variable-length subnet masks
VLSM (variable-length subnet masking) lets subnets in one network use different prefix lengths. Allocate the largest subnet first. A 100-host subnet needs /25 (126 usable hosts). A 50-host subnet needs /26 (62 usable hosts).
Route aggregation and supernetting
Contiguous prefixes can merge into one block. 192.168.0.0/24 and 192.168.1.0/24 combine into 192.168.0.0/23. Aggregation shrinks routing tables.
Longest-prefix match in a forwarding table
A router forwards a packet using the matching entry with the longest prefix. For destination 10.1.2.3, both 10.0.0.0/8 and 10.1.0.0/16 match. The router uses the /16 entry because it is more specific.
The IPv4 header fields that matter
- Total Length: the full packet size in bytes.
- Identification, Flags, Fragment Offset: used to reassemble fragmented packets.
- TTL: a hop limit that each router decrements.
- Protocol: the upper-layer protocol, such as TCP or UDP.
- Source and Destination Addresses: the 32-bit addresses used for forwarding.
Exercise
For 10.0.0.77/27, what are the network address, broadcast address, and number of usable hosts?
Show answer
A /27 block has 32 addresses. The block containing 77 is 64 to 95. The network address is 10.0.0.64, the broadcast is 10.0.0.95, and there are 30 usable hosts.