Subnet Masks

By | November 3, 2012

Formatting needs completing

Subnet Masks

For a device to know if another device its wants to communicate with its on the same network (and therefore can be communicated with directly via the switch its connected to) or whether it is on a different network (and therefore can only be communicated with via its default gateway) it needs to calculate its network ID and the network ID of the destination device. A subnet mask is required to calculate a network ID.

Subnet Mask by Example

Example 1 – Simple network with a Subnet 255.255.255.0

IP Address Subnet Mask Default Gateway
Device A 192.168.0.10 255.255.255.0 192.168.0.1
Device B 192.168.1.200 255.255.255.0 192.168.1.1
The IP address 192.168.0.10 converted to binary is 11000000 10101000 00000000 00001010
A subnet mask of 255.255.255.0 converted to binary is 11111111 11111111 11111111 00000000
The network ID is calculated by performing a bit by bit Boolean AND operation (if both bits are 1, a 1 returned, else a 0 is returned) between the IP address and subnet mask.
So, the network ID for Device A is calculated as 11000000 10101000 00000000 00000000
(192. 168.0.0 in decimal).

 

Repeating this process for Device B

 

The IP address 192.168.1.20 converted to binary is           11000000 10101000 00000001 00010100

A subnet mask of 255.255.255.0 converted to binary is   11111111 11111111 11111111 00000000

So, the network ID for Device B is calculated as                  11000000 10101000 00000001 00000000 (192. 168.1.0 in decimal).

 

Now, comparing the Device A’s Networks ID with Device B’s Network ID we can clearly see that they’re not equal (192.168.0.0 <> 192.168.1.0) and therefore if the Device A wants to communicate with Device B it must send its network packets to its default gateway (192.168.0.1) and hope that the router can route traffic to the Device B.

Example 2 – Network with a Subnet of 255.255.254.0

                                IP Address                          Subnet Mask                     Default Gateway

Device A              192.168.0.10                       255.255.254.0                     192.168.0.1

Device B              192.168.1.20                       255.255.254.0                     192.168.1.1

Device C              192.168.2.30                       255.255.254.0                     192.168.2.1

 

The IP address 192.168.0.10 converted to binary is           11000000 10101000 00000000 00001010

A subnet mask of 255.255.254.0 converted to binary is   11111111 11111111 11111110 00000000

So, the network ID for Device A is calculated as                  11000000 10101000 00000000 00000000 (192. 168.0.0 in decimal).

 

Repeating this process for Device B

 

The IP address 192.168.1.20 converted to binary is           11000000 10101000 00000001 00010100

A subnet mask of 255.255.254.0 converted to binary is   11111111 11111111 11111110 00000000

So, the network ID for Device B is calculated as                  11000000 10101000 00000000 00000000 (192. 168.0.0 in decimal).

 

Repeating this process for Device C

 

The IP address 192.168.2.30 converted to binary is           11000000 10101000 00000010 00011110

A subnet mask of 255.255.254.0 converted to binary is   11111111 11111111 11111110 00000000

So, the network ID for Device C is calculated as                  11000000 10101000 00000010 00000000 (192. 168.2.0 in decimal).

 

 

Now, comparing the Device A’s Networks ID with Device B’s Network ID we can clearly see that they’re equal (192.168.0.0 == 192.168.0.0) and therefore if the Device A wants to communicate with Device B it can send network packets directly across the switch its connected to.

Comparing the Device A’s Networks ID with Device C’s Network ID we can clearly see that they’re not equal (192.168.0.0 <> 192.168.2.0) and therefore if the Device A wants to communicate with Device C it must send its network packets to its default gateway (192.168.0.1) and hope that the router can route traffic to the Device C.

Example 3 – Network with a Subnet of 255.255.240.0

                                IP Address                          Subnet Mask                     Default Gateway

Device A              192.168.0.10                       255.255.240.0                     192.168.0.1

Device B              192.168.1.20                       255.255.240.0                     192.168.1.1

Device C              192.168.2.30                       255.255.240.0                     192.168.2.1

Device D              192.168.15.160                  255.255.240.0                     192.168.15.1

Device E               192.168.16.170                  255.255.240.0                     192.168.16.1

 

The IP address 192.168.0.10 converted to binary is           11000000 10101000 00000000 00001010

A subnet mask of 255.255.240.0 converted to binary is   11111111 11111111 11110000 00000000

So, the network ID for Device A is calculated as                  11000000 10101000 00000000 00000000 (192. 168.0.0 in decimal).

 

Repeating this process for Device B

 

The IP address 192.168.1.20 converted to binary is           11000000 10101000 00000001 00010100

A subnet mask of 255.255.240.0 converted to binary is   11111111 11111111 11110000 00000000

So, the network ID for Device B is calculated as                  11000000 10101000 00000000 00000000 (192. 168.0.0 in decimal).

 

Repeating this process for Device C

 

The IP address 192.168.2.30 converted to binary is           11000000 10101000 00000010 00011110

A subnet mask of 255.255.240.0 converted to binary is   11111111 11111111 11110000 00000000

So, the network ID for Device C is calculated as                  11000000 10101000 00000010 00000000 (192. 168.0.0 in decimal).

 

Repeating this process for Device D

 

The IP address 192.168.15.160 converted to binary is       11000000 10101000 00000010 00011110

A subnet mask of 255.255.240.0 converted to binary is   11111111 11111111 11110000 00000000

So, the network ID for Device D is calculated as                  11000000 10101000 00000010 00000000 (192. 168.0.0 in decimal).

 

Repeating this process for Device E

 

The IP address 192.168.16.170 converted to binary is       11000000 10101000 00010000 00011110

A subnet mask of 255.255.240.0 converted to binary is   11111111 11111111 11110000 00000000

So, the network ID for Device E is calculated as                  11000000 10101000 00010000 00000000 (192. 168.16.0 in decimal).

 

Comparing Device A’s Network ID (192.168.0.0) with Devices B, C, D & E.

 

                                Devices Network ID        Compared to Device A                  Communicate

Device B              192.168.0.0                         Equal                                                     Directly

Device C              192.168.0.0                         Equal                                                     Directly

Device D              192.168.0.0                         Equal                                                     Directly

Device E               192.168.16.0                       Equal                                                     Via default gateway.