Calculation of the subnet mask

Source: Internet
Author: User

The IP address is a 32-bit binary value that marks the address of each computer in the TCP/IP communication protocol. Usually we use dotted decimal notation, such as 192.168.0.5 and so on.
Each IP address can be divided into two parts. That is, the network number section and the Host number section: The network number represents the network segment number to which it belongs, and the host number represents the address number of the host in that segment.
According to the size of the network, IP address can be divided into a, B, C, D, e five categories, where a, B, C is three major types of address, class D for multi-purpose transmission of multi-address,
Class E is used to extend an alternate address. The valid range of IP addresses for A, B, and C three is the following table:

Category network number/placeholder host number/number of placeholder uses
A 1~126/8 0~255 0~255 1~254/24 National
B 128~191 0~255/16 0~255 1~254/16 across the organization
C 192~223 0~255 0~255/24 1~254/8 Enterprise Organization

With the continuous expansion of the interconnection network application, the shortcomings of the original IPv4 are gradually exposed, that is, the network number occupies too much, and the host number is too small,
So the host address that it can provide is also becoming scarce, currently in addition to using NAT within the enterprise to use reserved address self-distribution,
Typically, a high-class IP address is re-partitioned to form multiple subnets for use by user groups of different sizes.
The main purpose here is to use the IP address effectively in the network segmentation case, by taking the high part of the host number as the subnet number,
Extend or compress the subnet mask from the usual network bit boundaries to create more subnets for a class of addresses. But when you create more subnets,
The number of available host addresses on each subnet will be less than the original.
The subnet mask is a 32-bit binary address that flags whether two IP addresses belong to a subnet, and each of the 1 represents the bit as a network bit,
0 represents the host bit. It is also represented as an IP address using dotted decimal. If the two IP addresses have the same results as the bitwise AND of the subnet mask,
That means they belong together in the same subnet.
When calculating the subnet mask, we should pay attention to the reserved address in the IP address, namely "0" address and broadcast address,
They refer to the IP address of the host address or the network address is all "0" or "1", they represent the network address and broadcast address, generally cannot be counted.

The following is an example of an algorithm that illustrates the subnet mask:
For IP addresses that do not have to be partitioned into subnets, their subnet masks are simple enough to be written according to their definition: If a class B IP address is 10.12.3.0, no more subnets need to be split,
The subnet mask for the IP address is 255.255.0.0. If it is a Class C address, its subnet mask is 255.255.255.0. Other analogies are no longer detailed.
The following is the key to the introduction of an IP address, but also need to its high-level host location as a partition of the subnet network number, the remaining is the host number of each subnet,
This is how to perform a mask calculation for each subnet.
First, use the number of subnets to calculate
Before you can find the subnet mask, you must first understand the number of subnets to divide, and the number of required hosts within each subnet.
1) Convert the number of subnets to binary to represent
2) The number of bits obtained for the binary, N
3) Obtain the class subnet mask of the IP address, the first n position of its host address Part 1 that is the subnet mask of the IP address subnetting subnet.
To divide a class B IP address 168.195.0.0 into 27 subnets:
1) 27=11011
2) The binary is a five-digit number, N = 5
3) The subnet mask of Class B address 255.255.0.0 the host address of the first 5 position 1, get 255.255.248.0
This is the subnet mask for Class B IP address 168.195.0.0 that is divided into 27 subnets.
Second, the use of the host number to calculate
1) Convert the number of hosts into binary to represent
2) If the host number is less than or equal to 254 (pay attention to remove the reserved two IP addresses), then obtain the host's bits number, is N, here certainly 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 the number of host address bits for that IP address to 1, and then set all n bits to 0 from the back forward, which is the subnet mask value.
If you want to divide Class B IP address 168.195.0.0 into several subnets, there are 700 hosts in each subnet:
1) 700=1010111100
2) The binary is a 10-digit number, N = 10
3) Set the subnet mask of the Class B address to the host address of 255.255.0.0 1, get 255.255.255.255
And then from the back forward will be 10 position 0, that is: 11111111.11111111.11111100.00000000
That is 255.255.252.0. This is the subnet mask that you want to divide into class B IP address 168.195.0.0, which hosts 700 units.
The following is a list of all types of IP addresses can be divided into all subnets, the division of the host and subnet placeholder, and the number of hosts and subnets (maximum),
Note that you want to remove the reserved IP address (that is, the primary or sub-subnet is all "0" or "1" after partitioning):
Class A IP address:
Subnet bit/host seat netmask subnet maximum number/host maximum number
2/22 255.192.0.0 2/4194302
3/21 255.224.0.0 6/2097150
4/20 255.240.0.0 14/1048574
5/19 255.248.0.0 30/524286
6/18 255.252.0.0 62/262142
7/17 255.254.0.0 126/131070
8/16 255.255.0.0 254/65536
9/15 255.255.128.0 510/32766
10/14 255.255.192.0 1022/16382
11/13 255.255.224.0 2046/8190
12/12 255.255.240.0 4094/4094
13/11 255.255.248.0 8190/2046
14/10 255.255.252.0 16382/1022
15/9 255.255.254.0 32766/510
16/8 255.255.255.0 65536/254
17/7 255.255.255.128 131070/126
18/6 255.255.255.192 262142/62
19/5 255.255.255.224 524286/30
20/4 255.255.255.240 1048574/14
21/3 255.255.255.248 2097150/6
22/2 255.255.255.252 4194302/2
Class B IP Address:
Subnet bit/host seat netmask subnet maximum number/host maximum number
2/14 255.255.192.0 2/16382
3/13 255.255.224.0 6/8190
4/12 255.255.240.0 14/4094
5/11 255.255.248.0 30/2046
6/10 255.255.252.0 62/1022
7/9 255.255.254.0 126/510
8/8 255.255.255.0 254/254
9/7 255.255.255.128 510/126
10/6 255.255.255.192 1022/62
11/5 255.255.255.224 2046/30
12/4 255.255.255.240 4094/14
13/3 255.255.255.248 8190/6
14/2 255.255.255.252 16382/2
Class C IP Address:
Subnet bit/host seat netmask subnet maximum number/host maximum number
2/6 255.255.255.192 2/62
3/5 255.255.255.224 6/30
4/4 255.255.255.240 14/14
5/3 255.255.255.248 30/6
6/2 255.255.255.252 62/2

