What is Subnetting ?-Subnetting is the process of diving a network into small networks and is a common task on IPV4 networks.
Before we discuss how to implement it it is useful to understand why and when we need to do it and to do that we are first going to work through a simple analogy to illustrate the problem subnetting solves
As an analogy imagine a school and we need to split it into class rooms.
But why split it into class rooms? The answer is to stop classes interfering with one another.
Now each classroom has a desk with a computer and we have been tasked with creating a labeling system for the computers.
Now say we have 30 classrooms each with a maximum of 30 students and computers.
If we assign numbers to our classrooms and computers then we could have for example:
computer 11, classroom 24
We need two digits for the classroom which would allow for a maximum of 100 classrooms (0-99).
We need two digits for the computer which would allow for a maximum of 100 computers (0-99).
If we also say that classroom numbers 0 and 99 and computer numbers 0 and 99 were reserved and not allowed to be assigned then we now have a maximum of 98 classrooms and 98 computers which is enough for own requirements.
So lets create our label we could use the following scheme:
- computer 11, classroom 24
There are many possible permutations we just need to pick one and tell every one about out labeling scheme.
Lets assume we go for 2411 where 24 is the classroom and 11 is the computer.
So now when we see the following 0223 we now know that this refers to classroom 2 and computer 23.
This we do easily in our heads once we know the labelling scheme.
We could even make it easier for ourselves by creating a paper mask that we put over the label that would reveal the classroom.
IP Addresses and Subnetting
Just like in our classroom example an IP address is split into two components a network component and a node component.
So the address 10.0.2.1 is split into Network plus Node.
So is the network number 10, or 10.2 or 10.0.2 ?
In early IPv4 networks address classes were used to identify the number of bytes allocated to the network component.
The main classes were class A,B,C. With the allocation as follows:
Class A network,node,node,node
Class B network,network,node,node
Class C network,network,network,node
To determine the class you needed to examine the most significant byte (far left).
- 0-127 Class A
- 128-191 Class B
- 192-ccc Class C
IP Subnetting- Problems with Large Networks
All modern networks use the Ethernet data link protocol.
Ethernet uses a shared media and is negatively effected when a large number of nodes are connected to the same media.
This is just the same as having too many kids in the same classroom.
You can equate a network and node address to our classroom and desk number
What would happen if you had a classroom with 100’s of desks i.e. hundreds of pupils?
So even though a Class A address can accommodate thousands of nodes it it totally impractical to put this many nodes on a single network.
The solution to the problem was to split the network into small networks called sub networks or subnets.
Take for example a class A address which uses 1 byte for the network ID and 3 bytes for the Node ID. Written
It is important to understand that the network part of the address is only used for routing IP packets on the public internet.
Once the packet enters the private network then the Node address is used and the public Network address is not used.
Now a network administrator can interpret the node address any way they want, and so it is possible to split the node address into subnet and Node. So we could have
Net.Subnet.Node.Node or Net.Subnet.Subnet.Node.
The technique used to create subnets is to use a Mask.
The mask effectively hides the Node component and leaves the network and sub network components.
If the IP address was printed on paper we could hide the last byte by placing a paper mask over the number with three holes.
Note: if your binary is a little rusty see the binary numbers tutorial
To do this on a computer we use a number which we then logically AND with with IP address.
Here is the logic table for AND
1 and 1 =1
1 and 0 =0
0 and 1 =0
0 and 0 =0
So our mask to hide the last byte is 255.255.255.0 As 0 and Anything is always 0
The best way to see this is to write the numbers out in binary
000001011.00000001.00000001.00010101 = 184.108.40.206
and then do a logical AND
the Network address is 220.127.116.11 which corresponds to network 11 subnet 1.1
The Subnet mask determines how the IPv4 address is split.
Th example above used a class A IP address we can do the same with a class B address.
Net.Net.Node.Node —->Net.Net.Subnet.Node Using Mask 255.255.255.0
Subnetting on a byte boundary is the easiest to do and understand but we can also subnet on non byte boundaries.
1- You have been allocated a class A network address of 18.104.22.168. You need to create at least 20 networks and each network will support a maximum of 160 hosts. Would the following two subnet masks Work?
255.255.0.0 and or 255.255.255.0
Yes both would work.
Mask 255.255.0.0 has 8 bits for the subnet and 16 bits for the host
8 bits would accommodate 28=256 subnets
16 bits would accommodate 216= over 64000 hosts
Mask 255.255.255.0 has 16 bits for the subnet and 8 bits of the host.
Have possible 28 -2 hosts =254 which is enough.
2. – You have been allocated a class B network address of 22.214.171.124 and and need to create 4 subnets each with around 200 hosts what is the easiest mask to use to satisfy the criteria?
Easiest is to sub net on a byte boundary which would mean a subnet mask of 255.255.255.0
This would allocate 8 bits for the subnet and 8 bits for the host.
We need to accommodate around 200 hosts which requires 8 bits which we have.
We need 4 subnets which requires 4 bits and we have 8 bits. So we have more than enough.
Classless Inter-Domain Routing (CIDR)
Classless Inter-Domain Routing was introduced in 1993 to replace the classful network design.
Instead of allocating network addresses using address classes based on 8 bit groups it uses variable length subnet masking.
It also introduced a new method of denoting network masks.
A class C network would have a subnet mask of 255.255.255.0 which means that 24 bits are used for the network.
In CIDR notation this is designated by a /24 following the IP address. So:
IP address 192.168.1.168 subnet mask 255.255.255.0 is written as: 192.168.1.168/24 in CIDR notation.
|Address Class||No of Network Bits||No of Host Bits||Subnet mask||CIDR notation|
- Write the IP address 126.96.36.199 mask 255.255.255.192 in CIDR notation
Decimal 192 =11000000 binary which means that 2 bits of this octet are used for the subnet. Now add the 24 bits 255.255.255 and we have 26 bits. So we write:
2. Write is the IP address 188.8.131.52 mask 255.255. 248.0 in CIDR notation
Decimal 248 =11111000 binary which means that 5 bits of this octet are used for the subnet. Now add the 16 bits 255.255. and we have 21 bits. So we write:
Simple Subnetting Exercise Questions
The best way to learn to do subnetting is to try some examples. We will look a some common subnetting problems that arise when creating networks.
1 – You have been allocated a class C network address of 184.108.40.206 how may hosts can you have?
2- You have been allocated a class A network address of 220.127.116.11. You need create at least 10 networks and each network will support a maximum of 100 hosts. Would the following two subnet masks Work.
255.255.0.0 and or 255.255.255.0
3 – You have been allocated a Class B network address of 18.104.22.168. You have subnetted it using the subnet mask 255.255.255.0 How many networks can you Have and how many hosts can you place on each network?
A1– 255-2= 254 – Why? host addresses of all 0’s and all 1’s are not allowed.
A2- Yes you only need 8 bits for 100 hosts and both subnet masks would give you that.
A subnet mask of 255.255.255.0 would give you lots of networks (2 16) and 254 hosts.
A subnet of 255.255.0.0 would give you lots of hosts (approx 216) and 256 networks.
A3 – the network has 8 bits and so does the node component. This means that you have have 28 =256 networks and 256 -2 = 254 hosts
Subnetting Class C Addresses
So far we have been subnetting on a byte boundary using class A and B addresses.
Now we are going to look at how we subnet on a non-byte boundary using a Class C Address.
Exercise- You have been allocated a class C network address of 22.214.171.124.
You need to create 5 sub networks each network has a maximum of 10 hosts.
Now our current subnet mask is 255.255.255.0
We can only use the first 8 bits for out subnets as these 8 bits have been allocated as host addresses.
So for 10 hosts we need 4 bits (16-2 =14 hosts)
for 5 subnets we need 3 bits (8 networks possible)
11100000=224 (Note: 3 bits for sub networks)
11110000=240 (Note: 4 bits for sub networks)
So Subnet masks of 255.255.255.224 and 255.255.255.240 would both work.
In CIDR notation we have 126.96.36.199/27 and 188.8.131.52/28
Subnet Table and Calculator
Below is a simple subnet table that makes it easier for calculating subnets.
There are also many online subnet calculators available like this one
Subnet Worked Examples
Test you knowledge using these online quizes
Related Tutorials and Resources: