Subnetting and Supernetting
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 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.