Understanding IP Routing and Subnet Masks Print E-mail
Understanding IP Routing and Subnet Masks

For reference, the following is a complete list of all possible masks:

Bits         Mask           Hex      Bits          Mask             Hex     

    8     255.0.0.0       FF000000      20    255.255.240.0      FFFFF000     

   10     255.192.0.0     FFC00000      21    255.255.248.0      FFFFF800     

   11     255.224.0.0     FFE00000      22    255.255.252.0      FFFFFC00     

   12     255.240.0.0     FFF00000      23    255.255.254.0      FFFFFE00     

   13     255.248.0.0     FFF80000      24    255.255.255.0      FFFFFF00     

   14     255.252.0.0     FFFC0000      25    255.255.255.128    FFFFFF80     

   15     255.254.0.0     FFFE0000      26    255.255.255.192    FFFFFFC0     

   16     255.255.0.0     FFFF0000      27    255.255.255.224    FFFFFFE0     

   17     255.255.128.0   FFFF8000      28    255.255.255.240    FFFFFFF0     

   18     255.255.192.0   FFFFC000      29    255.255.255.248    FFFFFFF8     

   19     255.255.224.0   FFFFE000      30    255.255.255.252    FFFFFFFC     

Certain combinations of subnet masks and remote addresses cannot be supported, due to Internet requirements. These combinations depend on the value of the first octet (first number in dotted IP notation) of the IP address. These restrictions are:

    Octet values                       Notes                    



0, 127, 224-255      These are illegal network numbers; do not  use                                        

1-126                Class A network, any of above masks will  work                                       

128-191              Class B network, 8-15 and 17 bits disallowed                                 

192-223              Class C network, 8-23 and 25 bits  disallowed                                 

For each of the legal network classes and subnets, here are the total possible number of subnets and host addresses per subnet. This table gives information on how to use the host bits and subnet bits to allow the maximum number of hosts or subnets.

Class A:

 Bits    Subnets       Hosts        Bits       Subnets        Hosts  

   8        1        1,777,214       20          4094         4,094     

  10        2        4,194,302       21          8190         2,046     

  11        6        2,097,150       22         16382         1,022     

  12        14       1,048,574       23         32766          510      

  13        30        524,286        24         65534          254      

  14        62        262,142        25         131070          16      

  15       126        131,070        26         262142          62      

  16       254         65,534        27         524286          30      

  17       510         32,766        28        1048574          14      

  18      1,022        16,382        29        2097150          6       

  19      2,046        8,190         30        4194302          2       

Class B:

   Bits     Subnets      Hosts       Bits     Subnets      Hosts    

    16         1        65,534        24        254         254     

    18         2        16,382        25        510         126     

    19         6         8,190        26       1,022        62      

    20         14        4,094        27       2,046        30      

    21         30        2,046        28       4,094        14      

    22         62        1,022        29       8,190         6      

    23        126         510         30       16,382        2      

Class C:

   Bits      Subnets     Hosts       Bits     Subnets      Hosts    

    24          1         254         28         14         14      

    26          2          62         29         30          6      

    27          6          30         30         62          2      

It is a trivial optimization exercise to show that the total number of available host addresses is maximized if subnetting is unused. In the presence of subnetting, the total number of available host addresses is maximized if the number of subnet bits is equal to the number of host bits. Thus, "optimum" mask for class A networks is 255.255.240.0, for class B networks it is 255.255.255.0, and for class C networks it is 255.255.255.240.

Example of Class C Complex Subnet Masking

Complex subnet masking is used to increase the number of usable subnets with less hosts per subnet or to increase the number of hosts per subnet with less actual subnets.

In a Class C address the first 3 octets can not be changed, only the last octet can be changed. Anyone with a Class C network address has to use complex subnet masking in order to get any subnets. Complex masking may also be used in a Class A or a Class B address environment.

The following is an example of Class C subnet masking. It tries to show, in actual bits and bytes, how to subnet a Class C address into 62 subnets, with 2 hosts per subnet. The example also shows why you lose some of your available addresses or hosts when you do complex masking.

Network #: 197.129.59.0 Class: C

Subnet Mask: 255.255.255.252
# of Subnets: 62
# of Host per Subnet: 2
Example:

IP Address: 197.129.59.6
# Subnet Bits: 6
Subnet Address: 197.129.59.4
Subnet Mask: 255.255.255.252
Subnet Broadcast Address: 197.129.59.7

The IP Address broken down into binary is:

IP Address      Network                                 Subnet     Host      

197.129.59.6    11000101.10000001.00111011              000001     10        

The Subnet Mask can be obtained from the IP Address when you know how many bits you want to subnet on. We are subnetting on the first 6 bits of the last octet, and regulating 2 bits for the host field. For example:

11000101.10000001.00111011. | 000001 | 10

Where the last 2 bits are regulated for the host bits. We then change all the subnet bits to 1's and host bits to 0 to come up with the subnet mask of:

255.255.255.252 11111111.11111111.11111111. | 111111 | 00

To find the Subnet address, AND the Subnet bits of the IP address with the subnet mask. The first subnet address is:

 197.129.59.6 11000101.10000001.00111011. | 000001 | 10
255.255.255.252 11111111.11111111.11111111. | 111111 | 00
197.129.59.4 11000101.10000001.00111011. | 000001 | 00 Note: A logical AND returns a 1 when both values are one, otherwise it returns a 0.

To find the Subnet Broadcast Address, AND the Subnet bits of the IP Address with 1 and change the host bits to 1. The subnet broadcast turns out to be:

197.129.59.7 11000101.10000001.00111011. | 000001 | 11

Therefore, the network breakdown for this subnet is:

197.129.59.4 reserved for Subnet Address

Valid Host bits are:

197.129.59.5 through 197.129.59.6

197.159.29.7 reserved for subnet broadcast

This same scenario is repeated for each subnet. The last subnet available is the 197.129.59.248 subnet address. In binary this address looks like:

11000101.10000001.00111011. | 111110 | 00

The last 2 bits, which are the host bits, are 0. This indicates a network address.

Enough said on that.

So where did the rest of the numbers go? There are a total of 255 addresses, but with this numbering scheme we only have 124 addresses. Where did the 130 other addresses go too?

Every subnet must have a reserved address for a subnet address and a reserved address for a subnet broadcast. Class B addressing scheme, masking on the third octet with 8 bits, the subnet address usually looks like 134.141.35.0, with a subnet broadcast of 134.141.35.255. Class C address using a 6 bit mask, gives 62 different subnets. Each subnet must have 62 subnet addresses and 62 subnet broadcasts.

Well, were down to 7 missing addresses. We can also take away the 197.129.59.252 address because it is also a reserved address.

11000101.10000001.00111011. | 111111 | 00

This is the all 1's subnet. Because of confusion with the subnet mask, it can not be used as a subnet address.

That brings us down to 6 missing addresses. The addresses 197.129.59.1 thru 197.129.59.3 and 197.129.59.253 thru 197.129.59.255 seem like they should be valid addresses, but tyey are not. Here is why.

The address of 197.129.59.1 in binary is:

11000101.10000001.00111011. | 000000 | 01

There are no 1's in the 4th octet part of the subnet field. All 0's in the subnet field do not make up a recognizable subnet. So we cannot use those 3 addresses. These addresses are referred to the 0's subnet.

The address of 197.129.59.253 in binary is:

11000101.10000001.00111011. | 111111 | 01

If you look closely at this address you see that the subnet portion of the 4th octet is all 1's in the subnet field. This is exactly how the subnet mask was defined. So we cannot use the last three addresses. This brings us down to 0 lost addresses.

< Previous