what is subnet mask [reading: 32327]
subnet mask is the basic knowledge that every network administrator must master. Only by mastering it can we really understand the setting of TCP/IP protocol. Let's explain what subnet mask is in simple terms.
structure of IP address
to understand what a subnet mask is, you must understand the composition of IP address. The Internet is made up of many small networks, and each network has many hosts, thus forming a hierarchical structure. IP addresses are designed with the hierarchical characteristics of address allocation in mind, and each IP address is divided into two parts: network number and host number, so as to facilitate the addressing operation of IP addresses.
how many digits are the network number and the host number of an p>IP address? If you don't specify it, you don't know which bits are the network number and which are the host number, which needs to be realized by subnet mask.
what is a subnet mask
a subnet mask cannot exist alone, and it must be used together with an IP address. Subnet mask has only one function, which is to divide an IP address into two parts: network address and host address.
the setting of subnet mask must follow certain rules. Like IP address, the length of subnet mask is 32 bits, and the network bit on the left is represented by binary number "1"; On the right is the host bit, which is represented by the binary number "1". The attached figure shows the binary comparison of IP address "192.168.1.1" and subnet mask "255.255.255.1". Among them, there are 24 "1", which means that the left 24 bits of the corresponding IP address are network numbers; There are eight "1", which means that the 8 bits on the right of the corresponding IP address are the host number. In this way, the subnet mask determines which of the 32-bit binary digits of an IP address are network numbers and which are host numbers. This is very important for the network using TCP/IP protocol. Only by subnet mask can the relationship between the subnet where a host is located and other subnets be indicated, so that the network can work normally.
There are hundreds of commonly used subnet masks
Here are only two commonly used subnet masks, namely "255.255.255.1" and "255.255.1.1".
1. the subnet mask is "255.255.255.1": the last number can be changed arbitrarily in the range of 1~255, so 256 IP addresses can be provided. However, the actual number of available IP addresses is 256-2, that is, 254, because the host number cannot be all "1" or all "1".
2. a network with subnet mask of "255.255.1.1": the last two digits can be arbitrarily changed in the range of 1~255, and 2552 IP addresses can be provided. But the actual number of available IP addresses is 2552-2, that is, 65123.
the subnet mask setting of p>IP address is not arbitrary. If the subnet mask is set too large, that is to say, the subnet range is enlarged, then according to the subnet routing rules, it is likely that the data sent to the destination machine that is not in the same subnet as the local machine will be considered to be in the same subnet because of wrong judgment, then the data packet will be
Responder: Fanix-Trainee Wizard Level 3 9-31 14: 53
The IP address is a 32-bit binary value. Usually we use dotted decimal system, such as 192.168.1.5 and so on.
each IP address can be divided into two parts. That is, the network number part and the host number part: the network number indicates the number of the network segment to which it belongs, and the host number indicates the address number of the host in the network segment. According to the size of the network, IP addresses can be divided into five categories: A, B, C, D and E. Among them, A, B and C are the three main types of addresses, D is a multicast address for multicast transmission, and E is used to expand standby addresses. The valid range of a, b and c IP addresses is as follows:
category network number/occupied host number/occupied usage
a 1 ~ 126/81 ~ 2551 ~ 2551 ~ 254/24 national level
b 128 ~ 1911 ~ 255/161 ~ 2551. 16 Cross-organization
C192 ~ 223 1 ~ 255 1 ~ 255/241 ~ 254/8 Enterprise organization
With the continuous expansion of Internet application, the disadvantages of the original IPv4 are gradually exposed, that is, the network number occupies too much space and the host number is too few, so the host address it can provide is becoming scarcer and scarcer. At present, in addition to using NAT to use reserved addresses in enterprises.
The main purpose here is to effectively use IP addresses in the case of network segmentation. By taking the high-order part of the host number as the subnet number, we can expand or compress the subnet mask from the usual network bit boundary to create more subnets of a certain type of address. However, when more subnets are created, the number of available host addresses on each subnet will be less than before.
subnet mask is to indicate whether two IP addresses belong to the same subnet, and it is also a 32-bit binary address. Each of them is 1, which means that the bit is a network bit, and 1 means a host bit. Like IP addresses, it is represented by dotted decimal system. If two IP addresses get the same result under the bitwise AND calculation of subnet mask, it means that they * * * belong to the same subnet.
when calculating the subnet mask, we should pay attention to the reserved addresses in the IP address, that is, the "1" address and the broadcast address. They refer to the IP address when the host address or the network address are all "1" or "1", which represent the local network address and the broadcast address, and generally cannot be counted.
Here's an example to illustrate the algorithm of subnet mask:
For an IP address that doesn't need to be divided into subnets, its subnet mask is very simple, that is, it can be written according to its definition: if a class B IP address is 11.12.3.1, it doesn't need to be divided into subnets, then its subnet mask is 255.255.1.1. If it is a class C address, its subnet mask is 255.255.255.1. Other analogies will not be described in detail. What we will introduce below is an IP address, and its high host bit needs to be used as the divided subnet network number, and the rest is the host number of each subnet. How to calculate the mask of each subnet at this time?
1. Using the number of subnets to calculate
Before finding the subnet mask, we must first find out the number of subnets to be divided and the number of hosts required in each subnet.
1) Convert the number of subnets into binary to represent
2) Get the number of bits in the binary, which is N
3) Get the subnet mask of the IP address, and set the first n bits of its host address to 1 to get the subnet mask for subnetting the IP address.
If you want to divide the class B IP address 168.195.1.1 into 27 subnets:
1)27=11111
2) The binary number is five digits, and N = 5
3) Mask the subnet of the class B address into the first five positions of the host address of 255.255.1.1.
2. Calculate the number of hosts
1) Convert the number of hosts into binary to represent
2) If the number of hosts is less than or equal to 254 (pay attention to remove the two reserved IP addresses), get the binary digits of the host, which is n, where n <: 8。 If it is greater than 254, then n >: 8, which means that the host address will occupy more than 8 bits.
3) Use 255.255.255.255 to set all the host address bits of this IP address to 1, and then set all the n bits to 1 from back to front, which is the subnet mask value.
If you want to divide the class B IP address 168.195.1.1 into several subnets, there are 711 hosts in each subnet:
1) 711=1111111111
2) The binary number is ten digits, N = 11
3) The subnet mask of the class B address is 255. Get 255.255.255.255
, and then set the back 11 to 1 from back to front, which is: 111111111111111111111111111111
that is, 255.255.252.1. This is the subnet mask of Class B IP address 168.195.1.1 to be divided into 711 hosts.
the following is a list of all subnets that can be divided by various IP addresses, the number of divided hosts and subnets, and the (maximum) number of hosts and subnets. Pay attention to remove the reserved IP addresses (that is, those with host bits or subnet bits all of "1" or "1" after division):
Class A IP addresses:
subnet bits/maximum number of subnet masks for host bits/maximum number of hosts
2/22 255.192.1.1 2/4194312
. 21 255.241.1.1 14/1148574
5/19 255.248.1.1 31/524286
6/18 255.252.1.1 62/262142
7/17 255.254.1.1 126/131171
8/16 255.255.1.1 254/65536
9/ 15 255.255.128.1 511/32766
11/14 255.255.192.1 1122/16382
11/13 255.255.224.1 2146/8191
12/12 255.255.241.1 4194/4194
13/ 11 255.255.248.1 8191/2146
14/11 255.255.252.1 16382/1122
15/9 255.255.254.1 32766/511
16/8 255.255.255.1 65536/254
17/ 7 255.255.255.128 131171/126
18/6 255.255.255.192 262142/62
19/5 255.255.255.224 524286/31
21/4 255.255.255.241 1148574/14
21/ 3 255.255.255.248 2197151/6
22/2 255.255.252 4194312/2
Class B IP address:
subnet bit/host bit subnet mask maximum number/host maximum number
2/. 13 255.255.224.1 6/8191
4/12 255.255.241.1 14/4194
5/11 255.255.248.1 31/2146
6/11 255.255.252.1 62/1122
7/9 255.255.254.1 126/511
8/ 8 255.255.255.1 254/254
9/7 255.255.255.128 511/126
11/6 255.255.255.192 1122/62
11/5 255.255.255.224 2146/31
12/4 255.255.255.241 4194/ 14
13/3 255.255.255.248 8191/6
14/2 255.255.255.252 16382/2
Class C IP address:
subnet bit/host bit subnet mask Maximum number/host number. 5 255.255.224 6/31
4/4 255.255.255.241 14/14
5/3 255.255.255.248 31/6
6/2 255.248 Let's look at a common question in the exam: the IP address of a host is 212.112.14.137, and the mask is 255.255.255.224. It is required to calculate the network address and broadcast address of the host's network.
The conventional method is to convert this host address and subnet mask into binary numbers, and then the network address can be obtained after logical AND operation. In fact, if you think about it carefully, you can get another method: the mask of 255.255.255.224 contains 256-224 = 32 IP addresses (including network addresses and broadcast addresses), so the network address with this mask must be a multiple of 32. The network address is the beginning of the subnet IP address, and the broadcast address is the end. The usable host address is within this range, so only 128 is slightly less than 137 and is a multiple of 32, so the network address is 212.112.14.128. The broadcast address is the network address of the next network minus 1. And the next multiple of 32 is 161, so we can get the broadcast address of 212.112.14.159. This example can be understood by referring to the following table.
sub-network number of binary sub-network domain number of binary host domain number range of binary host domain number
No.1 sub-network 111 11111.1 Thru.31
No.2 sub-network 111 11111 thru 11111 Thru.63
No.3 sub-network 111 11111 Thru. .64thru.95
the 4th subnetwork 111 11111.96thru.127
the 5th subnetwork 111 11111 thra1111.128thru.159
the 6th subnetwork 111.