Subnet Mask Concise Manual

Source: Internet
Author: User

All the calculation and application of the subnet mask are based on the binary, so we should focus on the binary form of The netmask. Generally, we can view the IP attribute in decimal format. in order to make it easier for users to watch, in fact, computers use binary methods to calculate and use subnet masks,

A common IP address is composed of a network ID and a host ID, such

192.168.0.3

Network ID: 192.168.0

Host ID: 3

The subnet mask is also the same, such

255.255.255.0

However, because the subnet mask is bitwise, we need to first convert it to binary for analysis. This is a string of binary numbers with a length of 32 bits (simply put, 32 bits ).

11111111.111111.1111111111.00000000

The number of 1 represents the length of the subnet mask.

0 represents the length of the subnet mask host bit.

According to the subnet mask, only the network bit can be composed of 1 consecutive, the host bit can only be composed of 0 consecutive, and the left side can only be the network bit, after the network bit is written, it can only be the host bit,

Therefore, it can only be a combination of the following numbers

10000000----128
11000000----192
11100000----224
11110000----240
11111000----248
11111100----252
11111110----254
11111111----255

That is to say, only the following decimal subnet mask may occur:

201710000128.0

This is wrong!

201710000120.0

Because binary will never convert such a decimal number

This subnet mask is also incorrect!

2017128.128.0

If it is converted to binary, you will understand,

11111111.0000000.0000000.00000000

It does not comply with the rule that the network identification position is consecutive 1.

 

 

Subnet Mask Representation

1. Common decimal representation,

255.0.0.0

255.254.0.0

2. Common expressions in linux, which are represented by an IP address plus "/" followed by a number ranging from 1 to 32. The digit part is the length of the network identification space.

192.168.1.1/24

Because the length of the network identification space is 24, that is, there are 24 1, that is

11111111.111111.1111111111.00000000

Convert to decimal, that is, decimal limit 255.0.

 

How to calculate the subnet mask

The subnet mask is used to divide subnets. Therefore, the exact number of subnet masks is divided into subnets in two ways. The first is to determine the number of subnets in advance. the number of hosts in each subnet is determined in advance,

1. determine the number of subnets in advance

1) convert the number of subnets to binary representation.

 

2) The number of digits to obtain the binary value is N.

 

3) obtain the subnet mask of the IP address, and obtain the subnet mask of the IP address.

 

To divide Class B IP address 168.195.0.0 into 27 subnets:

 

1) 27 = 11011

 

2) the binary is five digits, N = 5

 

3) set the subnet mask of the Class B address to the first 5 locations of the host address of 255.255.0.0, and obtain 255.255.248.0.

 

That is, the subnet mask of Class B IP address 168.195.0.0 divided into 27 subnets.

2. determine the number of hosts in each subnet in advance.

1) convert the number of hosts to binary representation

 


2) If the number of hosts is less than or equal to 254 (note that the reserved two IP addresses are removed), the binary number of the host is obtained, which is N. N <8. If it is greater than 254, N> 8, which means the host address occupies more than 8 digits.

 


3) Use 255.255.255.255.255 to set the number of host addresses of this type of IP address to 1, and then set all the N digits to 0 from the forward, that is, the subnet mask value.

 


To divide Class B IP address 168.195.0.0 into several subnets, each subnet contains 700 hosts:

 


1) 700 = 1010111100

 


2) the binary is ten digits, N = 10

 


3) set all the host addresses of the subnet mask 255.255.0.0 for the Class B address to 1, and obtain 255.255.255.255.255.

 


Then, move the last 10 positions 0 from the back to the back, that is, 11111111.1111111100.00000000.

 


That is, 255.255.252.0. This is the subnet mask of the Class B IP address 168.195.0.0 to be divided into 700 hosts.


Related materials: https://wangyan.org/blog/ipv4-mask.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.