Introduction to subnets and subnet masks

Source: Internet
Author: User

First, what is a subnet

The IP address consists of two parts, the network ID and the host ID. The network number identifies a subnet on the internet, and the host number identifies a host in the subnet. A subnet is a smaller network that is based on a particular type of address.

Second, why to divide the subnet

The Internet organization defines five IP addresses, with a, B, and C three addresses. A Class A network has 126, each class A network may have 16777214 hosts, they are in the same broadcast domain (broadcast domain refers to all the network can receive the same broadcast messages of the device collection). Obviously, there are so many nodes in the same broadcast domain is not possible, so there will be a lot of IP addresses are not allocated to cause waste. This allows a large IP network based on a class to be divided into smaller subnets. Just like our room divided into a lot of, because a very big big house put a bed that is very wasteful, divided into a lot of houses, we can live in many people, so that both save space, and give everyone privacy, everyone clean their room, also easy to manage.

Iii. What is a subnet mask

The subnet mask is a sign of the mesh, and the subnet mask can be used to determine whether it is in the same network. The subnet mask cannot exist alone, it must be used in conjunction with an IP address. The subnet mask has only one function, which is to divide an IP address into two parts: network address and host address. The subnet mask setting must follow certain rules. The same as the IP address, the length of the subnet mask is also 32 bits, the left is the network bit, with the binary number "1", the right is the host bit, the binary number "0" is represented. For example, the subnet mask is 255.255.255.0, converted to binary 11111111.11111111.11111111.00000000 "1" has 24, then the binary IP address from left to right 24 bits is the network number, the same network number is the same network segment. "0" has 8, then the binary IP address from the right to the left of the 8-bit is the host number, the network segment contains a maximum of 256-2 = 254 hosts, because the gateway and broadcast address is subtracted.

The relationship between subnet mask and subnet network

The IP address can be judged whether it belongs to the same subnet by comparing the subnet mask to the network address, and the subnet requires a subnet mask to divide the subnet, identifying the network address and the host number.

V. How subnets and subnet masks are divided

Subnetting is the use of taking the host bit, take this taken part as a sub-network bit. So this means that the more subnets are divided, the fewer hosts each subnet will hold.

The subnet mask is used to identify which part of the IP address is the network address, which part is the host address, which consists of 1 and 0, a length of 32 bits, and a total of 1 bits representing the network number. Not all networks require subnets, so introduce 1 concepts: Default subnet mask (defaults subnet mask). The default subnet mask for Class A IP addresses is 255.0.0.0; The Class B is 255.255.0.0; The Class C is 255.255.255.0.

The default subnet mask for Class A addresses, for example, 255.0.0.0:/8 represents the first 8 bits of the IP binary as the network address for Class A addresses, such as the subnet mask with IP address 12.0.0.2 as the default 125.0.0.0 then his network address is 12.0.0.0.

Class B Default Subnet mask 255.255.0.0/16,c class address the default subnet mask 255.255.255.0/24 is also the same.

Here's an example to help you understand the partitioning of subnets and subnet masks

Example one, if our school applied to a Class B address: 129.12.0.0/16. The number of hosts we have available is 2 of 16 -2=65534 (minus the broadcast address and gateway address).

Assuming we have 7 departments in our school, we need to divide 7 different subnets (assuming that the number of hosts in the 7 departments here is the same, and that the allocations are sufficient). Then the minimum value of the 2 N-th square >=7,n is 3. Therefore, the network bit needs to borrow 3 bits from the host bit. Then you can separate 8 subnets from the 129.12.0.0/16 network segment.

Detailed process:

First, the 129.12.0.0/16 is expressed in binary notation

10000001.00001010.00000000.00000000/16

After 4-bit borrowing (16 subnets can be divided)

1, 10000001.00001010. 00000.00000000/19 "192.12.0.0/19"

2, 10000001.00001010. 00100000.00000000/19 "192.12.32.0/19"

3, 10000001.00001010. 01000000.00000000/19 "192.12.64.0/19"

4, 10000001.00001010. 01100000.00000000/19 "192.12.96.0/19"

5, 10000001.00001010. 00000.00000000/19 "192.12.128.0/19"

6, 10000001.00001010. 10100000.00000000/19 "192.12.160.0/19"

7, 10000001.00001010. 00000.00000000/19 "192.12.192..0/19"

8, 10000001.00001010. 11100000.00000000/19 "192.12.224.0/19"

Select 7 from each department and assign one. The number of hosts available per department is:

2 of the 13-time Square 8192-2=8190.

Subnet mask calculation using subnet number

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.

There are 7 subnets divided.

Then 7=111

N=5

The subnet mask of Class B address 255.255.0.0 the host address of the first 3 position 1, get

11111111.11111111.11100000.00000000

The subnet mask is 255.255.224.0

This is the subnet mask for Class B IP address 168.195.0.0 that is divided into 27 subnets.

Compute the subnet mask using the number of hosts

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 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 to remove the reserved IP address (that is, the main camera or sub-network is divided into 0 or all "1"):

Introduction to subnets and subnet masks

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.