Subnet Addressing Torn Apart By Ankit Fadia ankit@bol.net.in

  Note: Please note that this manual is a sequel to the IP Addresses Torn Apart manual. I suggest that you read that one before proceeding further.   Till now we have learnt that the IP Address of all hosts connected to the Internet are divided into two parts-:  

The Network ID (netid)

  1. The Host ID (hostid)

The number of octets or bits allocated to the netid and the hostid parts depends on the class or the range to which the IP Address belongs. For Example,   If an IP Address belongs to Class A, then the first 8 bits are allocated to the netid part, while the remaining 24 bits are allocated to the hostid part.   However, with the introduction of Subnet Addressing, a new division is introduced which divides an IP Address into 3 parts-:  

The Network ID (netid)

  1. The Host ID (hostid)
  2. The Subnet ID (subnetid)

The introduction of Subnet Addressing not only hides the organizational structure of the internal network, but also prevents the wastage of IP Addresses. Typically, an IP Address belonging to Class B will be divided in the following manner:                                                   First 16 bits -----Network ID                                                 Last 16 bits -----Host ID   Such a division requires 216  -2 hosts to be attached to that particular network. However, such a large number of hosts are seldom attached to the same network. Thus the practice of not using Subnet addressing leads to the wastage of IP Addresses.   ******************** HACKING TRUTH: Please note that we subtract the 2 because a system with a Host ID of 0 or 255 is invalid i.e. a host ID value of 0 or 255 cannot be allocated to a system, as both are reserved for special usage. For Example, a host ID value of 0 is usually used for routers. ********************  

But, after subnetting it the IP Address would typically look as follows:

                                                First 16 bits -------Network ID                                                 Next 8 bits----------Subnet ID                                                 Next 8 bits----------Host ID   This allows for the usage of 254 hosts per subnet of the 254 subnets possible.   NOTE: I have used 8 bits for the Subnet ID in this example. However, we can easily allocate as many bits as we want to, to the Subnet ID part.  

Netmask Values

  A netmask value is a 32-bit value containing one bits (255’s) for the network ID and zero bits (0’s) for the host ID. Using the netmask value one can easily determine as to how many bits are reserved for the net ID and how many bits for the host ID. In other words, thus, we can also say that by studying the netmask value of an IP Address we can determine the Class to which an IP Address belongs.   One can find out the netmask value of an IP Address by giving the following command:   C:\WINDOWS>route PRINT   Active Routes:     Network Address               Netmask                  Gateway Address        Interface        Metric         127.0.0.0                         255.0.0.0                  127.0.0.1                         127.0.0.1           1   203.94.53.12                        255.255.0.0               203.94.0.0                       0.0.0.0               1   202.21.87.43                        255.255.255.0           202.21.87.0                     0.0.0.0               1   Let us examine the output line by line. The first line says:     Network Address               Netmask                  Gateway Address        Interface        Metric         127.0.0.0                         255.0.0.0                  127.0.0.1                         127.0.0.1           1   In this case the netmask has a value of 255.0.0.0, which means that the first octet contains all one bits (255’s), while the last three octets contain all zero bits (0’s). In other words, it signifies that the first octet is the network ID (as it contains only one bits) while the last three octets are reserved for the host ID (as it contains only zero bits). Hence, the IP Address 127.0.0.1 is a Class A Internet Protocol Address with 127 being the netid and .0.0.0 being the host ID.   Coming to the second line, we have a netmask value of 255.555.0.0, which means that the first two octets are the network ID parts (i.e. 203.94) while the last two octets are the host ID parts (i.e. 53.12). It also tells us that the IP Address belong to Class B of addresses.  Similarly, in the last case the netmask value of 255.255.255.0 means that the address 202.21.87.43 belongs to Class C of addresses with the network ID being 202.21.87 and the host ID being 43.   ****************** HACKING TRUTH:  If your prime aim is to find the Class of addresses to which an IP belongs, you need not follow the above process. By simply knowing an IP Address and comparing it with the Class-Range Chart below, we can easily determine the Class to which it belongs:   Class                                      Range                                 A                             0.0.0.0 to 127.255.255.255                                 B                             128.0.0.0 to 191.255.255.255                                 C                             192.0.0.0 to 223.255.255.255                                 D                             224.0.0.0 to 239.255.255.255                                 E                              240.0.0.0 to 247.255.255.255   *****************   To recapitulate we can say that the prime usage of netmask is to determine the Class of addresses to which an IP Address belongs.  

Subnet Mask Explained

 

Just like Netmask, Subnet Mask too is a 32-bit value containing one bits (255’s) for network ID and subnet ID while zero bits (0’s) for the host ID. Subnet Mask when together used with Netmask can be used to determine exactly how many bits are allocated for the Network ID, Host ID and Subnet ID.

Let us take an example to make this clearer. Assume the following data for this exercise:

IP Address: 202.12.34.77

Netmask: 255.255.0.0

Subnet Mask: 255.255.255.0

According to the netmask value, the first two octets are reserved for usage by the network ID, while the last two octets are reserved for host ID. Thus, we can now break down 202.12.34.77 into:

Net ID: 202.12

Host ID: 34.77

This particular IP Address has a subnet mask of 255.255.255.0, which means that the first three octets are to be used for Net ID and the Subnet ID, while the last octet by the Host ID. Using this information, we can break down 202.12.34.77 into:

Net ID and Subnet ID: 202.12.34

Host ID: 77

However, earlier we determined that the net ID is 202.12, thus combining all the above information we can finally divide 202.12.34.77 into:

Net ID: 202.12

Subnet ID: 34

Host ID: 77

To recapitulate, we can say that Netmask gives us the boundary between Host ID and Network ID, while Subnet Mask gives us the boundary between Network ID and Subnet ID.

Whenever you connect to your ISP, you are allocated a static IP Address (almost always), which changes each time you reconnect. In order to determine your IP Address, Class of Addressing, host ID, network ID and Subnet ID, simply follow the below process:

NOTE: I carried out this example on my system.

Firstly, in order to find the IP Address of my system, I first connect to my ISP and  use the Netstat command:

C:\WINDOWS>netstat -n   Active Connections     Proto   Local Address          Foreign Address        State   TCP    203.94.253.183:1025    64.4.13.56:1863        ESTABLISHED   TCP    203.94.253.183:1031    209.143.242.119:80     ESTABLISHED   This gives me my Dynamic IP Address, which is, 203.94.253.183. Using the Class-Range chart I deduce that my IP Address is using Class B addressing, which would mean that my netmask is probably 255.255.0.0.   All that I need to know now, in my quest to break apart my IP Address, is my Subnet mask. In order to find the Subnet Mask of a Windows system, one need to follow the below process:  

Click on Start > Run

  1. Type winipcfg in the space provided.
  2. The IP Configuration Dialog Box pops up. This useful utility reveals your IP Address, Subnet Mask along with other useful information.
  When I tried this out on my system, it gave me a Subnet Mask of 255.255.255.0. Combining this value with a Netmask value of 255.255.0.0, we come to the following information:   IP Address: 203.94.253.183 Class of Addressing: Class B Network ID: 203.94 Subnet ID: 253 Host ID: 183  

 

With this we come to the end of this manual. Hope you liked it and till next time, goodbye. ;-)  

Ankit Fadia

Ankit@bol.net.in  

http://hackingtruths.box.sk mailto:ankit@bol.net.in