# IP address and subnet division

Source: Internet
Author: User

What is an IP address?

We know that the Internet is a general term for a communication network composed of computer connections all over the world. When two computers connected to a network communicate with each other, some additional information is contained in the packets transmitted by them, the additional information is the address of the computer that sends the data (source IP address) and the address of the computer that receives the data (destination IP address ).

For convenience of communication, every computer is allocated with an ID address similar to the phone number in our daily life. This ID address is what we call the I P address today. According to TCP/IP protocol, IP addresses are composed of 32-bit binary numbers and are unique over the Internet. For example, the IP address of a computer connected to the Inte network is:

11010010 01001001 1000110000000010

Obviously, these numbers are not very memorable. To make it easier to remember, people divide the 32-bit binary code that makes up the IP address of a computer into four segments (currently IPv4, IPv6 will take a long time, by the way, I mentioned ^_^ of IPv6 not mentioned above. Each segment has eight digits, which are separated by decimal points. Then, every eight digits are converted into decimal digits, in this way, the IP address of the above computer becomes 210.73.140.2.

We have said that the Internet is a large inter-network that connects countless networks around the world. Each computer in a network is uniquely identified by its own IP address, we can also imagine that each network also has its own identifier on the Internet in this large inter-network. This is very similar to the phone number in our daily life. For example, if a phone number is 0515163, the first four digits in the number indicate the region of the phone number, the following number indicates a telephone number in the region. Similar to the preceding example, we divide the IP address of a computer into two parts: the network ID and the host ID. All hosts on the same physical network use the same network ID. A host on the network (including Workstation, server, and router) has a host ID corresponding to it.

The four bytes of an IP address are divided into two parts. One part is used to indicate the specific network segment, that is, the network identifier; the other part is used to indicate the specific node, that is, the host identifier, that is, a specific computer number in a network. For example, the IP address of the server in Yancheng Information Network Center is 210.73.140.2. For this IP address, we can divide it into two parts: the network ID and the host ID, so that the above IP address can be written:

Network ID: 210.73.140.0

Host ID: 2

Write in combination: 210.73.140.2

Because there may be many computers in the Network, some networks may contain many computers, and some networks may contain fewer computers. Therefore, according to the size of the network, divide 32-bit address information into five positioning methods. Which of the five most commonly used methods are Class A, Class B, and class C. What about class D and Class E? Class D is called multicast addressing. It acts as a backup for transmitting multi-purpose information and is allocated to one or more network interfaces on different subnets. Class E is called a reserved address, it is only used for Internet testing and development. Next we will take a look at the first three types of IP addresses.

1): Class a ip Address

A Class a ip address refers to the network number of the first segment of the four segments of the IP address, and the remaining three segments are the numbers of the local computer. If an IP address is displayed in binary format, a Class a ip address consists of a 1-byte network address and a 3-byte host address. The maximum IP address must be 0 ". In Class a ip addresses, the network ID length is 7 bits, the host ID is 24 bits, and the number of class A network addresses is small. It can be used in large networks with hundreds of thousands of hosts.

2): Class B IP Address

A Class B ip address refers to the four segments of the IP address. The first two segments of the number are network numbers. The class B IP address consists of a 2-byte network address and a 2-byte host address, the maximum value of the network address must be "10 ". In a class B ip address, the network ID is 14 bits and the host ID is 16 bits. The class B network address is applicable to networks of medium scale and other scales, each network can accommodate more than 60 thousand computers.

3): Class c ip Address

A Class c ip address refers to the network number in the four segments of the IP address, and the remaining segment is the number of the local computer. If an IP address is displayed in binary format, the class c ip address consists of a 3-byte network address and a 1-byte host address. The maximum IP address must be 110 ". In a class c ip address, the network ID is 21 characters in length, the host ID is 8 characters in length, and the number of class C network addresses is large, which is suitable for small-scale local networks, each network can contain up to 254 computing machines.

1. network addressing rules

A. The network address must be unique.

