Timedora

3 IPv4 Subnet Calculation Practice

Learn to interpret IPv4 prefixes, calculate subnet boundaries and address ranges, divide networks into equal subnets, and verify the results.

IPv4 addresses, masks, and prefixes

An contains 32 bits, usually written as four decimal octets. A marks the leading network bits and the remaining bits for addresses within the network. gives the number of network bits after a slash: for example, /24 has 24 network bits and 8 .

In binary, a valid has a continuous run of 1 bits followed by 0 bits. The is found by applying a bitwise AND to the IP address and the mask.

For an ordinary IPv4 subnet with hh , the total and usable address counts 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 , which is the first address in the block, and the , which is the last. These formulas apply to ordinary subnets; special-purpose prefixes can have different rules.

Find a subnet boundary and address range

For a prefix that does not end on an octet boundary, find the octet where the mask changes from 255 to a smaller value. Calculate the in that octet:

Block size=256−mask value in that octet\text{Block size} = 256 - \text{mask value in that octet}

Subnet network boundaries are multiples of this . Find the multiple at or below the address's value in that octet; this is the network boundary. The next boundary minus one gives the .

Worked example: 192.168.10.77/26

  1. The prefix leaves 32−26=632 - 26 = 6 , so the mask is 255.255.255.192.

  2. In the fourth octet, the is 256−192=64256 - 192 = 64.

  3. The fourth-octet boundaries are 0, 64, 128, and 192. Since 77 is between 64 and 127, the is 192.168.10.64.

  4. The next boundary is 128, so the is 192.168.10.127.

  5. The usable range is 192.168.10.65–192.168.10.126. There are 26−2=622^6 - 2 = 62 .

Check that .77 falls between the network and broadcast addresses. The block contains 64 total addresses.

Divide a network into equal subnets

To create at least SS equal-size subnets, borrow the smallest number of bb such that:

2b≥S2^b \geq S

Add bb to the original prefix length. The resulting subnets are equal in size, and each has fewer than the original network.

Worked example: divide 192.168.20.0/24 into four subnets

  1. Four subnets require b=2b = 2 borrowed bits because 22=42^2 = 4.

  2. The new prefix length is 24+2=2624 + 2 = 26, or /26.

  3. Each subnet has 6 , 64 total addresses, and 62 .

  4. The is 64, so the fourth-octet boundaries are 0, 64, 128, and 192.

The four subnets are:

  • Network 192.168.20.0/26; usable range 192.168.20.1–192.168.20.62; broadcast 192.168.20.63.

  • Network 192.168.20.64/26; usable range 192.168.20.65–192.168.20.126; broadcast 192.168.20.127.

  • Network 192.168.20.128/26; usable range 192.168.20.129–192.168.20.190; broadcast 192.168.20.191.

  • Network 192.168.20.192/26; usable range 192.168.20.193–192.168.20.254; broadcast 192.168.20.255.

The four blocks are consecutive, each contains 64 addresses, and they do not overlap. Together they cover the original /24, which contains 256 addresses.

Worked subnet calculations

Find the range for 10.1.5.200/27

The mask is 255.255.255.224, giving a of 32. The address falls in the fourth-octet block from .192 through .223. The is 10.1.5.192, the is 10.1.5.223, and the usable range is 10.1.5.193–10.1.5.222. With 5 , there are 25−2=302^5 - 2 = 30 .

Find the range for 172.16.8.130/25

The mask is 255.255.255.128, giving a of 128. The address falls in the fourth-octet block from .128 through .255. The is 172.16.8.128, the is 172.16.8.255, and the usable range is 172.16.8.129–172.16.8.254. With 7 , there are 27−2=1262^7 - 2 = 126 .

Divide 10.0.4.0/24 into eight equal subnets

Eight subnets require 3 borrowed bits, so the new prefix is /27. The network addresses are 10.0.4.0, 10.0.4.32, 10.0.4.64, 10.0.4.96, 10.0.4.128, 10.0.4.160, 10.0.4.192, and 10.0.4.224. Each subnet contains 32 total addresses and 30 .

Verify subnet calculations

Before accepting a calculation, check that:

  • The prefix is between /0 and /32, and the mask consists of consecutive 1 bits followed by 0 bits.

  • The given address falls within the calculated network-to-broadcast range.

  • The lies on a valid block boundary.

  • The is the last address before the next boundary.

  • When a network is divided, the number of subnets and their address counts add up to the original block.

In general, use the prefix length to determine the number of network bits and the remaining . Use the mask and to locate subnet boundaries, then identify the , , and usable range. For equal-size subnetting, borrow enough bits to meet the required subnet count, calculate the resulting , and verify that the blocks are aligned, consecutive, and non-overlapping.