Subnetting and Supernetting

Site: Saylor Academy
Course: CS402: Computer Communications and Networks
Book: Subnetting and Supernetting
Printed by: Guest user
Date: Friday, July 19, 2024, 4:48 PM

Description

Read these pages for a deeper and more detailed understanding of the need and use of subnetting and supernetting. Make sure that you understand the exact subnet to which an address/mask combination belongs. Once you determine the exact subnet, make sure that you can name the first and last hosts on that subnet, as well as the network name and broadcast address. These are very important principles that need to be mastered.

Subnetting and Masking

What does subnetting do?

  • As originally conceived, the internet was a big network composed of 4 addressable portions, class A, Class B, Class C, and Class D, all based on the particular IP address used.
  • From IP’s point of view, the address is always divided into a network number (based on the class) and a host address
    • Host bits of the IP address represent a unique location within the network
  • Subnetting:
    • Changes a single network into multiple networks
    • Takes bits from the host field and uses them to represent internal subnetworks
    • It hides network complexity and makes network administration easier.
  • Subnetting also can be used to break up the traffic in a network so that it follows a more logical flow.
  • For example, the network could be divided into a subnetwork for accounting, a different one for engineering, etc.

The Mask

  • The network mask is the instrument used for subnetting.
    • An address like 20.25.107.3 is a class A address. In a classful environment, that would normally be considered as netid.hostid.hostid.hostid. With 24 bits for host, over 16 million hosts can be addressed.
      • For this particular example, the address belongs to the 20 network. All addresses in that network must start with 20.
      • 20.25.107.3 and 20.30.107.3 are both in the same network, with 25.107.3 and 30.107.3 representing the hosts within that network.
  • Subnetting is used to look at the address in a different way. Let’s apply a network mask of 255.255.0.0. That mask tells the system that we will not only use the first byte for the network. The second byte will also be used for the network as well.
  • The address with this mask now will be considered to be of the form: netid.netid.hostid.hostid.
    • 20.25.107.3 and 20.30.107.3 are in now different (sub)networks, the 20.25.0.0 and the 20.30.0.0

Constructing The Mask

  • The mask will be constructed as an IP address composed of a series of contiguous ones. The series of ones will determine which part of the address will be considered as the (sub)network address.
  • In the previous example, looked in binary form, the mask was 16 bits long like this:
    • 1111 1111 1111 1111 0000 0000 0000 0000
  • In decimal, this address translates to 255.255.0.0
  • This simply means that the first two bytes are used as network and the last two bytes will be used for the host part.
  • Without subnetting, classful addresses have a default
    • 255.0.0.0 for Class A
    • 2255.255.0.0 for Class B
    • 255.255.255.0 for Class C.

Applying the mask

  • A Class A network has up to 126 different networks each with over 16 million hosts. Each one of the 126 different addresses is routed to the appropriate entry gateway.
  • Example: 20.X.Y.Z is routed to a gateway that handles network 20, regardless of X.Y.Z . As explained before, X.Y.Z represents the particular host within this class A network.
  • Once there, the gateway has the option of having a table with the exact location of all the over 16 million hosts. Because of this, straight routing will be very difficult to do.
  • To make the situation manageable, we use the full X portion (second byte) of the address to create subnetworks. This is accomplished with a 255.255.0.0 mask (/16)
    • Every single bit of the second byte now represents a new subnet. Eight new bits will generate 28, or up to 256 different subnetworks (from 0 to 255) .
    • For this example.
      • Subnets will increase linearly. First one is 20.0.0.0, second will be 20.1.0.0, third will be 20.2.0.0, etc.
      • 20.25.Y.Z is routed to subnet 20.25.0.0
      • 20.30.Y.Z is routed to subnet 20.30.0.0
  • The network mask is a convenient way of determining the different subnetworks available, to make the appropriate route decisions.

Example: Router handling 20.0.0.0 network


Working with the mast

  • A simple way to visualize how the mask works is by considering that the system performs a logical AND of the mask with an incoming address to extract the subnetwork portion. We will look into this process to help understand the whole concept.
  • Example: router handling the 20 network is using a 255.255.0.0, mask and receives a packet with address 20.25.107.8. Let’s translate the address into its binary equivalent in order to perform the logical AND. The result of this AND is the subnet number.

 1111 1111 1111 1111 0000 0000 0000 0000 = 255.255.0.0 (mask)

