In the scenario where a network node needs to determine whether a destination IP address is inside or outside the LAN, the node uses a subnet mask to make this determination.

LAN subnet range

All nodes within the LAN have IP addresses chosen from a specific contiguous range. This range defines the LAN’s subnet. The range is structured that the leftmost bits are same for devices in a common LAN.

For example in a IPv4 network, devices within the same LAN might all have IP address in the format 192.168.1.x where the ‘x’ represents the unique portion of each devices’s IP address. The subnet range is 192.168.1.0 to 192.168.1.255. (8 bits for one block, max value for a block is 255 which is 8 1s)

Device_1_addr: 192.168.1.122
Device_2_addr: 192.168.1.220
Decive_3_addr: 192.168.1.168

Subnet mask

To identify whether a given IP address is inside the LAN, the node uses a subnet mask. We want to know if the prefix (leftmost bits, excludes the unique bits) of two nodes are in the same subnet range (192.168.1.0), so we can confirm they are within the same LAN.

Detailed masking process

The subnet mask is a binary mask, we would like to set the unique portion of the devices to 0, and only focus on the prefix. We use the AND operation with a mask that has sequence of contiguous 1s for the prefix portion, followed by contiguous 0s for the device independent bits.

Example

Each subnet block is 8 bits long: 0000 0000. 0000 0000. 0000 0000. 0000 0000

Use previous example, we want to know if two devices (sender and receiver) are within the common LAN, we use Device_1_addr and Device_2_addr as example:

  1. Device 1 address to binary
Device_1_addr
11000000.10101000.00000001.01111010
  1. Device 2 address to binary
Device_2_addr
11000000.10101000.00000001.11011100
  1. Perform masking on device 1
  11000000.10101000.00000001.01111010 <- DATA
& 11111111.11111111.11111111.00000000 <- MASK
--------------------------------------
  11000000.10101000.00000001.00000000 <- RESULT
  1. Perform masking on device 2
  11000000.10101000.00000001.11011100
& 11111111.11111111.11111111.00000000
--------------------------------------
  11000000.10101000.00000001.00000000
  1. Compare masking results Convert both results to decimal:
Device 1 result
192.168.1.0
Device 2 result
192.168.1.0

Since the results of the logical AND operation for both addresses matches the LAN’s subnet range (192.168.1.0), two devices are within the same LAN.


Back to parent node: Address Resolution Protocol (ARP)

Computer_networksINFO1112IPInternet_layerLANBinary_masking