A subnet can be thought of as a range or block of IP addresses that have a common network ID. For example, the CIDR represents the following block of 14 IP addresses:

Given an IP address in CIDR notation, it’s useful to be able to determine the range of actual IP addresses that the CIDR represents. This matter is straightforward when the octet within which the network ID mask ends happens to be 0, as in the preceding example. You just determine how many host IDs are allowed based on the size of the network ID and count them off.

However, what if the octet where the network ID mask ends is not 0? For example, what are the valid IP addresses for when the subnet mask is In that case, the calculation is a little harder. The first step is to determine the actual network ID.

You can do that by converting both the IP address and the subnet mask to binary and then extracting the network ID as in this example:

                192  .   168  .     1  .   100
IP address:  11000000 10101000 00000001 01100100
Subnet mask: 11111111 11111111 11111111 11110000
Network ID:  11000000 10101000 00000001 01100000
                192  .   168  .     1  .   96

As a result, the network ID is

Next, determine the number of allowable hosts in the subnet based on the network prefix. You can calculate this by subtracting the last octet of the subnet mask from 254. In this case, the number of allowable hosts is 14.

To determine the first IP address in the block, add 1 to the network ID. Thus, the first IP address in my example is To determine the last IP address in the block, add the number of hosts to the network ID. In my example, the last IP address is As a result, the with subnet mask designates the following block of IP addresses:

About This Article

This article can be found in the category: