How to calculate the subnet mask
Business development often causes many organizations to face the following problem: the number of workstations is increasing, and it is becoming increasingly difficult to manage a single large network. If a single large network is divided into multiple subnets, the performance of the entire network can be significantly improved by separately managing each subnet.
To divide subnets, You need to calculate the subnet mask and allocate the corresponding host blocks. Although binary calculation can be used to draw a conclusion, it is easier to calculate in decimal format. After long-term practice and experience
The author summarizes the subnet mask and the decimal algorithm of the host block.
Method 1: calculate the number of subnets.
- 1
1. First, convert the number of subnets from decimal to binary;
- 2
2. Then, set the number of bits to n;
- 3
3. Finally, find the subnet mask of the address category corresponding to this IP address. Then, set all the first n digits of the host address (that is, the host number) of the obtained subnet mask to 1, so that the subnet mask of the IP address is obtained.
- 4
For example, you need to divide the Class B IP address 167.194.0.0 into 28 subnets:
1) (28) 10 = (11100) 2;
2) If the binary number is 5, n = 5;
3) this IP address is a Class B address, and the subnet mask of the Class B address is 255.0.0, and the host address of the Class B address is the last two digits (0-255.1-254 ). Set the first five hosts in subnet mask 255.0.0 to 1 to obtain 255.255.255.248.0, which is the subnet mask of type B IP address 167.194.0.0 divided into 28 subnets.
End
Method 2: calculate the number of hosts.
- 1
1. First, convert the number of hosts from decimal to binary;
- 2
2. then, if the number of hosts is less than or equal to 254 (Note: The reserved two IP addresses should be removed), count the number of digits of the binary number obtained from "1" and set it to N; if the number of hosts is greater than 254, N> 8, that is, the host address will exceed 8 digits;
- 3
3. finally, use strongswan 255.255 to set all the host address locations of these IP addresses to 1, and then set all the n-bits to 0 in the order of "forward from the back, the obtained value is the subnet mask value.
- 4
For example, you need to divide the Class B IP address 167.194.0.0 into several subnets, each with 500 hosts:
1) (500) 10 = (111110100) 2;
2) If the binary number is 9, n = 9;
3) set the host address of the subnet mask 255. 255.0.0 of the B-type address to 1 to obtain 255.255.255.255.255. Then, move the last 9 to 0 from the back to the back, and you can get: 11111111. 11111111.111110.00000000, that is, 255.255.254.0. This group of values is the subnet mask that is divided into 500 Class B IP addresses of the host 167.194.0.0
How to calculate the subnet mask