Thursday, 23 March 2023

Subnetting

An Analogy

Imagine you are a post man. You have a post round on a street with 100 houses, but only 2 of them houses are occupied. You have to walk around the estate to deliver mail to 2 houses. It takes you longer because one is at one house is at one side of the estate and one at the opposite side. Wouldn't it be more efficient if both those houses are next to each other? You also notice all the empty houses have their doors open and its costing a lot of money for the up keep of those empty houses. This is subnetting in a nutshell. On a typical home network you have a maximum of 256 addresses (254 are usable) but if your fortunate your house might only have 10 devices. That's 244 wasted addresses. Now you may get a new Xbox for your birthday or a new tablet so wouldn't it be more efficient to reduce that address space? The subnetting journey starts.....

IPv4 Classes

Before starting on this epic journey, you must understand IP version 4 classes. The first number in an Ip address or the first octet indicates the network class. For example 10.0.0.0 indicates it is a Class A IP address because it falls between 1 and 127.255.255.255. 172.16.0.0 is a class B address because the 172 falls between 128 and 191. 

Classes are important. The class range determines the default subnet mask and the default CIDR notation. 


ClassIP RangeDefault Subnet MaskDefault CIDR notation
Class A1-127.255.255.255255.0.0.0/8
Class B128-191.255.255.255255.255.0.0/16
Class C191-223.255.255.255255.255.255.0/24
Class D224-239.255.255.255N/AN/A
Class E240-255.255.255.255N/AN/A


CIDR notation 

A CIDR notation refers to the amount of bits that are assigned to the network. Subtracting the CIDR notation number from 32 will give you the number of bits that are assigned to hosts. For example;

In a class C IP address the default subnet mask is 255.255.255.0 and the default CIDR notation is /24. This means that 24 bits are being used by the network and the remaining 8 bits can be used for hosts. If you calculate 8 bits in binary you will get 128+64+32+16+8+4+2+1 = 255. This means that on a default class C address you have 256 addresses (0 is a number) and if you subtract the network address and a broadcast address (all addresses follow this rule -2) then you have 254 available/usable addresses for hosts. Another binary representation of this example is;

11111111.11111111.11111111.00000000

The highlighted peach are the network bits and the green the hosts bits. 


Subnetting

Now we have the foundations lets look at some scenarios.

Scenario 1

Lets say you purchase an IP address from an ISP 192.168.1.0. You have two offices each with 100 clients and you don't want to buy another IP address but split this network up into two and reduce the number of available hosts from the default. Lets work through this problem;

If you remember from previous we have 256 available addresses on a default class C address. But we only need 100. We also know that the default subnet of 255.255.255.0 carries a default CIDR notation of /24. Below is the subnet mask highlighted peach are the network bit and highlighted green are the host bits.


128+64+32+16+8+4+2+1 .128+64+32+16+8+4+2+1.128+64+32+16+8+4+2+1. 128+64+32+16+8+4+2+1

So, we need to reduce the number of hosts in this scenario and increase the number of networks. Remember that network bits run from left to right and hosts from right to left. So in this scenario lets take the first bit from the last octet (the green 128). This now means we are using 25 bits and our new CIDR notation is /25. If we add the bits together (the highlighted peach) we will get our new subnet mask of 255.255.255.128


128+64+32+16+8+4+2+1 .128+64+32+16+8+4+2+1.128+64+32+16+8+4+2+1128+64+32+16+8+4+2+1


To now work out the hosts we can simply add the green bits together.
So the IP address we bought was 192.168.1.0.
Our first network address is 192.168.1.0  , then adding the bits in green gives the last address on this network 192.168.1.127 (applying the -2 rule discussed previously 192.168.1.0 is the network address and 192.168.1.127 is the broadcast address therefore we have 126 usable addresses)

Then the second network address is 192.168.1.128 to 192.168.1.255 (as with network 1 we need to subtract 2 so our network address is 192.168.1.128 our broadcast address is 192.168.1.255 and the addresses in between are usable addresses)


No comments:

Post a Comment

Fast switching vs Process switching

Process Switching: Process switching is the traditional method of packet forwarding used in early routers. When a packet arrives at a router...