# Calculate Subnet Network Masks and CIDR notation

**Posted:**April 6th, 2011 |

**Author:**jordan |

**Filed under:**Blog, Networking |

**Tags:**calculate, networking, subnets | No Comments » Tweet

How to calculate the network mask from a CIDR notation, or a CIDR notation from a network mask. To figure this out we need to understand the relationship between the two. A network mask when written in binary will be 32 bits long. This also means that each octet of a network mask can hold a total of 8 bits.

255.255.0.0 == 11111111.11111111.00000000.00000000

255.255.255.0 == 11111111.11111111.11111111.00000000

255.255.255.192 == 11111111.11111111.11111111.11000000

### Example 1-1: Calculate the network mask from CIDR Notation /16

1. First subtract the CIDR notation from the total number of bits available in CIDR notation. This is the number of bits occupied in the mask.

2. Next, place no more than 8 bits into each octet starting with the one the on the right.

3. Move the bits into an exponent of two and calculate

4. Subtract one from each octet and you now have your reverse mask

5. Inverse the reverse mask to finally find out your network mask

The network mask for CIDR notation /16 is 255.255.0.0

### Example 2-1: Calculate the CIDR notation from network mask 255.255.0.0

This is exactly the procedure above but just reversed

1. Inverse the network mask to find out your reverse mask

2. Add one to each populated octet

3. Find the exponent value of 2 for each octet (PROTIP: double 2 in your head until you hit the number, that is the number of bits ie {2 4 8 16} = 4…)

4. Add up all the exponent values and subtract from 32

### Example 1-2: Calculate the network mask from CIDR Notation /13

1. First subtract the CIDR notation from the total number of bits available in CIDR notation. This is the number of bits occupied in the mask.

2. Next, place no more than 8 bits into each octet starting with the one the on the right.

3. Move the bits into an exponent of two and calculate

4. Subtract one from each octet and you now have your reverse mask

5. Inverse the reverse mask to finally find out your network mask (PROTIP, for the second octet just subtract 7 from 255)

### Example 2-2: Calculate the CIDR notation from network mask 255.248.0.0

This is exactly the procedure above but just reversed

1. Inverse the network mask to find out your reverse mask

2. Add one to each populated octet

3. Find the exponent value of 2 for each octet (PROTIP: double 2 in your head as many bits as you have 2 4 8 16…)

4. Add up all the exponent values and subtract from 32

Tweet
## Leave a Reply