A subnet mask allows users to identify which part of an IP address is reserved for the network and which part is available for host use. By looking at the IP address alone, especially now with classless inter-domain routing, users cannot tell which part of the address is which. Adding the subnet mask or netmask gives users all the information needed to calculate network and host portions of the address with ease. In summary, knowing the subnet mask can allow users to easily calculate whether IP addresses are on the same subnet or not.

Determining Network and Host Portions of an IP Address with a Subnet Mask
To determine what the network address is for any given IP address, users merely have to convert both octal addresses into binary and do a bitwise AND operation. Here is an example of using an IP address of 156.154.81.56 with a network mask of 255.255.255.240:
| IP Address: | 10011100.10011010.01010001.00111000 |
| Subnet mask: | 11111111.11111111.11111111.11110000 |
| Bitwise AND | ———————————————– |
| Result: | 10011100.10011010.01010001.00110000 |
The network address for the IP address and subnet mask in question is 156.154.81.48. To determine how many hosts can be on this same subnet, it is a simple operation. Count the number of bits from the right until the first “1″ in the binary network address display is reached. That number will be the power raised to 2 for the calculation of possible number of hosts. Also, subtract two from the result because one address is reserved for broadcast and network addresses. This results in the final algorithm of 2^n-2. In this case there are 4 bits of 0 in the network address, leaving 2^4-2 hosts possible or 14 hosts. This means that the network address is 156.54.81.48, that there is a range of addresses available to hosts from 156.154.81.49 – 156.154.81.62, and that the broadcast address for this network is 156.154.81.63.
Are Subnet Masks Necessary?
Subnet masks are critical to communications on an IP network. Network devices use the IP address targets and defined netmask to determine if the network the host is on is a local subnet or a remote network. This is important because devices act differently depending on the result. If the subnet is local, the device will send an ARP request to retrieve the MAC or hardware address of the system in question to communicate over the data-link layer. If the address is found to be on a remote network, then the network device routes packets to the gateway in its routing table that is set to handle that network. If no routing table entry matches that network, the packets are routed to the default route. If no default route is defined, the packets are dropped with nowhere left to go.

This is the BEST explaination and break down of ip-address and subnetting I have read, it was simple and to the point.
seriously the best explanation of subnet masks!! hats off to You Man! Respect
and thanks a lot to You!! God Bless!
Concise and to the point! Thanks
Really done a great job. thanks in abundance.
best way of explanation.
a lot of information. thank u
Clear ans simple..Thanks a mil
Like all the other persons who have commented. This is by far yhe best explanation of subneting. I have read about 6 different articles before i cam to this one. All the others confuse matters by going straight to the binary.
Excelent work