Home  >  Article  >  What is subnet mask

What is subnet mask

青灯夜游
青灯夜游Original
2023-01-29 16:57:0126614browse

The subnet mask is a 32-bit address that is used to mask a part of the IP address to distinguish the network identification and the host identification, and to indicate whether the IP address is on a LAN or a WAN. The subnet mask can indicate which bits of an IP address identify the subnet where the host is located, and which bits identify the host's bit mask; the subnet mask cannot exist alone, it must be used in conjunction with the IP address.

What is subnet mask

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

What is a subnet mask?

Subnet mask (subnet mask) is also called network mask, address mask, and subnet Mask, which is used to indicate which bits of an IP address identify the subnet where the host is located, and which bits identify the host's bit mask. The subnet mask cannot exist alone, it must be used in conjunction with the IP address.

The subnet mask is a 32-bit address that is used to mask a part of the IP address to distinguish the network identification and the host identification, and to indicate whether the IP address is on a LAN or a WAN.

Subnet mask is a virtual IP technology produced to solve the problem of IP address allocation under the background of shortage of IPv4 address resources. The three types of addresses A, B, and C are divided into several subnets through the subnet mask. , thus significantly improving the efficiency of IP address allocation and effectively solving the situation of tight IP address resources. On the other hand, in order to better manage the network in an enterprise's intranet, network administrators also use subnet masks to artificially divide a larger enterprise's internal network into more small-scale subnets, and then use The routing function of the three-layer switch realizes subnet interconnection, thereby effectively solving many network management problems such as network broadcast storms and network viruses.

In most network textbooks, the function of the subnet mask is generally described as dividing the IP address into a network identification (Net.ID) and a host identification (Host.ID) through logical operations. Only two hosts with the same network ID can communicate with each other without routing.

According to the definition of RFC950, a subnet mask is a 32-bit binary number in which all bits corresponding to the network address are set to 1 and all bits corresponding to the host address are set to 0. The subnet mask tells the router which part of the address is the network address and which part is the host address, allowing the router to correctly determine whether any IP address belongs to this network segment and thus perform routing correctly. On the network, data is transmitted from one place to another relying on IP addressing. Logically speaking, it is a two-step process. The first step is to find the network to which the host belongs from the IP, which is like finding which community this person belongs to; the second step is to find the location of the host in the network from the IP, which is like finding the person in the community.

The setting of subnet mask must follow certain rules. Like the binary IP address, the subnet mask consists of 1 and 0, and the 1 and 0 are consecutive. The length of the subnet mask is also 32 bits. The left side is the network bits, represented by the binary number "1", the number of 1s is equal to the length of the network bits; the right side is the host bits, represented by the binary number "0", the number of 0s is equal to the host bit length. The purpose of this is to use 0 to cover the original host number when performing a bitwise AND operation between the mask and the IP address without changing the original network segment number, and it is easy to determine the number of hosts in the subnet through the number of 0 bits (2 The host number is raised to the power of -2, because when the host number is all 1, it represents the broadcast address of the network, and when it is all 0, it represents the network number of the network. These are two special addresses). The subnet mask can indicate the relationship between the subnet where a host is located and other subnets, so that the network can work normally.

The function of subnet mask

A subnet mask is a 32-bit address, a technology used in conjunction with an IP address . It has two main functions. One is to shield part of the IP address to distinguish the network identification and the host identification, and to indicate whether the IP address is on the local area network or on the remote network. The second is used to divide a large IP network into several small sub-networks.

Using subnets is to reduce the waste of IP. Because with the development of the Internet, more and more networks are created, some with hundreds of networks, and some with only a few. This wastes a lot of IP addresses, so subnets must be divided. Using subnets can improve the efficiency of network applications.

The method to determine whether two computers belong to the same network segment through the computer's subnet mask is to convert the computer's decimal IP address and subnet mask into binary form, and then perform binary AND ) calculation (all 1s result in 1, incomplete 1s result in 0), if the results are the same, then the two computers belong to the same network segment.

Declare the network address and host address

The subnet mask must be used in conjunction with the IP address. Table 1 shows the binary and decimal correspondence between the default subnet masks of commonly used network Class A, B, and C IP addresses. The working process of the subnet mask is: perform a bitwise logical AND operation on the 32-bit subnet mask and the IP address in binary form to obtain the network address, and combine the binary non-result of the subnet mask with the IP address. The binary logical AND operation is performed, and the result obtained is the host address. For example: 192.168.10.11 AND 255.255.255.0, the result is 192.168.10.0, which means: the IP address belongs to the network 192.168.10.0, and its host number is 11, that is, the host number 11 in this network.