B. The network ID cannot start with a number 127. In Class A addresses, the number 127 is reserved for the internal return function.

C. The first byte of the network logo cannot be 255. The number 255 is used as the broadcast address.

D. the first byte of the network ID cannot be "0". "0" indicates that the address is a local host and cannot be transferred.

2. Host addressing rules

A. The host ID must be unique in the same network.

B. each bit of the host ID cannot be "1". If all the bits are "1", the address of the host is the broadcast address, not the host address.

C. each bit of the host ID cannot be "0". If each bit is "0", it means "only this network", and there is no host on this network.

Concept and function of subnet mask

The subnet mask is a 32-bit binary value applied to TCP/IP networks. It can block part of an IP address and separate the network part from the host part. Based on the subnet mask, the administrator can further divide the network into several subnets.Why subnet mask?

Although we can say that the subnet mask can separate the network part and host part of the IP address, we still have questions. For example, why do we need to distinguish the network address from the host address? What will happen after the distinction? Well, let's talk about it in detail!

When two computers using the TCP/IP protocol communicate with each other, we perform the 'and' operation by comparing the subnet mask of the local computer with the IP address of the receiver's host, you can get the network number of the target host. Because each host is configured with a local IP address and subnet mask When configuring the TCP/IP protocol, you can know the network number of the host.

By comparing the two network numbers, you can know whether the receiver host is on the current network. If the network number is the same, it indicates that the receiver is on the current network, data packets can be directly sent to the target host through the relevant protocol. If the network number is different, it indicates that the target host is on the remote network, then the packet will be sent toRoutingRouter sends data packets to other networks until the destination is reached. In this process, you can see that the subnet mask is indispensable!

How to obtain the Network/Host address using the subnet mask

Since the subnet mask is so important, how does it separate the network address and host address in the IP address?

The process is as follows:

1. Convert the IP address and subnet mask to binary;

2. perform the "and" Operation on the IP address and subnet mask in the binary format, and convert the answer to the decimal format to get the network address;

3. Remove the subnet mask in binary form from the back ';

4. perform the "and" Operation on the subnet mask and IP address after the "inverse". Convert the answer to the decimal format to get the host address.

The following is an example:

Assume there is an I P address: 192.168.0.1

Converted to binary: I P address 111000000.10101000.20.0000.00000001

Perform the "and" Operation on the two: 11000000.10101000.00000000.00000000

Convert it to decimal: 192.168.0.0

This is the network address of the above IP address, host address, and so on.

Tip: as we observe that the subnet mask above is the default subnet mask of the class C address (I .e., the subnet is not divided), we can see that the network address is the first three parts of the IP address, that is, the first three bytes.

Q:

What? You still don't understand? Ask me why I want to perform the "and" operation instead of other operations? In fact, you should be able to understand the above example carefully.

'1' does not affect the result when performing the 'and' operation. '0' returns 0 when performing the 'and' operation, using this feature of 'and, when the administrator sets the subnet mask, the bits corresponding to the network address on the subnet mask are set to '1', And the other bits are set to '0 ', when it is treated as "and", the network number in the IP address will be retained into the result, and the host number will be set to 0. In this way, the network number will be parsed and the host number will be the same, you only need to first take the subnet mask as the 'back', while doing the 'and '.

1) default subnet mask:

That is, no subnet is divided. The bits of the corresponding network number are set to 1, and the host number is set to 0.

Default subnet mask of Class A network: 255.0.0.0

Default subnet mask of type B network: 255.255.0.0

Default subnet mask for Class C networks: 255.255.255.0

2) custom subnet mask:

Dividing a network into several subnets requires different network numbers or subnet numbers for each segment. In fact, we can think of host numbers as two parts: Subnet numbers and subnet host numbers. The format is as follows:

IP addresses not divided by subnets: network number + host number

IP address after subnet division: network number + subnet host number

That is to say, after the IP address is divided into subnets, part of the previous host number is assigned to the subnet number, and the rest is the subnet host number.