AND 0001 0100 0001 1001 0110 1011 0000 1000 = 20.25.107.8 (address)

-------------------------------------------------------------------------

 0001 0100 0001 1001 0000 0000 0000 0000 = 20.25.0.0 (result = subnet)


New Mask

  • Not all masks need to be of the classful type (i.e., 255). As long as they are contiguous, any number of ones can be used as a mask. For example, consider the following mask: 255.255.192.0.
  • That mask in binary form is:

255.255.192.0 = 1111 1111 1111 1111 1100 0000 0000 0000

  • We are simply taking the first two bits of the third byte away from the hosts to generate new subnets.
  • Suppose address 20.25.107.8 is received by the router. The process to consider is exactly as before. A logical AND is performed of the mask with the incoming address to obtain its subnet:

 1111 1111 1111 1111 1100 0000 0000 0000 = 255.255.192.0 (mask)

AND 0001 0100 0001 1001 0110 1011 0000 1000 = 20.25.107.8 (address)

---------------------------------------------------------------------------------

 0001 0100 0001 1001 0100 0000 0000 0000 = 20.25.64.0 (result = subnet)


How Many Subnets?

  • By using that mask, the incoming 20.25.107.8 address is found to be part of the 20.25.64.0 subnet.
  • Very important information for the subnets is carried now in the third byte where only the first two bits are used by the mask.
    • Basically we will need to make a binary count of those 2 bits to determine the number of subnets. Two bits generate 24, or four, subnets. They will correspond to addresses that start with 00, 01, 10 and 11 in the third byte as seen by the example below.
  • In the example below, when we fill the host field from all zeros to all ones, we are covering every single address possible in that range.
    • For every single one of those addresses within that range, the result of the logical AND of the address with that particular mask will always give the exact same result. This result is the subnet number.
    • All the addresses in that range, then, belong to the same subnet.

Subnets Created – binary count: 00, 01

Let’s look at all the possible scenarios when using the new mask

 1111 1111 1111 1111 1100 0000 0000 0000 (mask)

AND 0001 0100 0001 1001 0000 0000 0000 0000 (first possible host address) 20.25.0.0 to to

 0001 0100 0001 1001 0011 1111 1111 1111 (last possible host address ) 20.25.63.255

---------------------------------------------------------- -------------------

 0001 0000 0001 1001 0000 0000 0000 0000 (result = subnet) 20.25.0.0

Every address between 20.25.0.0 to 20.25.63.255 will lie in the 20.25.0.0 subnet.

 1111 1111 1111 1111 1100 0000 0000 0000 (mask)

AND 0001 0100 0001 1001 0100 0000 0000 0000 (first possible host address) 20.25.64.0 to to

 0001 0100 0001 1001 0111 1111 1111 1111 (last possible host address) 20.25.127.255

--------------------------------------------------------------- ---------------------

 0001 0000 0001 1001 0100 0000 0000 0000 (result = subnet) 20.25.64.0

Every address between 20.25.64.0 to 20.25.127.255 will lie in the same 20.25.64.0 subnet


Subnets Created – binary count: 10, 11

 1111 1111 1111 1111 1100 0000 0000 0000

AND 0001 0100 0001 1001 1000 0000 0000 0000 20.25.128.0 to to

 0001 0100 0001 1001 1011 1111 1111 1111 20.25.191.255

--------------------------------------------------------- ----------------

0001 0000 0001 1001 1000 0000 0000 0000 20.25.128.0

Every address between 20.25.128.0 to 20.25.191.255 will lie in the 20.25.0.0 subnet.

 1111 1111 1111 1111 1100 0000 0000 0000

AND 0001 0000 0001 1001 1100 0000 0000 0000 20.25.192.0 to to

 0001 0000 0001 1001 1111 1111 1111 1111 20.25.255.255

---------------------------------------------------------- -----------------

 0001 0000 0001 1001 1100 0000 0000 0000 20.25.192.0