Dividing subnets

The subnet mask mechanism provides a method for subnet division. Its function is to: reduce the traffic on the network; save IP addresses; facilitate management; and solve certain problems of the physical network itself. After dividing subnets using subnet masks, communication can be achieved within the subnet, but communication across subnets cannot be achieved. Routers should be used for inter-subnet communication, and static routing information should be configured correctly. To divide subnets, you should follow the rules of subnet division structure. It is to use continuous 1 to increase the number of digits in the IP address to represent the network address, and at the same time reduce the number of digits to represent the host address. For example, the IP address is 130.39.37.100, the network address is 130.39.37.0, the subnet address is 130.39.37.0, the subnet mask is 255.255.255.0, the network address part and the subnet identification part correspond to "1", and the host identification part corresponds to "0". Using CIDR, it is expressed as: 130.39.37.100/24, which is the IP address/mask length. The 8-bit binary value corresponding to 255 on the third byte is the digits of the host address lent to the network address part, which serves as the number of digits to divide the subnet.

Example

1, 255.255.255.0

The subnet mask consists of consecutive 1 It is composed of 0 and 0. Consecutive 1 indicates the network address and continuous 0 indicates the host address. The capacity of the subnet can be calculated by the number of 0 (the IP address range of the host in the subnet). First, let’s take a look at how the default subnet mask 255.255.255.0 divides subnets. The binary number of this subnet mask consists of 24 1s and 8 0s. The 8 0s represent the subnets divided by the subnet mask. The subnet capacity is 256 (2 to the 8th power), which means that 192.168.1.0-255 are all in the same subnet. There are only 254 available addresses among these 256 addresses because the first IP address of each subnet is specified. is the network segment address, and the last IP address is the broadcast address, both of which are unavailable. For example: For the network segment 192.168.1.0, if the subnet mask is set to 255.255.255.0, 192.168.1.1-192.168.1.254 is the available IP address. If the IP address is set in this range, the computers can connect to each other normally.

What is subnet mask

2, 255.255.255.252

Of course, the above is the default situation and the simplest situation. Next we analyze how the subnet mask 255.255.255.252 divides subnets. Convert the subnet mask into binary into 30 1s and 2 0s, which means that there are only 4 IP addresses (2 to the power of 2) in each subnet. The address segment 192.168.1.0-255 can be divided into 64 subnets. , the address range of the first subnet is 192.168.1.0-192.168.1.3, the address range of the second subnet is 192.168.1.4-192.168.1.7, and so on. The first and last IP addresses of each subnet are unavailable, and only 2 IP addresses are available. That is to say: if the subnet mask is set to 255.255.255.252, then the subnet can only accommodate two computers, and the IPs of the two computers must be in the same subnet to connect normally. For example, the IP settings of one computer is 192.168.1.10, and the IP of the other computer must be set to 192.168.1.9.

What is subnet mask

Practical combat of subnet division

Through the above two examples, readers should understand the role of subnet mask. Here is a Practical examples test the learning results just now. A small company has four departments: administration, R&D, marketing, and after-sales. Each department has 40 computers connected to the company's LAN switch. If you want to divide subnets for each department on the 192.168.1.0 network segment, the subnet mask How should it be set, and what is the address range of each subnet?

The 192.168.1.0 network segment has a total of 256 addresses, divided into 4 subnets. Each subnet requires 64 addresses; 64 is 2 to the 6th power, and the subnet mask should end with 6 0s, leaving is completed with 1, consisting of 26 1's and 6 0's, converted to decimal is 255.255.255.192; each subnet has a total of 64 IP addresses, after trimming the beginning and ending, there are only 62 available addresses, and the first subnet is available The IP address range is: 192.168.1.1-62, the available IP address range of the second subnet is 192.168.1.65-126, the available IP address range of the third subnet is: 192.168.1.129-190, the available IP address of the fourth subnet The range is 192.168.1.193-254; the computers in each department of the company are set according to the IP address range in 3. The subnet masks of all computers must be set to 255.255.255.192. After the setting is completed, the computers in each department can network normally. Computers between different departments cannot be directly connected.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What is subnet mask. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn