How to Use Subnet Masks- Understanding IP

For the subnet address scheme to work, every machine on the network must know which part of the host address will be used as the network address. This is accomplished by assigning each machine a subnet mask.

The network administrator creates a 32-b it subnet mask consisting of 1s and 0s. The 1s in the subnet mask represent the positions in the IP address that refer to the network and subnet addresses. The 0s represent the positions that refer to the host part of the address. Figure 4.6 illustrates this combination.

FIGURE 4.6 The subnet mask revealed

Subnet mask code

1s = Positions representing network or subnet addresses

0s = Positions representing the host address

Subnet mask for Widget, Inc.

Network address Subnet Host positions positions positions

In the Widget Inc. example, the first two bytes of the subnet mask are 1s because  Widget’s network address is a Class B address, formatted as Network.Network.Node.Node. The third byte, normally assigned as part of the host address, is now used to represent the subnet address. Hence, those bit positions are represented with 1s in the subnet mask. The fourth byte is the only part of the example that represents the host address.

The subnet mask can also be expressed using the decimal equivalents of the binary patterns. The binary pattern of 1111 1111 is the same as decimal 255. Consequently, the subnet mask in the example can be denoted in two ways, as shown in Figure 4.7.

FIGURE 4.7 Different ways to represent the same mask

Subnet mask in binary: 1111 1111. 1111 1111. 111 1 1111. 0000 0000

Subnet mask in decimal:   255        .          255       .          255       .           0

(The spaces in the above example are only for illustrative purposes.

The subnet mask in decimal would actually appear as 255.255.255.0.)

Not all networks need to have subnets, and therefore they don’t need to use custom subnet masks. In this case, they are said to have a default subnet mask. This is basically the same as saying that they don’t have any subnets except for the one main subnet on which the network is running. Table 4.4 shows the default subnet masks for the different classes of networks.

TABLE 4.4 Default subnet masks

ClassFormatDefault subnet mask
ANetwork.Node.Node.Node255.0.0.0
BNetwork.Network.Node.Node255.255.0.0
CNetwork.Network.Network.Node255.255.255.0

Once the network administrator has created the subnet mask and has assigned it to each machine, the IP software applies the subnet mask to the IP address to determine its subnet address. The word mask carries the implied meaning of “lens” in this case; that is, the IP software looks at its IP address through the lens of its subnet mask to see its subnet address.

Figure 4.8 illustrates an IP address being viewed through a subnet mask.

FIGURE 4.8 Applying the subnet mask

Subnet mask code

1s = Positions representing network or subnet addresses

0s = Positions representing the host address

Positions relating to the subnet address

Subnet mask:                           1111 1111. 1111 1111. 1111 1111. 0000 0000

IP address of a machine on subnet 1:           1000 0010. 0011 1001. 0000 0001. 0011 1000

(Decimal: 130.57.1.56)                                                                             

Bits relating to the subnet address

In this example, the IP software learns through the subnet mask that, instead of being part of the host address, the third byte of its IP address is now going to be used as a subnet address. The IP software then looks in its IP address at the bit positions that correspond to the mask, which are 0000 0001.

The final step is for the subnet bit values to be matched up with the binary numbering convention and converted to decimal. In the Widget Inc. example, the binary- to- decimal conversion is simple, as illustrated in Figure 4.9.

FIGURE 4.9 Converting the subnet mask to decimal

Binary numbering convention

Position/value:

Widget third byte:                                              0     0    0      0 0 0 0 1

Decimal equivalent:                                                                  0 + 1 = 1

Subnet address:                                                                                    1

By using the entire third byte of a Class B address as the subnet address, it is easy to set and determine the subnet address. For example, if Widget Inc. wants to have a subnet 6, the third byte of all machines on that subnet will be 0000 0110 (decimal 6 in binary).

Using the entire third byte of a Class B network address for the subnet allows for a fair number of available subnet addresses. One byte dedicated to the subnet provides eight bit positions. Each position can be either a 1 or a 0, so the calculation is 28, or 256. Thus, Widget Inc. can have up to 256 total subnetworks, each with up to 254 hosts.

Although RFC 950 prohibits the use of binary all 0s and all 1s as subnet addresses, today almost all products actually permit this usage. Microsoft’s TCP/IP stack allows it, as does the software in most routers (provided you enable this feature, which sometimes is not the case by default). This gives you two additional subnets. However, you should not use a subnet of 0 (all 0s) unless all the software on your network recognizes this convention.

How to Calculate the Number of Subnets

The formulas for calculating the maximum number of subnets and the maximum number of hosts per subnet are as follows:

2number of masked bits in subnet mask            maximum number of subnets

2number of unmasked bits in subnet mask– 2             maximum number of hosts per subnet

In the formulas, masked refers to bit positions of 1, and unmasked refers to bit positions of 0. The downside to using an entire byte of a node address as your subnet address is that you reduce the possible number of node addresses on each subnet. As explained earlier, without a subnet, a Class B address has 65,534 unique combinations of 1s and 0s that can be used for node addresses. The question then is why would you ever want 65,534 hosts on a single physical network?

The trade- off is acceptable to most who ask themselves this question. If you use an entire byte of the node address for a subnet, you then have only 1 byte for the host addresses, leaving only 254 possible host addresses. If any of your subnets are populated with more than 254 machines, you’ll have a problem. To solve it, you would then need to shorten the subnet mask, thereby lengthening the number of host bits and increasing the number of host addresses. This gives you more available host addresses on each subnet. A side effect of this solution is that it shrinks the number of possible subnets.

Figure 4.10 shows an example of using a smaller subnet address. A company called Acme Inc. expects to need a maximum of 14 subnets. In this case, Acme does not need to take an entire byte from the host address for the subnet address. To get its 14 different subnet addresses, it needs to snatch only 4 bits from the host address (24 = 16). The host portion of the address has 12 usable bits remaining (212 – 2 = 4,094). Each of Acme’s 16 subnets could then potentially have a total of 4,094 host addresses, and 4,094 machines on each subnet should be plenty.

FIGURE 4.10 An example of a smaller subnet address

Acme, Inc.

Network address:          132.8 (Class B; net.net.host.host)

 Example IP address:   1000 0100. 0000 1000.0001 0010.0011 1100

Decimal:               132    .        8       .       18      .        60

Subnet Mask Code

1s = Positions representing network or subnet addresses

0s = Positions representing the host address

Subnet mask:

 Binary:                        1111 1111. 1111 1111.1111 0000.0000 0000

Decimal:                                255    .      255    .      240     .         0

(The decimal 240 is equal to the binary 1111 0000.)

Positions relating to the subnet address

Subnet mask:                                   1111 1111. 1111 1111.1111 0000.0000 0000

 IP address of a Acme machine:     1000 0100. 0000 1000.0001 0010.0011 1100

(Decimal: 132.8.18.60)

Bits relating to the subnet address

Binary-to-Decimal Conversions for Subnet Address

Subnet mask positions: 0       0  0

Position/value: (continue)  128    64      32      16      8        4        2      1 Third byte of IP address:      0        0        0        1        0        0        1      0 Decimal equivalent:   0 + 16 = 16

Subnet address for this IP address:                                                           16

Leave a Reply

Your email address will not be published. Required fields are marked *