Subnetting example: =================== Assume you have a class C IP prefix at hand (200.25.10) and you want to create two different subnets of sizes 15 and 63 out of it. Since these subnets are created simultaneously let's arrange them in decreasing order to make life simple. You will see how this simplifies things when we create network prefixes for CIDR with the same parameters but do not have the flexibility of rearrangement. # bits required for a 63 host subnet: 6 (provisions for 64 distinct IP addresses - ignore the fact all 1s and all 0s aren't usable) # bits that become part of the mask: 2 (since this is a class C address, we only have 8 total bits we can manipulate) Subnet mask: 255.255.255.192 (mask size = # 1s = network prefix size = 26. Since class C address already has a default mask of 24 bits after adding the 2 higher order left over bits we now have a mask of size 26) Since none of the 8 bits are assigned so far, the allocation of IP addresses for the hosts in this subnet would look like: Lowest IP addr Highest IP addr Subnet # Subnet mask ----------------------------------------------------------------------- 200.25.10.0 200.25.10.63 200.25.10.0/26 255.255.255.192 Notice that the last bytes of the IP addresses of the first and last host on this subnet are 00000000 and 00111111 respecively (first two bits are same for all hosts). As a result of this contiguous assignment the last 2 bits of the mask would be able to ensure that packets for ALL the hosts on this subnet can be forwarded correctly. Now we can worry about creating the next subnet of 15 hosts. # bits required for a 15 host subnet: 4 # bits that become part of the mask: 4 Subnet mask: 255.255.255.240 (mask size = 28) Since we have already used up addresses through 200.25.10.63, we need to start the host numbering for this subnet at 200.25.10.64. The last host will have the IP address 200.25.10.79. The overall allocation for this subnet would look like: Lowest IP addr Highest IP addr Network # Subnet mask ------------------------------------------------------------------------ 200.25.10.64 200.25.10.79 200.25.10.64/28 255.255.255.240 The last byte of the IP address of the first and last host on this subnet are 01000000 and 01001111 respecively (first 4 bits are same for all hosts). As a result of this contiguous assignment the last 4 bits of the mask would be able to ensure that packets for ALL the hosts on this subnet can be forwarded correctly. CIDR example: ------------- Let's take the above example again, only now the class C prefix 200.25.10 is to be divided into two CIDR networks of 15 and 63 respectively in that order. This restriction is realistic because the requests for creating these networks can arrive in this order and the central addressing authority would have already allocated the network prefix for the first network before it receives the next request. Let's now see how things vary in the presence of this restriction. We start by allocating addresses for the 15 host network. # bits required for a 15 host network: 4 # bits that become part of the mask: 4 Network mask: 255.255.255.240 (mask size = 28) Since none of the 8 bits are assigned so far, the allocation of IP addresses for the hosts in this network would look like: Lowest IP addr Highest IP addr Network # Network mask ---------------------------------------------------------------------- 200.25.10.0 200.25.10.15 200.25.10.0/28 255.255.255.240 Notice that the mask depends only on the number of bits required for assigning contiguous IP addresses to the hosts and is unchanged for this network from the subnetting problem. As before, let's verify that the mask will identify the SAME network for ALL the hosts on this network. Since the last bytes of the IP addresses for the first and last host of this network are 00000000 and 00001111 respectively, the last 4 bits of the mask will be able to identify ALL the hosts on this network. Now we can worry about creating the next network of 63 hosts. # bits required for a 63 host network: 6 # bits that become part of the mask: 2 Network mask: 255.255.255.192 (mask size = 26) Ideally, following the subnetting example we worked on earlier we would be tempted to use addresses 200.25.10.16 through 200.25.10.79 for this network. But that would be incorrect. To see why, let's write down the last byte of the IP addresses of the first and last hosts on this 63 host network: Last byte for the first host: 00010000 Last byte for the last host: 01001111 Since only the most significant bit is common between first and last hosts on this network, the mask of size 26 will not identify the correct subnet number for all the hosts on this network. This is because the bits used for assigning the IP addresses for hosts 0 through 63 in this network are not aligned at the 64 number boundary. For mask 255.255.255.192 to work the most economical assignment of continuous IP addresses for hosts would have to be 200.25.10.64 through 200.25.10.127. Notice that the last bytes for the IP addresses of the first and last host on this network are now 01000000 and 01111111, assuring that the last 2 bits of the mask will correctly identify packets for ALL the hosts on this network. The final allocation for this network would look like: Lowest IP addr Highest IP addr Subnet # Network mask ------------------------------------------------------------------------- 200.25.10.64 200.25.10.127 200.25.10.64/26 255.255.255.192 Notice that the above assignment has left addresses 200.25.10.16 through 200.25.10.63 unassigned with the last bytes being 00010000 and 00111111 respectively. This chunk of addresses unfortunately cannot be assigned to any single network. This is because the longest mask common to the IP addresses with these as the last bytes is of size 26 (24 bits for the class C address + 2 common most significant bits from the last byte) and includes the already assigned addresses 200.25.10.0 through 200.25.10.15 that have their last bytes as 00000000 through 00001111. One can argue that since these already assigned addresses have a longer network mask of size 28 things will still be fine at the routers because of the longest prefix rule but since this relies on routers doing the right thing and makes the problem of coming up with mask more complex, such assignments are usually not done. As a result, the only possibility of using up this left over address space is to allocate 200.25.10.16 through 200.25.10.31 to one network of size 16 hosts (or two networks of size 8 hosts etc.) and 200.25.10.32 through 200.25.10.63 to another network of size 32 hosts (or two networks of size 16 hosts etc.).