Learning Tips 1: how to calculate the subnet mask

Source: Internet
Author: User

The subnet mask is used to determine whether the IP addresses of any two computers belong to the same subnetwork. the simplest understanding is that after the IP address and subnet mask of the two computers perform the and operation, if the result is the same, the two computers are on the same sub-network and can communicate directly.
Computing Demonstration:

IP address 192.168.0.1
Subnet Mask 255.255.255.0

Convert to binary for calculation:

IP address 1102.16.10101000.00000000.00000001
Subnet Mask 11111111.111111.1111111111.00000000

And Operation

111000000.10101000.00000000.00000000

Converted to decimal:

192.168.0.0

Operation demonstration 2:

IP address 192.168.0.254
Subnet Mask 255.255.255.0

Convert to binary for calculation:

IP address 1102.16.10101000.20.2.16.11111110
Subnet Mask 11111111.111111.1111111111.00000000

And Operation

111000000.10101000.00000000.00000000

Converted to decimal:

192.168.0.0

Computing demonstration 3:

IP address 192.168.0.4 subnet mask 255.255.255.0

Convert to binary for calculation:

IP address 1102.16.10101000.00000000.00000100
Subnet Mask 11111111.111111.1111111111.00000000

And Operation

111000000.10101000.00000000.00000000

Converted to decimal: 192.168.0.0
After the and operation on the IP addresses and subnet masks of the three groups of computers, we can see that the operation results are the same. All are 192.168.0.0, so the computers will regard the three computers as the same sub-network and then communicate with each other.
Maybe you have to ask, how many IP addresses are available for such subnet masks? You can calculate this.
According to the above, we can see that the IP address of the local area network is defined by ourselves (of course, it is the same as other IP addresses). This is determined by the subnet mask through the analysis of 255.255.255.0. It can be concluded that:
The first three IP addresses can only be fixed to 192.168.0, so only the last one is left. Obviously, an IP Address can only have (Power 8-1 of 2), that is, 256-1 = 255. Generally, the last digit is 0 or 255.
So you may ask: what if my subnet mask is not 255.255.255.0? You can also do this. If your subnet mask is 255.255.128.0, the first two IP addresses in your lan must be fixed. (what, why is it fixed? Do you understand the above ?)
In this way, you can follow the calculation below to see how many machines can be deployed in the same sub-network.
1. Decimal 128 = binary 1000 0000
2. the IP address and subnet mask must be used for and operations.
3. IP address 0001000000001001.1 *******.********
Subnet Mask 11111111.111111.0000000.00000000 and computation 000000000001001.0000000.00000000 is converted to the following decimal format: 16.73.128.0

4. We can see that the available IP addresses on the Intranet are:

000000000001001001.0000000.00000000

To

0001000000001001001.11111111.111111

5. Convert to decimal:

16.73.128.0 to 16.73.20.255

6. 0 and 255 are generally used internally for special purposes. Usually not used.

7. The final result is as follows: all available IP addresses in our unit are:

192.168.128.1-192.168.128.254
192.168.129.1-192.168.129.254
192.168.130.1-192.168.130.254
192.168.131.1-192.168.131.254
.............
192.168.139.1-192.168.139.254
192.168.140.1-192.168.140.254
192.168.141.1-192.168.141.254
192.168.142.1-192.168.142.254
192.168.143.1-192.168.143.254
.............
192.168.254.1-192.168.254.254
192.168.255.1-192.168.255.254

8. The total number is (255-128 + 1) * (254-1 + 1) = 128*254 = 32512

I. Use the sub-network data for Computation

Step 3:
1. Merge the sub-network into a binary representation
2. Obtain the Second-in-number n
3. Set the first n locations 1 in the host address section of 255.255.0.0 to 255.255.262.0, which is the subnet mask of the IP addresses divided into N subnets.

Example: Class B IP address 168.195.0.0 is divided into 50 subnetworks
50 = 110010
N = 6
Take the first six locations 1 of the host address segment of 255.255.0.0, and obtain 255.255.262.0, which is the subnet mask of the Class B IP address divided into 50 subnets.

Ii. calculation using the host machine data

Step 3:
1. Convert the host data into binary representation
2. If the host number is smaller than or equal to 254 (note that the reserved two IP addresses are removed), the binary number of the host is obtained. The value is N. N <8. If the host address is greater than 254, N> 8 means that the host address occupies more than 8 digits.
3. Use 255.255.255.255 to set the number of host addresses of this type of IP address to 1, and then set all the N digits to 0 from the forward, that is, the subnet mask value.

Example: Class B IP address 168.195.0.0 is divided into several sub-networks with 700 hosts in each Subnet
700 = 1010111100
The binary number is ten digits, n = 10 (1001)
Set all the host addresses of the subnet mask 255.255.0.0 of the B-type address to 1, get 255.255.255.255.255, and then forward the last 10 positions to 0, that is, 11111111.111111.111100.00000000, that is, 255.255.255.252.0. This is the subnet mask of the Class B IP address 168.195.0.0 to be divided into 700 hosts.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.