Timedora

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:

  • /24 corresponds to 255.255.255.0.

  • /26 corresponds to 255.255.255.192.

  • /27 corresponds to 255.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 hh, the total number of addresses and the usual number of are:

Total addresses=2h\text{Total addresses} = 2^h
Usable host addresses=2h−2\text{Usable host addresses} = 2^h - 2

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 256−192=64256 - 192 = 64.

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.64

  • First usable host: 192.168.10.65

  • Last usable host: 192.168.10.126

  • Broadcast: 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 23=82^3 = 8. Each subnet has 5 , so it has 25−2=302^5 - 2 = 30 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.128

  • Usable host range: 192.168.10.129–192.168.10.158

  • Broadcast: 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.