Timedora

6 IPv4 Subnetting Practice

Learn how IPv4 prefixes and subnet masks define networks, calculate subnet boundaries and host ranges, and choose subnet sizes for addressing needs.

IPv4 subnetting and prefixes

Subnetting divides an block into smaller networks. It helps organize devices, limit broadcast traffic to each subnet, and allocate address space to fit network needs.

An is 32 bits long. states how many leading bits identify the network, and the remaining bits identify addresses within it. CIDR uses explicit prefix lengths rather than relying on address classes.

Subnet masks and address counts

A has 32 bits: network bits are 1 and host bits are 0. The is the number of leading 1 bits. Dotted-decimal masks show those bits in four octets.

Common prefix sizes have these address counts and ordinary usable host counts:

  • /24: mask 255.255.255.0; 256 total addresses and 254 usable hosts.

  • /25: mask 255.255.255.128; 128 total addresses and 126 usable hosts.

  • /26: mask 255.255.255.192; 64 total addresses and 62 usable hosts.

  • /27: mask 255.255.255.224; 32 total addresses and 30 usable hosts.

  • /28: mask 255.255.255.240; 16 total addresses and 14 usable hosts.

  • /29: mask 255.255.255.248; 8 total addresses and 6 usable hosts.

  • /30: mask 255.255.255.252; 4 total addresses and 2 usable hosts.

For ordinary IPv4 subnets, usable host addresses exclude the and . /31 is a special case commonly used on point-to-point links, where both addresses can be assigned to the two endpoints. /32 represents one address.

A prefix can fall within any octet. For example, /20 has mask 255.255.240.0: eight network bits in each of the first two octets and four more in the third, for 20 network bits total.

A method for calculating subnets

For a prefix /p, the host-bit count is 32−p32-p. The total address count is 232−p2^{32-p}. For ordinary subnets, the usable host count is usually the total address count minus 22.

To calculate a subnet:

  1. Find the host bits: 32−p32-p.

  2. Find the total addresses: 2host bits2^{\text{host bits}}.

  3. Find the usable hosts: usually the total addresses minus 22.

  4. Find the by keeping the network bits and setting all host bits to 0. Equivalently, bitwise-AND the IP address with its .

  5. Find the by keeping the network bits and setting all host bits to 1.

  6. Find the : one address after the through one before the .

When the mask changes within an octet, calculate the as 256−mask value256-\text{mask value} in that octet. Subnet network numbers advance by that .

Worked subnet calculation

For 192.168.10.77/26, the mask is 255.255.255.192. The last-octet is 256−192=64256-192=64, so subnet boundaries are .0, .64, .128, and .192. The address .77 falls between .64 and .127, so it belongs to that subnet.

  • : 192.168.10.64

  • : 192.168.10.127

  • : 192.168.10.65–192.168.10.126

  • Total addresses: 26=642^6=64

  • Usable hosts: 64−2=6264-2=62

The IP address identifies a device within the block; the prefix determines which block it belongs to.

Planning subnet sizes

Choose a prefix that provides enough host addresses for the devices on a subnet, allowing room for growth. For example, 25 devices need at least 27 addresses under the ordinary network-and-broadcast rule. A /27 provides 32 total addresses and 30 usable host addresses, so it fits.

A /24 can be divided into eight /27 subnets because /27 has three more network bits than /24. The number of equal subnets is 23=82^3=8. For 10.20.30.0/24, the subnet network addresses are:

  • 10.20.30.0/27

  • 10.20.30.32/27

  • 10.20.30.64/27

  • 10.20.30.96/27

  • 10.20.30.128/27

  • 10.20.30.160/27

  • 10.20.30.192/27

  • 10.20.30.224/27

often used for internal addressing are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.

Practice and answers

For each exercise, find the , , , and usable host count. Assume ordinary subnets unless noted.

  1. 192.168.5.130/25

  2. 172.16.4.200/22

  3. Divide 192.168.8.0/24 into equal subnets that each support at least 50 usable hosts. Find the number of subnets and the first subnet’s range.

Answers

  1. /25 has 128 addresses, and boundaries in the last octet advance by 128. The is 192.168.5.128; the is 192.168.5.255; the is 192.168.5.129–192.168.5.254; and there are 126 usable hosts.

  2. /22 has mask 255.255.252.0, so the third-octet is 256−252=4256-252=4. The third-octet boundary containing 4 is 4. The is 172.16.4.0; the is 172.16.7.255; the is 172.16.4.1–172.16.7.254; and there are 1,022 usable hosts.

  3. A /26 provides 62 usable hosts, so use /26. A /24 yields four /26 subnets. The first is 192.168.8.0/26: 192.168.8.0, 192.168.8.63, and 192.168.8.1–192.168.8.62.