Defining Valid IP Address Ranges for Subnets

Once you’ve managed to define a custom subnet mask that meets your requirements, the next step is calculating the ranges of IP addresses that are valid for a given subnet. Remember that after a custom subnet mask is defined, you have actually turned one big network address space into a number of smaller sub-network address spaces. Because of this, certain addresses will no longer be considered local to one another.

Calculating ranges of addresses isn’t difficult, but we’ll again need to go back to binary to understand how this is accomplished.

Consider the example of network 192.168.0.0 with a custom subnet mask of 255.255.248.0. Remember that this is one of the private address ranges outlined in RFC 1918, and the default mask is 255.255.0.0 in this case. To begin, we’ll need to convert the subnet mask to binary, and define the network, subnet, and host portions, as shown in the figure below.

Figure: Network, subnet and host portions based on the custom subnet mask 255.255.248.0.

Notice that the first 16 bits represent the network, the next 5 define subnets, and the last 11 are used to uniquely identify hosts on a subnet.

Since 5 bits are used to define the subnet portion of the address, this gives us 25-2 or 30 possible subnets. Each subnet can support 211-2, or 1022 unique hosts. Calculating the range of available addresses for each subnet involves beginning with the first subnet that is not all binary 0s, and then looking at the additional subnets. In this case, the first subnet is defined as the one where all but the last bit is set to binary 0. The first host on the 00001 subnet will be the lowest host value that is not all 0s, since the all 0s address identifies the subnet. The highest address in a range will be the highest host value that is not all 1s, since that value is reserved for broadcasts. I know this can be a little confusing, so take a look at the example in the figure below.

Figure: Defining the IP address range for the first subnet.

If you take the addresses in the figure above and convert them back to decimal, you’ll see that the range of IP addresses available on the first subnet are those from 192.168.8.1 up to 192.168.15.254.

Calculating the next range of addresses requires that we change the subnet ID to its next lowest value. In this case, it would be 00010. To make things easier, consider this to be an isolated 5-bit binary number. The first subnet is 1; the next is 2, then 3, then 4, and so forth. In this way, the first five subnet IDs in our example would be those listed in the table below.

Subnet ID Decimal Value 00001 1 00010 2 00011 3 00100 4 00101 5

Notice that each subnet simply increases by a value of 1 when we consider it as an isolated 5-bit number. This would continue all the way up to 11110, at which point we run out of subnets. Remember that according to Cisco, the subnet IDs of all binary 0s and all binary 1s should be avoided.

Our example continues by calculating the ranges for the second and third subnets. Notice in the figure below that the subnet ID has changed for each, but that we still always include the lowest and highest possible host values – the beginning and end of each range.

Figure: Defining the IP address ranges for the second and third subnets.

The table below outlines the first three address ranges, along with the subnet ID (when the host bits are all set to binary 0) and the broadcast address for that subnet (where the host ID is set to all binary 1).

Subnet ID Address Range Broadcast Address 192.168.8.0 192.168.8.1 – 192.168.15.254 192.168.15.255 192.168.16.0 192.168.16.1 – 192.168.23.254 192.168.23.255 192.168.24.0 192.168.24.1 – 192.168.31.254 192.168.31.255

If you look closely, you should notice a pattern developing – each new subnet (in this example) starts at a multiple of 8 in the third octet, and each ends just before the next multiple of 8. In this case, the fourth subnet would begin at the next multiple of 8, 192.168.32.1 and go up to just before the next multiple of 8 in the third octet. Since the next multiple of 8 is 40 (and represents the beginning of the next subnet), it must end at 39, or 192.168.39.254.

The pattern with multiples of 8 only occurs with a 248 custom mask value. With different masks, different multiples will become clear.

Let’s try another example. We’ll use the address 10.0.0.0 with a subnet mask of 255.255.0.0. With this example, there are 8 bits used for subnetting, leaving 16 bits for hosts. The figure below outlines the first three ranges of addresses in this example, beginning with the first subnet – 00000001 in the second octet.

Figure: First three address ranges for the address 10.0.0.0 using the custom mask 255.255.0.0.

In this case, the ranges move in multiples of 1 in the second octet – the first subnet is 1, the second is 2, the third is 3, and so forth. It would be safe to say that the fourth subnet will be the range between 10.4.0.1 – 10.4.255.254. Once you’ve found the multiple, determining the ranges is much easier. The first three subnet IDs, address ranges, and the broadcast address on each subnet are shown in the table below.

Subnet ID Address Range Broadcast Address 10.1.0.0 10.1.0.1 – 10.1.255.254 10.1.255.255 10.2.0.0 10.2.0.1 – 10.2.255.254 10.2.255.255 10.3.0.0 10.3.0.1 – 10.3.255.254 10.3.255.255

Some people find Class C address ranges a little trickier to deal with, but if you follow the rules, they are no more difficult that any other range. For example, let’s say that we have the network address 202.191.15.0 with a subnet mask of 255.255.255.240. We know that subnetting occurs in the fourth octet in this example, and that we have 4 subnet bits and 4 host bits. The first subnet will again be lowest non-zero value, or 0001. The first host in each range will be the first non-zero value, and the last host the highest value that is not all binary 1s. The figure below outlines the first 3 ranges in this case.

Figure: First three address ranges for the address 202.191.15.0 using the custom mask 255.255.255.240.

Notice that the values in the ranges look a little different when converted to decimal, as illustrated in the figure above. This is because the subnet IDs end in non-zero values.

Subnet ID Address Range Broadcast Address 202.191.15.16 202.191.15.17 – 202.191.15.30 202.191.15.31 202.191.15.32 202.191.15.33 – 202.191.15.46 202.191.15.47 202.191.15.48 202.191.15.49 – 202.191.15.62 202.191.15.63

If you’re confused by this example, it’s probably because of the oddities that seem to occur in the ranges. For example, why is 202.191.15.16 not a valid IP address when a subnet mask of 255.255.255.240 is used? Look again at what happens when you convert this address to binary – the host portion is all binary 0s, which we already know is not allowed! The key to understanding address ranges is always the same – when in doubt, break everything down into binary. Looking at addresses in decimal only will often make things much more confusing than they need to be.

Author: Dan DiNicolo

Dan DiNicolo is a freelance author, consultant, trainer, and the managing editor of 2000Trainers.com. He is the author of the CCNA Study Guide found on this site, as well as many books including the PC Magazine titles Windows XP Security Solutions and Windows Vista Security Solutions. Click here to contact Dan.