Tuesday, January 21, 2014

Discontinuous subnet masks

The subnet mask for a particular network is Which of the following pairs of IP addressed could belong to this network? (GATE 2003)

A: &
B: &
C: &
D: &

Now here a lot of people get suspicious about the validity of this given subnet mask (31 = 00011111 ).
As according to the definition of subnet mask (from many renowned books, personally read 3 of them), this is a 32-bit number(for ipv4) where all the bits of the network part are represented as “1”and all the bits of the host part are represented as “0”. That means all 0’s should be following 1’s in a subnet mask.

Then that means this given subnet mask is wrong?
The answer is No. This subnet mask is completely fine. This is an example of a discontinuous subnet mask, which is no longer supported on most routers. Discontinuous subnet masks are still supported on some network access control devices for features like ACLs. (Sometimes, notably on Cisco routers, the subnet masks are written inverted, in this case, so you'll see, for example, to mean a /24). But practically these are not being used a lot nowadays. So Many people are unaware of this.

Those authors are also not wrong in their definition of a subnet mask. They are only referring to the latest trend being followed in Networking.

Now back to the question. The principle is the same: convert the dotted-quad IP addresses and mask to 32-bit unsigned integers and AND each address with the mask. If the results are the same, they're in the same subnet. 

NM =
• Hence, first, two parts of the n/w have to be same. Last part(third & fourth) can be anything.  This removes the possibility for A and C options.
• Now for B, consider the third part:
28 = 0001 1100
31 = 0001 1111
        0001 1100
29 = 0001 1101
31 = 0001 1111
        0001 1101
Last 5 bits are different. So they are not on the same network. 

• Now for D, consider the third part:
129 = 1000 0001
31  =  0001 1111
          1000 0001 

161 = 1010 0001
31   = 0001 1111
          1000 0001
Last 5 bits(network part) are same. Hence, the correct answer is D.