Know an IP address, how to calculate its subnet mask ah?
Source: Internet
Author: User
There are two ways to compute the subnet mask:
Method One: Use the subnet number to calculate:
1. First of all, the number of subnets from the decimal number into binary number;
2. Then, the number of digits of the binary number obtained by the statistic is set to n;
3. Finally, the subnet mask of the address category corresponding to this IP address is first obtained. Then the subnet mask will be found in the host address part (that is, "host number") of the first n bits all 1, so you can get the IP address partition subnet subnet mask.
For example: A class B IP address 167.194.0.0 should be divided into 28 subnets:
1) (28) 10 = (11100) 2;
2 the number of digits in this binary is 5, then the n=5;
3 This IP address is a Class B address, while the subnet mask for Class B addresses is 255.255.0.0, and the host address of Class B addresses is the latter 2 digits (i.e. 0-255.1-254). Then the subnet mask 255.255.0.0 in the first 5 bits of the host address 1, you can get 255.255 248.0, and this set of values is divided into 28 subnets of the B class IP address 167.194.0.0 subnet mask.
Method Two: Using the number of hosts to calculate.
1. First, the number of hosts is converted from decimal numbers to binary numbers;
2. Next, if the number of hosts is less than or equal to 254 (note: the reserved two IP addresses should be removed), the number of digits in the binary number obtained from "1" is set to N; If the number of hosts is greater than 254, then n>8, that is, the host address will be more than 8;
3. Finally, use 255.255.255.255 to set the host address number of such IP addresses to 1, and then follow the "forward" order of all n bits to 0, the resulting value is the desired subnet mask value.
For example: You need to divide the class B IP address 167.194.0.0 into several subnets, each with a host of 500 units:
1) (500) 10 = (111110100) 2;
2 the number of digits in this binary is 9, then the n=9;
3 The subnet mask of the Class B address is 255. 255.0.0 's host address is all set to 1 and gets 255.255.255.255. And then from the back forward will be 9 digits after 0, can be: 11111111. 11111111.11111110.00000000 is 255.255.254.0. This set of values is divided into 500 sets of host-Class B IP address 167.194.0.0 subnet mask.
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.