What is the subnet mask?

On the network, data is transmitted from one place to another by IP addressing.
Logically speaking, it is a two-step process.
The first step is to find the network to which it belongs from the IP , for example, to find which community the person belongs to;
The second cloth, and then find the location of the host in this network from the IP , just like finding this person in the community.
The network in the first step is called "Subnet".
Logically speaking, generally the same subnet (Subnet) uses the same gateway. Just like the entrance to a community.
The IP address of IPv4 is 32 bits, in the form of http://xxx.xxx.xxx.xxx , and each xxx value is 0-255.
If the first three xxx are the same, it means the same subnet, or the first two, or something else? This is not necessarily.
Just like there are large and small communities, some communities have thousands of households, and some communities have only a few.
Therefore, the "Subnet Mask" is introduced to identify the size of the subnet.
The IP addresses we generally see are encoded in decimal, so if you change your perspective, from a binary point of view, each IP address is a 32-bit 1 or 0.
The subnet mask is used to tell the coverage area of ​​this subnet. Of the 32 bits, how many first bits are the network segment? Of course, the rest is the host segment.
Take a typical example:
The first 24 bits in the IP represent the subnet number, and the last 8 bits represent the host number.
So the subnet mask is 24 1s (representing the first 24 bits are the subnet part), plus 8 0s (the last 8 bits are the host part).
If the identification method of IP is used, it is 255.255.255.0.
Each 255 corresponds to 8 binary 1s, and the last 0 corresponds to 8 binary 0s.
The subnet can hold up to 256 hosts, that is, host numbers from 0 to 255.
Of course, the actual situation is not so much, there are some special numbers that are reserved (broadcast, gateway, etc.).
所以,总结来说:子网掩码就是用来帮助我们从IP地址中找出有多少位是表示子网的,有多少位又是表示主机号的,我们要清楚,当二进制中表示子网的位都设为1,主机都设为0

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325749583&siteId=291194637