The previous sections introduce some knowledge about subnet masks. Let's take a look at subnet division. Do not think that subnet division has nothing to do with subnet masks. subnet division also relies on subnet masks.

A subnet is a logical network generated on an IP address. It allows a network address to span multiple physical networks, that is, a network address represents multiple networks (obviously this can save IP addresses ). Oh, does it sound strange? How can a network be divided into many subnets inexplicably? So what is the purpose of doing so?

Let me give you an example: for example, if you are a network administrator of a school, your school has four network classrooms in different physical locations, each of which has 25 machines, your task is to configure IP addresses and subnet masks for these machines. You may think this is simple. Apply for four class C addresses, one for each classroom, and then configure them one by one. Well, this is true in theory, but have you ever thought it would be a waste? You have wasted a total of (254-25) x 4 = 916 IP addresses, if all network administrators do this, the IP addresses on the Internet will be exhausted in a very short period of time. Obviously, you cannot do this. You should divide subnets.

The subnet division is like this: because after the subnet is divided, the network number of the IP address remains unchangedLanExternally, there is still only one network, that is, the network represented by the network number. However, there is another scene inside the network, because the subnet numbers of each of our subnets are different, use the IP address and subnet mask after dividing the subnet (note that the subnet mask here is not the default subnet mask, but the custom subnet mask, which is calculated by the Administrator) when performing the "and" operation, each subnet will get a different subnet address, thus realizing the division of the network (with a different address, of course, it will be able to differentiate each subnet, interesting ).

Subnet addressing technology, I .e., subnet partitioning, helps solve the following problems:

1) huge network address management costs: if you are a class a network administrator, you will surely have a headache in managing a large number of hosts;

2) sharp expansion of the routing table in the vro: When the vro and other vrouters exchange the routing table, the Internet load is very high and the calculation required is also high;

3) Limited IP address space and eventually depletion: this is a crucial issue. The rapid development of the Internet makes the original addressing method unable to adapt, but some IP addresses cannot be fully utilized, this results in waste.

Therefore, it is important and sometimes necessary to divide subnets as needed when configuring a LAN or other networks. Currently, subnet addressing technology has been used by most local networks.

How to divide subnets and determine subnet masks

Before division, you must consider the current network requirements and future demand plans.

Subnetworks are divided mainly from the following aspects:

1. Number of physical segments in the network (that is, the number of subnets to be divided)

2. Number of hosts in each physical segment

To determine the subnet mask:

Step 1: determine the number of physical network segments, convert the number to the binary number, and determine the number of digits n. For example, if you need 6 subnets, the binary value of 6 is 110, and there are 3 digits in total, that is, n = 3;

Step 2: write out the default subnet mask based on your IP address type. For example, Class C, the default subnet mask is 11111111.111111.111111.00000000;

Step 3: Set the positions in the subnet mask corresponding to the first n digits of the host number to 1, and the remaining positions to 0. If n = 3 and

Class C address: The obtained subnet mask is 1111111111.111111.111111.11100000, which is in decimal format.

Class B address: The obtained subnet mask is 11111111.111111.112.160.00000000, which is converted into decimal format to obtain 255.255.224.0.

Class A address: The obtained subnet mask is 11111111.112.160.20.0000.00000000, which is converted into decimal format to get 255.224.0.0.

In addition, because the network is divided into six subnets, it occupies the first three digits of the host number. If it is a class C address, the host number can only be expressed as five digits, therefore, the number of hosts in each subnet = (5 to the power of 2)-2 = 30, the total number of hosts identified by the six subnets will be less than 254. Please note that!

Q:

1. you may have such questions. For example, in the above example, the binary value of 6 is 110, so why do we need to set the positions corresponding to the first n digits of the host number in the subnet mask to 1, instead of replacing the first n digits with the binary 110 of 6?

