About us

Quality oriented, customer-oriented, hardworking, pragmatic and innovative

<Return to the public list of news

How to determine whether two IP addresses are in the same network segment? What is a subnet mask?

Release time: 09:38:35, September 3, 2019

Many friends have a situation that they know how to allocate IP addresses for a small number of points. For projects with many points, the allocation of IP addresses is prone to errors. This is due to the lack of basic understanding of IP addresses. Let's take a look today.

1、 Ip address

IP addresses are used to number computers on the Internet. It is common to see that every networked PC needs an IP address for normal communication. We can compare "personal computer" to "a telephone", then "IP address" is equivalent to "telephone number", and the router in the Internet is equivalent to "program-controlled switch" of the telecommunications office.  


IP address is a 32-bit binary number, which is usually divided into four "8-bit binary numbers" (that is, four bytes).

 640.webp.jpg

Of course, there are some special features For different types of IP, Class D starts with 1110 for multicast, and Class E starts with 11110 for scientific research reservation.

2、 Subnet mask

Subnet mask is also called network mask and address mask. It is used to indicate which ID bits of an IP address are the subnet of the host, that is, the network ID part, and which ID bits are the mask of the host, that is, the host ID part. In fact, the IP address is divided into network address and host address. For example. For Class C IP, its subnet mask is 255.255.255.0. The first three bytes are network bits, and the last byte is host bits.


3、 Gateway

As we all know, you have to go through a door to go from one room to another. Similarly, when sending information from one network to another, it also needs to go through a "gateway", that is, a gateway, which is a network gateway from one network to another.


Gateway is also called the connector between networks, protocol converter. The default gateway implements network interconnection at the network layer. It is the most complex network interconnection device and is only used for network interconnection with two different high-level protocols. The gateway can be used for both WAN interconnection and LAN interconnection. The gateway is actually the IP address from one network to another, that is, the "gateway". For example, there is a case where the IP address range of one network A is "192.168.5.1-192.168.5.255" and the other network is "192.168.10.1-192.168.10.255". The two networks are not in the same subnet. If there is no router, the two networks cannot communicate. To achieve communication between networks, it must be achieved through the gateway. The general process is as follows: if the host in network A sends information to the host in network B, it will forward the data packet to its own gateway, and then the gateway in network B will send it to the gateway in network B, and then the gateway in network B will forward it to a host in network B.


Therefore, only by setting the IP address of the gateway, can TCP/IP protocol achieve mutual communication between different networks. What is the IP address of the machine? The IP address of the gateway is the IP address of the device with routing function. The device with routing function is a router, a server with routing protocol enabled (essentially equivalent to a router), and a proxy server (also equivalent to a router).


4、 Broadcast address

Broadcast address, as the name implies, is an address sent to all workstations around.


What is the broadcast address? In fact, the broadcast address sets the host identification segment in the IP address to all 1. For example, for the 192.168.1.0 network, its broadcast address is 192.168.1.255 (255 is binary 11111111). When a 192.168.1.255 packet is sent, it will be distributed to all computers on the network segment.


5、 Solution of network address

Network address is an operation between binary systems. You need to know the IP address and subnet mask, and then get their binary systems. The binary systems of the IP address and subnet mask are combined to obtain the network address (all host bits are 0).

For example, The IP address of a host is 202.112.14.137, and the subnet mask is 255.255.255.224. Find the network address

IP address&subnet mask

 640.webp (1).jpg

Convert the obtained IP to decimal, that is, 202.112.14.128.


Plan the subnet address and calculate the subnet mask according to the number of hosts in each network

This can also be calculated according to the above principles.

For example, if a subnet has 10 hosts, the IP address required for this subnet is

10+1+1+1=13 

Note: The first one added refers to the gateway address required for this network connection, and the next two ones refer to the network address and broadcast address respectively.  


Because 13 is less than 16 (16 is equal to the 4th power of 2), the host bit is 4 bits.


And 256 - 16=240, so the subnet mask is 255.255.255.240.


If there are 14 hosts in a subnet, many people often make the mistake of still allocating a subnet with 16 address spaces and forgetting to assign an address to the gateway. This is wrong because:

14+1+1+1=17 

17. It is greater than 16, so we can only allocate subnets with 32 addresses (32 is equal to the 5th power of 2). The subnet mask is 255.255.255.224


206 110 40/18 is divided into 16 subnets, each with a subnet mask of?

(It is divided into 16 subnets. According to the subnet mask/18, there are 18 ones. You need to borrow 4 bits from the host bit of the IP address to use as network bits!)


The subnet mask is 255.255.252.0


Each subnet can accommodate 1024 hosts.


The following detailed answers:

206.1110.1.0/18 From the last/18, we can know that the IP has specified its network bit as 18 bits, and its default subnet mask is 11111111.11111111.11 | 00000000000000 (where 1 represents the network bit and 0 represents the host bit)


It can be seen that the number of bits we can operate on is the next 14 zeros, that is, we can divide several bits on the ground as the network bits of the subnet, and then divide the subnet. The requirement is to divide the subnet into 16 subnets. We know that the fourth power of 2 is exactly 16, which means that the number of bits in the subnet network is 4, and 14-4=10 is the host bit of the subnet. So the string of binary I wrote above can become: 11111111.11111111.111111 | 00.00000000 (where 1 represents the network bit and 0 represents the host bit)


6、 IP segment/number - for example, 192.168.0.1/24?


IP segment/number - for example, 192.168.0.1/24?

The following number indicates the number of bits of our network number, that is, the first number in the subnet mask is 1


129.168.1.1/24 This 24 tells us that the network number is 24 digits


It is equivalent to telling us


The subnet mask is: 11111111 11111111 11111111 00000000


Namely: 255.255.255.0


/27 of 172.16.10.33/27


That is to say, the subnet mask is 255.255.255.224, that is, 27 all 1


11111111 11111111 11111111 11100000



/template/Home/Zkeys/PC/Static