Every address between 20.25.192.0 to 20.25.255.255 will lie in the 20.25.192.0 subnet.


Subnets Created - Summary

  • 4 distinctive subnets have been created:
    • 20.25.0.0 – corresponds to all hosts whose third byte address lies between 0000 0000 to 0011 1111
    • 20.25.64.0 – corresponds to all hosts whose third byte address lies between 0100 0000 to 0111 1111
    • 20.25.128.0 – corresponds to all hosts whose third byte address lies between 1000 0000 to 1011 1111
    • 20.25.192.0 – corresponds to all hosts whose third byte address lies between 1100 0000 to 1111 1111
  • The lesson here is that we will only need to look at the byte with the critical information to correctly determine all the subnet information

Second Router with a new mask

Special addresses .0

  • The all zero address, at the top of the subnet, is not allowed as a host address because it is used to represent the network. For example, for the first subnet above, 20.25.0.0 is the address of the subnet with 20.25.0.1 the first available host address for that subnet.
  • The all one address, at the bottom of the subnet, is not allowed as a host address because it is used to represent the broadcast address. In the same example for the top subnet above, the broadcast address will be the all ones, i.e., 20.25.63.255.
  • The last available host address for that subnet will be the one just behind the broadcast, i.e., 20.25.63.254.

Special addresses for the other subnets

Following the same logic we now know that the following is true for all the subnets obtained with that mask:

  • First subnet address is 20.25.0.0
    • First host: 20.25.0.1
    • Broadcast address: 20.25.63.255
    • Last host: 20.25.63.254
  • Second subnet address is 20.25.64.0
    • First host: 20.25.64.1
    • Broadcast address: 20.25.127.255
    • Last host: 20.25.127.254
  • Third subnet address is 20.25.128.0
    • First host: 20.25.128.1
    • Broadcast address: 20.25.191.255
    • Last host: 20.25.191.254
  • Fourth subnet address is 20.25.192.0
    • First host: 20.25.192.1
    • Broadcast address 20.25.255.255
    • Last host: 20.25.255.254

The dash (/) nomenclature

  • Masks can also be represented using the dash (/) nomenclature. The previous example could have been represented as 20.25.107.8/18
  • This simply means that the address is going to be treated with a mask whose first 18 bits are 1, which of course is the same as saying that the mask is 255.255.192.0.

Using the lesson learned above

  • Now we will change the action where things happen from the third byte to the second byte to stress the point that the process is the same on any byte that you extend the mask from the default. The following table shows what happens when the original class B mask of 255.0.0.0 is expanded by adding one bit at a time.
  • We already treated in detail the case where two bits are added. In the table below, the mask for 2 additional bits is in the form of /10 because we use all the bits from the first byte, plus 2 from the second byte. We still have 4 subnets separated by 64, that is, the 0, 64, 128, 192 networks as in our previous example.
  • Notice that each time that we add one bit, the number of subnets is doubled and the distance between them (i.e., the number of hosts available) is reduced in half. This will go all the way to a full byte (8 bits), where 256 subnets are created (and the mask, for this case, becomes 255.255.0.0)

Subnets for different masks.

/ form

Decimal

Number of Subnets () and subnet numbers

/9

255.128.0.0

(2) 0,128

/10

255.192.0.0

(4) 0, 64, 128, 192

/11

255.224.0.0

(8) 0, 32, 64, 96, 128, 160, 192, 224

/12

255.240.0.0

(16) 0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176,

192, 208, 224

/13

255.248.0.0

(32) 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104,

112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192,

200, 208, 216, 222, 230, 240, 248


Source: Eladio R. Cortes Ramos
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.

Classless Interdomain Routing

Supernetting vs Subnetting

  • Subnetting is the process where you take a big classful network and divide it into smaller subnetworks by increasing the number of bits representing the network.
  • Supernetting, on the other hand, is a process where you might want to increase the number of hosts in a network by increasing the number of bits representing the host, regardless of the class of the network. That’s why it is referred to as Classless Interdomain Routing or CIDR.

