Home / Certification / How to understand Subnet Masks

How to understand Subnet Masks

An IP address is a unique identifier for a device connected to a network. It’s a 32 bits number that converted in decimal covers the range 0-4.294.967.296 (i.e. 2 power 32). If the addressing space wasn’t hierarchically organized, it would be possible to connect around 4.3 billions network devices.

To simplify the use of the IP addresses, the binary number is often split in 4 octets. An octet is a group of 8 bits, and the different octets are separated by dots. Each octet, being composed by 8 bits, can cover the decimal range 0-255. An example of IP address in dotted notation is 199.234.8.78 where each number is an octet.

Think about a car odometer!

IP subnettingA simple way to imagine the IP addresses is thinking of them as they were the numbers of an old fashioned odometer. The cylinders spin around and after a full cycle they start again from the same initial number. The first value is a zero and rotating around it reaches 255 before starting again from zero.

 

IP addresses are binary numbers

It’s very important understanding how the IP addresses are natively binary numbers (being used in electronic devices) so each increment is done bitwise. For that reason, in the next table when an octet reaches 255, the next value is again zero. The octets are composed by 8 bits each, so they can only cover decimal values in the range 0-255. The following table shows how the IP addresses are incremented…doesn’t remind of an odometer?

 

0.0.0.0
0.0.0.1
0.0.0.2
0.0.0.3
….keeping incrementing….
0.0.0.253
0.0.0.254
0.0.0.255
0.0.1.0
0.0.1.1
0.0.1.2
0.0.1.3
….keeping incrementing….
0.0.1.253
0.0.1.254
0.0.1.254
0.0.1.255
0.0.2.0
0.0.2.1
0.0.2.2
….keeping incrementing….
255.255.255.254
255.255.255.255

 

Valid subnet masks

The IP subnet mask is a key component to determine the length of a subnet. The subnet mask is basically a mask of continguos bits all set to ‘1’ starting from the left side. All other bits are set to ‘0’. The next table illustrates all the valid subnet masks:

Subnet Mask
(decimal)
Subnet Mask (binary)Subnet Mask
(CIDR)
255.0.0.011111111.00000000.00000000.00000000/8 
255.128.0.011111111.10000000.00000000.00000000/9
255.192.0.011111111.11000000.00000000.00000000/10
255.224.0.011111111.11100000.00000000.00000000/11
255.240.0.011111111.11110000.00000000.00000000/12
255.248.0.011111111.11111000.00000000.00000000/13
255.252.0.011111111.11111100.00000000.00000000/14
255.254.0.011111111.11111110.00000000.00000000/15
255.255.0.011111111.11111111.00000000.00000000/16
255.255.128.011111111.11111111.10000000.00000000/17
255.255.192.011111111.11111111.11000000.00000000/18
255.255.224.011111111.11111111.11100000.00000000/19
255.255.240.011111111.11111111.11110000.00000000/20
255.255.248.011111111.11111111.11111000.00000000/21
255.255.252.011111111.11111111.11111100.00000000/22
255.255.254.011111111.11111111.11111110.00000000/23
255.255.255.011111111.11111111.11111111.00000000/24
255.255.255.12811111111.11111111.11111111.10000000/25
255.255.255.19211111111.11111111.11111111.11000000/26
255.255.255.22411111111.11111111.11111111.11100000/27
255.255.255.24011111111.11111111.11111111.11110000/28
255.255.255.24811111111.11111111.11111111.11111000/29
255.255.255.25211111111.11111111.11111111.11111100/30
255.255.255.25411111111.11111111.11111111.11111110/31
255.255.255.25511111111.11111111.11111111.11111111/32

Since the ‘1’ bits need to be contiguous, the octets of the subnet mask can only have the following values: 128, 192, 224, 240, 248, 252, 254, 255. As shown in the table, the shortest subnet mask has a length of /8 (corresponding to 255.0.0.0) while the longest has a length of  /32 (corresponding to 255.255.255.255).

 

Default subnet masks

IP Addresses are divided in classes and the following subnet masks are the defaults for the classes A-B-C:

  • Class A:  255.0.0.0
  • Class B:  255.255.0.0
  • Class C:  255.255.255.0

It’s very important understanding how the binary/decimal/CIDR notations are different expressions of the same concept. For example:

11111111.11111111.00000000.00000000  =  255.255.0.0  =  /16

In the example presented just above, the subnet mask is the same but it can be expressed using three different notations: binary, decimal, CIDR.

For the sake of the IP subnetting, it’s fundamental remembering that a decimal value of 255 corresponds to a ‘1111 1111′ so eight bits all set to one. The following rapid conversions need to be memorized:

255.0.0.0  =  /8

255.255.0.0  =  /16

255.255.255.0  =  /24

 

Non-default subnet masks

In case of a subnet mask with a non-default value, it’s easy understanding how the mechanisms work. For example:

255.255.192.0

can be converted into CIDR notation thinking that the two octets with 255 value correspond to 8+8 bits set to one, while 192 corresponds to two additional bits (see subnet mask table presented above) so a total of 8+8+2 = 18. In summary:

255.255.192.0  =  /18

 

The subnet mask is a fundamental component of IP subnetting, even though many Network Engineers struggle in fully understanding the meaning. If you are not familiar on how to calculate the subnetting presented in the table above, you might want to have a look at our Easy Subnetting Technique that allows to solve any subnetting problem in less than a minute.

Have you ever had an IP addressing problem in your network?

How to understand Subnet Masks
5 (100%)

About Valerio Plessi

Valerio is a CCIE R&S certified Network Consultant Engineer with 10+ years of experience in IT. In the past he worked for Cisco Systems as High Touch Technical Support Engineer, then he switched to Network Consulting taking care of large Enterprise and Service Provider customers. When not in front of his MacBook, he is probably travelling and photographing the world!

Check Also

books for network engineersbooks for network engineers

The 10 best books for Network Engineers

When I started my career in computer networking, I wish I knew the best books …

3 comments

  1. In the above illustration how can they be CLass A, B and C
    Class A: 255.0.0.0
    Class B: 255.255.0.0
    Class C: 255.255.255.0

    As far as my knowledge Class A has a range of only 0-127, where as 255 is shown as Class A, please make me understand

    • Class A: 255.0.0.0
      Class B: 255.255.0.0
      Class C: 255.255.255.0

      are the default subnet masks for class A, B and C. You are referring to the first octet of the IP address, in which is correct considering it for determining the class. For example:

      10.0.0.1 255.0.0.0

      Is a class A (range 0-127) with default subnet mask of /8 (255.0.0.0).

Leave a Reply

Your email address will not be published. Required fields are marked *