Photo by Jordan Harrison on Unsplash
Introduction to Subnet and Subnetting
Split a large network to smaller subnets
Instead of directly jumping to subnet we will talk a bit about IP addreses
IP address
So what basically is an IP address
Let us connect this with your home address. Suppose you are living at House no. 32, Docker street, Linux City, Computer State, Power Country and you order something from amazon australia. So the logistic partner would decode your address such that your parcel would be first sent along with others to Power Country then their facility at Power Country would ship it to Computer State along with other parcels belonging to Computer state and then it would be sent to Linux City then to Docker Street and finally it would reach your home. Just like your address is made up of your house no. , city, state , in a similar way an IP address consist of the network part and the host part which defines a unique device on the internet or on the local network.
Based on these network and host bits and IPv4 address is can be of 3 classes A, B and C (D & E class also exist but in our devices we can use only class A, B and C).
An IPv4 address is of 32 bits divided into 4 octets like x.x.x.x where each octet is of 8 bits so an octet can have 2^8 = 256 values i.e between 0 to 255.
So talking about Class A the first octet would represent the Network part (by default) i.e 8 bits and the remaining three octets would contain Host part i.e 24 bits. Similarly Class B has 2 octets as Network part and Class C has 3 octets as Network part.
To get to know about the class of a given ip we just need to observe its first octet
So if first octet between 0 - 127 then Class A 128 - 191 then Class B 192 - 223 then Class C
Router
A router is a device that connects two or more packet switched networks Suppose our device has an ip of 192.168.1.2 and we want to connect to a network with ip 192.168.1.10 this connection would not require any router to connect as both the devices are on the same network because it is a Class C ip address so the network part would be first 3 octets, as the first 3 octets of both the networks are same thus they are on the same network.
Another example We are network 192.168.5.2 and we want to connect to network 192.168.1.2 . We can't connect to this network as the third octet is different.
N: Network part H: Host part
Class A : N.H.H.H Class B : N.N.H.H Class C : N.N.N.H
Subnet
Slash value
The slash value represents the number of network bits present in the address. Example - 192.168.1.10/24 This means there are 24 network bits in this ip which is obvious for a class C address with default subnet mask.
This table represent the value of subnet mask for a complete octet Example - For 192.168.1.10/24 i.e 24 network bits divide it into octets 24 = 8 + 8 + 8 8 means complete octet subnet mask for complete octet = 128+64+32+16+8+4+2+1 = 255 So the subnet mask for this 255.255.255.0 Default subnet mask for Class C = 255.255.255.0 for class B there are 16 network bits so slash value will be 16 16 = 8 + 8 So subnet mask for this 255.255.0.0 Default subnet mask for Class B = 255.255.0.0 for class A there are 8 network bits so slash value will be 8 so subnet mask for this 255.0.0.0
Subnet
Subnetting is a process of dividing a network into 2 or more networks. The main goal of subnetting is to split a large network into a grouping of smaller, interconnected networks to help minimize traffic . As we know IPv4 addresses are present in limited number so subnetting also helps in reducing the wastage of ips
It is like having multiple lanes leading to same destination instead of a single road.
Ok now let us move on more numerical part that you may find in some interviews of networking. And we will learn these by doing examples.
FLSM ( Fixed Length Subnet Mask )
Let's say we have a class C network 192.168.1.0/24 and we want to divide this network, so that we can serve 2 computer labs having 100 computer hosts each.
So in one lab we have 100 computers
By default we have 24 Network and 8 Host bits 2^8 = 256 ips but we require only 100 in one lab this would cost wastage of 156 ips The nearest power that can serve this is 2^7 = 128 This means we require 7 Host bits instead of 8 but an ipv4 address would contain 32 bits in total this means network part in our case will have 25 bits so N = 25 and H = 7
For a slash value of 25 25 = 8 + 8 + 8 +1 8 means full octet i.e 255 but what about 1, this means 1 times 128 + 0 times 64 + 0 times 32 and so on........... which would result in 128 This means the subnet mask will be 255.255.255.128 so the first 3 octets are filled but the last octet is half filled i.e 256-128 = 128 this is called the gap. Now we have N = 25, H = 7, gap = 128 and sunet mask = 255.255.255.128 So we will divide the network as shown below
Note - We can't use the first and last ip of our lab i.e. 192.168.1.0 and 192.168.1.255 as the first ip is used by router for network identification and the last ip for broadcasting to all connected devices. Also now a device in lab A is on different subnet than a device in lab B so to connect them with each other we must need a router.
Example - Suppose we have network 17.0.0.0/8 and we want to divide this for 128 countries.
Given ip is of class A so N=8 and H=24 we know that 2^7 = 128 so Note that we are not given the no. of host devices So in these type of cases simply add the power i.e. 7 to the network part and simply remove 7 from host part
N = 8+7 = 15 H = 24-7 = 17
For N = 15 15 = 8 + 7 8 :- 255 7:- 1 times 128 + 1 times 64 + 1 times 32 + 1 times 16 + 1 times8 + 1 times 4 + 1 times 2 + 0 times 1 = 254 So the subnet mask = 255.254.0.0 Gap = 256-254 = 2.0.0 So we would divide the network as given below
Ok now we have a practise problem for you Suppose we are on network 150.10.0.0/16 and we want to divide this network into 2 parts with 1000 hosts each
VLSM ( Variable Length Subnet Mask )
Till now we have cases with same number of host devices in each partition . But in VLSM we have different number of computers in each partition.
Suppose we have a network 192.168.1.0/24 and we need to divide it in such a way that
N = 24, H = 8
For A 2^6 = 64 H = 6 and N = 26 26 = 8+8+8+2 Subnet mask = 255.255.255.192
For B 2^5 = 32 H = 5 and N=27 Subnet mask = 255.255.255.224
For C 2^4 = 16 H = 4 and N=28 Subnet mask = 255.255.255.240
For D 2^3 = 8 H=3 and N = 29 Subnet mask = 255.255.255.248
Gap AB = 2^6 = 64 Gap BC = 2^5 = 32 Gap CD = 2^4 = 16 Gap D-end = 2^3 = 8
Now the configuration will be
Hope you like this Blog , Follow me for more tech stuff Don't forget to follow me on twitter