# Step 4: Subnetting backwards

Before you begin with step 4, you must understand the layout of the IP address, it's possible Classes, the ANDing method and subnet masking. All these subjects are described in the previous steps.

Now you know how to subnet a network. But what if someone should ask you to do a reverse calculation of the subnet mask. Given an IP address and subnet mask, can you find out where the subnet begins, where it ends, and what the network, subnet and hosts part is? This is what we will try to explain in step 4.

Lets start with an IP address and subnet mask. Will take the following:

IP address : 192.168.90.36

Subnet masks : 255.255.255.224

Looking at this address (192.x.x.x) and mask (255.255.255.x) we know that it is a Class C address. It is using subnetting, because the last octet of the subnet mask is used by the value 224 for subnetting purposes.

If we use the ANDing method to determine the network part of the IP address we should find out that it is 192.168.90.36, as shown in the following calculation:

IP address : 11000000 . 10101000 . 01011010 . 00100100

subnet mask : 11111111 . 11111111 . 11111111 . 11100000

Network part : 11000000 . 10101000 . 01011010 . 00100000

Looking at the last octet of the subnet mask (11100000), the octet responsible for subnetting, it steals three bits from the hosts part. By using a method called 2^{N}-2, where ^{N} is the number of bits used to subnet, we can determine how many subnets that would give us.

2^{N}-2 = 2^{3}-2 = 8-2 = 6 (subnets)

The result of 2^{3} (or 2 'raised to the power of' ^{N}) is 8, but why do we subtract 2? because the hosts part can not be all one's or all zero's, so these two possibilities are subtracted from the outcome. This leaves us with the number 6, which is the total of the available number of subnets.

Now we have the network part (192.x.x.x) the number of subnets (6), but how many hosts does each subnet support using this subnet mask? We use the same method as we did determining the number of subnets. We have 5 bits for the hosts part, which we will apply to the 2^{N}-2 method:

2^{N}-2 = 2^{5}-2 = 32-2 = 30 (hosts)

The result is 30 hosts. Now we are complete. We know that the IP address is a Class C address, thus using a subnet mask with subnet bits in the fourth or last octet. We know that by stealing three bits from the hosts part, it creates 6 subnets per network. And we know that by leaving five hosts bits, this gives us 30 hosts per subnet.

Please remember, that for every network, subnet and host part, all zeros and all ones is not allowed. These addresses are reserved for Local Network (all zeros) or broadcast (all ones).