CIDR Address Allocation

  • CIDR
    • As described in RFC 1519
    • Allocates the address space into variable sized blocks, regardless of the class.
  • Example: The site needs around 2000 addresses,
    • 11 contiguous bits designating the host part of the address will generate 211 = 2048 contiguous addresses. That’s the closest to the required 2000 address, but:
      • No need to give a full class B address (wasted address space)
      • No need to give a class C address (too small for most organizations)
  • Similarly, a site needing 8000 addresses will require 13 contiguous bits that will generate 213 = 8192 addresses, etc.

Example 1:

  • Customer needs 2000 addresses
  • Group of addresses starting at 194.24.0.0 are available.
  • You need 11 contiguous bits (211 = 2048). You can accomplish this by giving the customer the group:
    • From 11000010 00011000 00000000 00000000 = 194.24.0.0
    • To 11000010 00011000 00000111 11111111 = 194.24.7.255
  • Mask needed will be:
    • 11111111 111111111 11111000 00000000 = 255.255.248.0
      • Notice that in the mask, the 11 contiguous bits of the host portion all become 0 so that when the logical AND is done with any host, the result will always be a 0, i.e., it will point to the customer’s address block.
      • The rest of the addresses become all ones so that the network part of the address will remain unaltered after the logical AND.

Example 2:

  • The customer needs 4000 addresses.
  • Can we give this customer the next available block starting at 194.24.8.0?
    • No:
      • We need 12 contiguous spaces (212 = 4096) to be the closest possible to 4000
      • 194.24.8.0 = 11000010 00011000 00001000 00000000, which only provides 11 contiguous bits.
  • If we go one bit up, i.e., to 194.24.16.0:
    • 194.24.16.0 = 11000010 00011000 00010000 00000000
    • 12 contiguous bits are available
  • The block of addresses will be:
    • From 194.24.16.0 = 11000010 00011000 00010000 00000000
    • To 194.24.31.255 = 11000010 00011000 00011111 11111111
    • Mask: 255.255.240.0 = 11111111 11111111 1111 0000 00000000
  • Why the mask?
    • First byte of all 1 “passes” first byte unchanged
    • Second byte of all 1 “passes” second byte unchanged
    • Next four 1111’s “pass” up to the 4th bit on third byte
    • Everything else is masked and become 0 to point to the network

Example 3:

  • Third customer wants 1000 addresses.
  • We can go back to 192.24.8.0
    • Only 10 contiguous bits necessary.
  • Assigned block is:
    • From 194.24.8.0 = 11000010 00011000 00001000 00000000
    • To 194.24.11.255 = 11000010 00011000 00001011 11111111
  • And mask:
    • 255.255.252.0 = 11111111 11111111 11111100 00000000

Routing Tables for the previous three examples

  • Routing tables are now updated with the following three entries:

Base Address

Mask

Port

192.24.0.0

255.255.248.0

X

192.24.16.0

255.255.240.0

Y

192. 24.8.0

255.255.252.0

Z

Default

W

Or in binary:

11000010 00011000 00000000 00000000

11111111 11111111 11111000 00000000

X

11000010 00011000 00010000 00000000

11111111 11111111 11110000 00000000

Y

11000010 00011000 00001000 00000000

11111111 11111111 11111100 00000000

Z


How are addresses handled?

  • Packet comes with address to 194.24.10.4. Where will it be routed?
  • The address will be systematically ANDed with all the masks in the routing table until a match is found.
  • For the first entry:
    • Address of 11000010 00011000 00001010 00000100 = 194.24.10.4
    • ANDed with the mask for the first entry in the table
    • The result is 11000010 00011000 00001000 00000000 = 194.24.8.0
    • Since this value does not match the base address for that customer (194.24.0.0), it will not be sent to the customer’s router through port A.
  • The address (194.24.10.4) is now ANDed with the mask for the second entry in the table.
    • Again the process will not yield a match with that customer’s base address.
  • It will be next ANDed with the mask for the third entry.
    • At this point a match occurs, i.e.,
    • ANDing 194.24.10.4 with 255.255.252.0 will result in 194.24.8.0.
    • The packet will then be sent to port Z which handles customer’s 3 router.
  • Packet will be sent to a “default” route if no match can be found.
  • There are some tricks that can be used to avoid searching the table sequentially. This will speed up the process.

Source: Eladio R. Cortes Ramos
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.