6 IPv4 Addressing and Subnetting
Learn how IPv4 addresses, subnet masks, and CIDR prefixes define subnets, and how to calculate network, broadcast, and usable host addresses.
IPv4 addresses and prefixes
An is a 32-bit value, usually written as four decimal octets separated by periods. Each octet ranges from 0 to 255, as in 192.168.10.77.
A separates the network prefix from the host portion of the address. In binary, the network bits are consecutive 1s, followed by 0s for the . expresses the prefix length as a slash followed by the number of network bits. For example, /26 has 26 network bits and 6 .
Common prefix-to-mask examples are:
/24corresponds to255.255.255.0./26corresponds to255.255.255.192./27corresponds to255.255.255.224.
CIDR allows networks to use prefix lengths suited to their needs rather than relying on the old fixed address classes.
Network, broadcast, and host addresses
In an ordinary IPv4 subnet, the has every host bit set to 0, and the has every host bit set to 1. Addresses between these endpoints are normally usable for hosts.
If the number of is , the total number of addresses and the usual number of are:
The subtraction excludes the network and broadcast addresses. There are exceptions: on point-to-point links, both addresses in a /31 can be used as endpoint addresses, while a /32 represents one individual address.
Find a subnet from an address
For 192.168.10.77/26, the prefix leaves 6 . This gives 64 addresses per subnet and normally 62 . The mask is 255.255.255.192; the last-octet is .
The subnet ranges in the last octet therefore begin at 0, 64, 128, and 192. Since 77 falls in the 64–127 block, the address information is:
Network:
192.168.10.64First usable host:
192.168.10.65Last usable host:
192.168.10.126Broadcast:
192.168.10.127
Check that the given host address falls between the network and broadcast addresses.
Subnetting a network
To divide 192.168.10.0/24 into /27 subnets, the new prefix borrows 3 bits from the original /24. The number of resulting subnets is . Each subnet has 5 , so it has under the ordinary-subnet rule.
The /27 is 32. The subnet containing 192.168.10.142 runs from .128 through .159, giving:
Network:
192.168.10.128Usable host range:
192.168.10.129–192.168.10.158Broadcast:
192.168.10.159
In general, read the CIDR prefix to determine the mask and number of . Use the host-bit count to find the subnet size, then identify the with all zero, the broadcast address with all one, and the usable range between them. Remember the /31 point-to-point and /32 exceptions.