Then according to the CCNA will appear in the topic to give you an example:

First, we look at a common test question: the IP address of a host is 202.112.14.137, the mask is 255.255.255.224,
The network address and broadcast address of the network to which this host is located is required.

The general method is to convert the host address and subnet mask into binary number, both logic and operation can get network address.
In fact, as long as you think carefully, you can get another way: The 255.255.255.224 mask contains 256-224 = 32 IP addresses (including network address and broadcast address),
Then the network address with this mask must be a multiple of 32. And the network address is the beginning of the subnet IP address, the broadcast address is the end, the host address can be used within this range,
So slightly less than 137 and a multiple of 32 is only 128, so the network address is 202.112.14.128. The broadcast address is the network address of the next network minus 1.
And the next 32 is a multiple of 160, so you can get a broadcast address of 202.112.14.159. You can refer to the following table to understand this example.

Number of sub-Network 2 sub-network Domains 2 domain number of host domains 2 range of number of inbound host domains
1th Sub-network 00000 thru 11111.0 thru.31
2nd Sub-network 001 00000 thru 11111. thru.63
3rd Sub-network 010 00000 thru 11111. x thru.95
4th Sub-network 011 00000 thru 11111. thru.127
5th Sub-Network of 00000 thru 11111. thru.159
6th Sub-network 101 00000 thru 11111. thru.191
7th Sub-network 00000 thru 11111.192 thru.223
8th Sub-network 111 00000 thru 11111 124 thru.255

CCNA Exam, there is also a type of question, you want to base on the number of hosts per network subnet address planning and computing subnet mask.
This can also be calculated in accordance with 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 1 plus refers to the gateway address required for this network connection, and the next two 1 refer to the network address and broadcast address respectively.
Because 13 is less than 16 (16 equals 2 of 4), the host bit is 4 bits. and

256-16=240

So the subnet mask is 255.255.255.240.

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

14+1+1+1=17

17 is greater than 16, so we can only allocate subnets with 32 addresses (32 equals 2 of the 5-square) space. At this point the subnet mask is: 255.255.255.224.

Calculation of the subnet mask

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.