October 11, 2023

Firstly, it doesn't matter if IP is class A, class B, or class C. Which IP class is irrelevant to problem, because in many cases a class B mask and a class A or class C network appear together, do not think that this is a mistake, this is often how question is written.

Secondly, you must master following knowledge:

1. Define meaning of word "subnet":

A subnet is designed to divide a large network into multiple smaller networks, each with same number of IP addresses. This small network is called a subnet of this large network. A large network can be a large class A network (class A network), a large class B network, or a large class C network.

(1) Binary to decimal conversion

(By way, here is binary to decimal conversion problem:

When an IP address is not used, BCD uses "addition of small powers" method, but when an IP address is used (except when calculating broadcast address, "broadcast address" is still used when calculating broadcast address. This method cannot be used to convert binary to decimal, but method 2 to Nth power is used to convert directly:

For example, when IP address calculation is not used, binary number 111 is converted to decimal, using method (2 to 2nd power + 2 to 1st power + 2 to 0th power, that is, 4+2 +1), result is 7 in decimal. However, this method cannot be used to convert binary to decimal when calculating IP addresses. When converting binary number 111 to decimal, if there are multiple ones, it is expressed as a power of 2. Here, three ones are 2. to 3rd power, then there is when calculating IP address, conversion of binary number 111 to decimal is 2 to 3rd power, and result of 2 to 3rd power is 8. )

⑵, total network quantity and available quantity

The number of class A networks is 2 to seventh power, that is 128. According to network specification, first and last of 128 must be removed, so number of usable class A networks is 126.

The number of class B networks is 2 to 14th power, which is 16,384. According to network specification, first and last of 16384 must be removed, so number of available class B networks is 16382.

The number of class C networks is 2 to power of 21, which is 2,097,152. According to network specification, first and last of 16384 must be removed, so number of available class C networks is 2,097,150.

⑶, total number of IP addresses in network and number of available IP addresses

Each major class A network (class A network) supports 2 IP addresses to power of 24, that is 16777216 IP addresses; each major class B network supports 2 IP addresses to power of 16, namely 65536 IP addresses; each Class C network supports 2 IP addressessa to 8th power, that is, 256 IP addresses. The number of available IP addresses is obtained by subtracting 2 from total number of IP addresses.

If a large class B network is divided into 32 small networks, then number of IP addresses of each small network will be 65536/32=2048; if a large class C network is divided into 32 small networks, then each small network The number of IP addresses in network is 256/32=8.

The function of mask is to tell computer how many "small networks" to divide "big network" into! Many books say that mask is used to determine number of network an IP address is on and to evaluate another IP address if it is on same subnet as current IP address. This is also true, but for us to do task, it doesn't make much sense. We must be clear: function of mask is to tell computer how many "small networks" to divide "big network" into! The mask is basis for determining number of subnets!

Third, clarify conversion of decimal numbers to 8-bit binary numbers

To answer these questions, you must be able to mentally convert decimal numbers within 255 to corresponding binary numbers. You can refer to this table of formulas (first line is binary, second line is decimal):

1 1 1 1 1 1 1 1

128 64 32 16 8 4 2 1

You can see:

The first binary 1 from left in first line corresponds to decimal 128

The second 1 from left in first line is 64 in decimal

The third 1 from left in first line is 32 in decimal

The fourth 1 from left in first line is 16 in decimal

The fifth 1 from left in first line corresponds to decimal 8

The sixth 1 from left in first line corresponds to decimal 4

The seventh digit 1 from left in first line corresponds to decimal digit 2

The 8th 1 from left in first line corresponds to decimal 1

The above relationships should be remembered, this is basis of basic conversion!

For example, converting decimal number 133 to binary can be represented as follows: since numbers 133 and 128 are relatively close, and first binary unit on left in formula table is number 128, you can immediately convert it. to an 8-bit binary file The leftmost bit is determined and set to 1. Next, we see that difference between 133 and 128 is only 5, and 5 is sum of 4 and 1, and 4 and 1 correspond to 6th and 8th digits on left in formula table, so decimal number 133 is converted to 8-bit binary Representation 10000101, which corresponds to following:

1 0 0 0 0 1 0 1 (133 in binary)

128 0 0 0 0 4 0 1 (133 decimal)

A method for converting other decimal numbers within 255 to 8-bit binary numbers can be deduced by analogy.

Fourthly, be aware of default masks fornetwork

The default Class A network mask is 255.0.0.0, converted to binary 11111111.00000000.00000000.00000000 The default mask means that a large Class A network (Class A network) is not divided into multiple smaller networks. The 1 in mask indicates network number, and 24 0 indicate that when network number is defined (the left 8 bits of an IP address expressed in binary are fixed), host number part of IP address is a 24-bit binary number. (An IP address consists of two parts: network number + host number)

The default Class B network mask is 255.255.0.0, converted to binary 11111111.11111111.00000000.00000000 The default mask means that a large Class B network is not split into multiple smaller networks. The 16 zeros indicate that when network number is defined (the left 16 bits of an IP address expressed in binary are fixed), 16-bit binary numbers can be used to represent host number part of IP address. (The default class B mask can be understood as dividing a large class A network (class A networks) into 2 small networks to power of 8 (i.e. 256)).

The default Class C network mask is 255.255.255.0, converted to binary 11111111.11111111.11111111.00000000 The default mask means that a large Class C network is not divided into multiple smaller networks. 8 0 here indicate that when network number is defined (the left 24 bits of an IP address expressed in binary are fixed), an 8-bit binary number can be used to represent host portion of IP address. (The default class C mask can be understood as dividing a large class A network (class A network) by 2 to 16th power (i.e. 65536) of small networks, which means dividing a large class B network by 2 to 8th degrees.(i.e. 256) small networks)

5. As for correct and effective mask:

A correct and effective mask must satisfy certain conditions, i.e. after converting decimal mask to binary, left side of mask must be completely equal to 1, and there must not be 0 in middle. For example, 255.255.248.0

The conversion to binary is 11111111.11111111.11111000.00000000. You can see that there are all 1s on left and no 0s in middle of 1 (0 is to right of 1), which is an effective mask. Let's look again at 254.255.248.0 converted to binary 11111110.11111111.11111000.00000000, this is an incorrect and effective mask because there is a 0 in middle of 1. look again at 255.255.249.0 converted to binary 11111111. 11111111.11111001.00000000 , which is not a valid and efficient mask because there is a 0 in middle of 1.

In some themes, instead of a subnet mask such as 255.255.248.0, it is displayed as an IP address/number, where /number is an alternate representation of subnet mask. When executing questions, we must correctly understand this alternative notation.The form we convert 255.255.248.0 to binary is 11111111.11111111.11111000.00000000, we see that there are 21 ones on left, so we can represent mask of 255.255.248.0 as /21. Conversely, when we see /21, we fill in 21 1s from left side of 32-bit binary number, separate each 8-bit part of 32-bit binary number with a dot, and then convert it to decimal, which is 255.255.248.0 up.

7. Two IP addresses are not available on network:

You can think of it like this: when a Class C network is not subnetted, two IP addresses are not available; now that class C network is divided into 4 subnets, there are 2 IP addresses in each subnet. So 8 IPs in 4 subnets are unreachable, and 8 IPs are used to subtract 2 unreachable IPs when subnet is not split, resulting in 6. Therefore, after dividing a class C network into 4 subnets, there will still be 6 unused IP addresses.

8. Determine number of subnets by mask

First of all, look at which default mask mask in question refers to, so we can know if we should subnet into large Class A, Class B, or Class C networks. For example, 202.117.12.36/30, we first Let's convert alternative mask notation /30 to our usual notation: 11111111.11111111.11111111.11111100, converted to decimal is 255.255.255.252.

Nine detailed examples:

Known 172.31.128.255/18, try calculating:

1. Number of subnets,

2. Network number,

3. Host number,

5. Start and end range of assigned IP addresses

Solution:

1. Count number of subnets

First, replace /18 with notation we're used to:

11111111.11111111.11000000.000000 converted to decimal is 255.255.192.0, you can see that left two parts of this mask correspond to class B default mask, so this mask is within range of class B default mask inside means that we will divide a large class B network into subnets. The default class B mask uses 16 bits (16 zeros) to represent assigned IP address. The mask in this question has two more 1s representing network number based on class B default mask. This tells class Network B is divided into (11) binary subnets, and (11) binary to decimal conversion is 4, so class B network is divided into 4 subnets in this question.

2. Calculate network number

Use formula: AND IP address binary and subnet mask binary, and result is network number. The AND rule is that 1 and 1 are 1, 0 and 1 are 0, and 1 and 0 are 0.

172.31.128.255

In binary it will be10101100.00011111.10000000.11111111,

So:

10101100.00011111.10000000.11111111

11111111.11111111.11000000.00000000

10101100.00011111.10000000.00000000

Will10101100.00011111.10000000.00000000

Decimal would be 172.31.128.0, so network number would be 172.31.128.0

3. Calculate host number

Also use formula: use binary sum of IP address (the binary inversion of subnet mask) to perform an AND operation, and result is host number. The reverse code should change original 0 to 1,

What was originally 1 becomes 0.

Thus, its backcode is expressed as00000000.00000000.00111111.11111111, and then binary and masked backcode representation of IP address is concatenated by AND:

10101100.00011111.10000000.11111111

00000000.00000000.00111111.11111111

00000000.00000000.00000000.11111111

Will00000000.00000000.00000000.11111111

Convert to decimal: 0.0.0.255. We remove 0 on left and only keep number on right, so we say that host number of this IP address is 255. NThe host number means that network number plus 255 is IP address.