The subnet mask is similar to an IP address - it is also a 4-byte field and can be represented using dot notation. In binary, it always consists of an unbroken series of ones, followed by an unbroken sequence of zeros. The total number of bits is always 32, but the number of ones and zeros determines the nature of the mask. By comparing any IP address with a given mask, it is possible to split the address into two parts, a network ID and a device ID (refer figure 6).
By computing the network ID with the origin IP address and the network ID of the destination IP address, and comparing the two, one can easily determine if the destination is within the same subnet (the network IDs will be equal.) And thus if the destination is local or remote (network IDs differ.)
A subnet mask allows you to identify which part of an IP address is reserved for the network, and which part is available for host use. If you look at the IP address alone, especially now with classless inter-domain routing, you can't tell which part of the address is which. Adding the subnet mask, or netmask, gives you all the information you need to calculate network and host portions of the address with ease. In summary, knowing the subnet mask can allow you to easily calculate whether IP addresses are on the same subnet, or not.
- How to subnet guide