The answer is: What is the purpose of the subnet mask calculation? It is hoped that it will be able to parse the network number when doing "and, that is to say, the location corresponding to the network number should be 1 (of course, including the location corresponding to the subnet number). Obviously, it is wrong to write 110, if you write this statement, it means that the first two digits of the host number are used as the subnet number. In this way, a maximum of two subnets can be divided, the following describes how to calculate the number of subnets). It is obviously different from the six subnets we originally divided. In this way, you can understand white horse?

2. Careful people may find that the subnet mask is the same for dividing 4 subnets, 5 subnets and 6 subnets, and the same as the subnet mask, is it wrong? Should the three subnet masks be different? Well, this is the case. Because the binary values of and 6 are 3, the three digits in the subnet mask are set to 1, so there is no problem with the Division, it's just a small problem in your understanding. If you divide it into four subnets, you can actually divide it into six subnets, but you only use four of them. For example, if you want to divide 8 subnets, The subnet mask is the same as that obtained by dividing 14 subnets, and all of them occupy 4 digits as the subnet number.

Related judgment methods

1) How can I determine whether a subnet is divided?

This problem is very simple. If it uses the default subnet mask, it indicates that no subnet is divided. Otherwise, it must be divided.

2) How do I calculate the subnet address?

The old method is to combine the IP address and subnet mask in binary form, and the result is the subnet address.

3) How do I calculate the host address?

Let alone this. First, take the binary of the subnet mask as an 'back' and then use the IP address as an 'and '.

4) How do I calculate the number of subnets?

We often mention this issue, starting with the subnet mask, there are two main steps:

1. Observe the binary form of the subnet mask and determine the number of digits N as the subnet number;

2. The number of subnets is 2 to the Npower-2. (Why do I subtract 2)

For example, if there is such a subnet mask: the binary value of the subnet mask is:

11111111.11111111.1111111111.11100000 the three times of N = 3 and 2 are 8, indicating that the subnet address may have

The following eight cases:

000

001

010

011

100

101

110

111

However, it represents the network's 000; it represents that the broadcast address's 111 is retained, so it needs to be reduced by 2. Do you understand?

5) How do I calculate the total number of hosts and the number of hosts in the subnet?

Total number of hosts = number of subnets X number of hosts in the subnet

The following example shows how to use a subnet mask:

The above discussion knows that it can be divided into a maximum of six subnets. How many hosts can there be in each subnet? In fact, I have already calculated for you. Because the network is divided into six subnets, it occupies the first three digits of the host number and is a class C address, the host number can only be expressed as a host number of five digits. Therefore, the number of hosts in the subnet is equal to (Power 5 of 2)-2 = 30.

Therefore, we can use this subnet mask to calculate that this network can identify a maximum of 6*30 = 180 hosts (as shown in the following figure, after dividing the subnet, the number of hosts that the entire network can identify will be reduced ).

6) Calculate the IP address range

With a custom subnet mask, we can obtain all possible IP address ranges of the network.

Procedure:

1. Write out the binary subnet address;

2. Convert the subnet address into decimal;

3. Calculate the number of hosts that the subnet can accommodate;

4. Obtain the IP address range (Starting address: Subnet address + 1; ending address: Subnet address + number of hosts)

Assume that a subnet mask is too many hosts. We can see that it can be divided into a maximum of six subnets and the number of hosts in the subnet is 30. All possible IP addresses and the calculation process are as follows:

Subnet -- subnet address (Binary) -------- subnet address ----- actual IP address range

1-11001010.0112.16.20.1010.00100000-202.112.10.32-202.112.10.33-202.112.10.62

2-11001010.0112.16.20.1010.0000000-202.112.10.64-202.112.10.65-202.112.10.943-region-202.112.10.96-202.112.10.97-202.112.10.126

-11001010.0112.16.20.1010.0000000-202.112.10.128-202.112.10.129-202.112.10.158

-11001010.0112.16.20.1010.10100000-202.112.10.160-202.112.10.161-202.112.10.190

-11001010.0112.16.20.1010.11000000-202.112.10.192-202.112.10.193-202.112.10.222

Related Keywords:

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.