A quick note on subnet mask

     Like myself, a lot of you may be not everyday network guys, but sometimes need to understand and work on network setup, configuration etc., specially while dealing with infrastructure projects. I had some confusions how the subnet mask or subnet are presented in IPv4 and had to refresh my mind going through documents and articles. I put together a note that is easy to understand and thought to post as it might be helpful for someone else also.


In this note, I am not going to explain the definition or other details regarding the subnet or subnet mask. If any of you are interested into that details, there are tons of materials available on the web including this Wikipedia post
     In IPv4, the subnet mask or subnet are usually presented in two forms. Below example is for 22 bit long network mask. That means 22 bits represent the network part and remaining 10 (32-22)  bits represent the host part and we only mask the network part. The available IP address(es) are calculated based on how many un-masked bits are available.

  • Classful network way: The routing prefix or subnet mask is usually specified in  quad-dotted decimal representation like
          255.255.252.0 (decimal format) 
          11111111.11111111.11111100.00000000 (binary format)
        
      Hope, you still remember, how to convert binary to decimal and vice-versa, if not, you can find this tool very handy: http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html
      
  • Classless Inter-Domain Routing (CIDR) way: The routing prefix is presented as  network address followed by slash character (/) followed by bit-length of the prefix, i.e. <network address>/<bit-length-of-prefix>
          xxx.xxx.xx.0/2
          
          So, in the above example, 22 bits are masked and only remaining 10 bits are available for host IP addresses. Another example, below

           192.168.55.0 (IP) ; 255.255.255.0 (netmask) or 192.168.55.0/24 applies to IPs in the range of 192.168.55.0 - 192.168.55.255

University of Wisconsin maintains a very handy CIDR Conversion Table, which along with other information gives you CIDR prefix length, their Dotted Decimal Netmask, and corresponding Netmask in Binary format.

 
Hope, this quick note and referenced information will be helpful.