IPv4 Subnetting
A quick guide on subnetting an IPv4 network
What is a subnet?
Internet Protocol version 4 (IPv4) addressing only allows for a 32-bit, or 4-byte address. In binary, this address would be represented as:
11111111.11111111.11111111.11111111
4 contiguous bytes, or 32 bits
However, IPv4 is expressed in decimal format. So, the translation of the address above would be 255.255.255.255
Because of this format, there are only a little under 4.3 billion addresses possible. Subnets come into play in order to segment and expand IP networks, allowing for way more than 4.3 billion devices to connect to the internet via IPv4. This is possible, because subnetting can split an IPv4 network into two or more subnets that can allow for multiple hosts on multiple subnets, while only reserving a single IPv4 address.
This is what has kept IPv4 dominant in expanding the internet for the decades it has been around. Most networks and devices rely on IPv4 addressing, although IPv6 is a slight update, it is still not as widely adopted or in use.
Why subnet a network?
Being able to segment a single network into multiple subnets allows for even greater precision in handling the traffic that goes through it. Subnetting also allows for scalability as a network grows, enabling more hosts to join and use the network with ease.
Because of the added precision, one huge benefit is reducing the congestion of traffic. For example, if a broadcast were to be sent to every single host every single time, a network would be overloaded very quickly; however, if it is within the limited domain of a single subnet, only the relevant devices would be receiving the broadcast, freeing up the channels of the network for other traffic.
From a security standpoint, subnetting is a huge benefit. Being able to partition a network and control the traffic between the segments greatly maximizes the network’s ability to filter traffic, perform access control, and even reduce the amount of harm done to machines within the entire network.
How do you subnet an IPv4 network?
Binary Calculations
If you’re unfamiliar with counting in binary, keep in mind that IPv4 addresses contain 32-bits in a contiguous 4-byte format. Here is the decimal value in relation to a binary value postured within one byte.
Simply the sums of the powers of 2, calculated positionally. If there is a 1, keep in mind the position and add each decimal value that corresponds with it.
So, for example: Given 10010101
10010101 = 128 + 0 + 0 + 16 + 0 + 4 + 0 + 1 = 149
Subnet Mask
A subnet mask is used in conjunction with an IPv4 address to determine which subnet a particular device is connected to within a network. The subnet mask also provides four critical pieces of information about each subnet. This includes:
The network’s IP address
The first available host IP on the subnet
The last available host IP on the subnet
The subnet’s broadcast IP
Note: Classful Subnetting
Based on the first bits of an IP address, we can calculate how many bits are allocated for the network, and for the host.
Class A
leading IP bits: 1–126 have a subnet mask of 255.0.0.0, meaning there are 8 bits for the network and 24 bits for the host.
Class B
leading IP bits: 128–191 have a subnet mask of 255.255.0.0, meaning there are 16 bits for the network and 16 bits for the host.
Class C
leading IP bits: 192–223 have a subnet mask of 255.255.255.0, meaning there are 24 bits for the network and 8 bits for the host.
Classless Interdomain Routing (CIDR) Block Notation
While subnets may be represented in classes, it isn’t quite as precise as we would need subnetting to be in order to really tailor a network. CIDR block notation allows you to allocate specific chunks of the address for the network, subnet, and host.
Given a Class A subnet mask (255.0.0.0), in binary this would be: 11111111.00000000.00000000.00000000
in CIDR block notation, this would simply be a /8, representing 8 bytes allocated for the network
Therefore, a class A IP address and subnet mask could be something like:
17.0.0.0/8
Calculating Subnets and Hosts
CIDR block notation allows for classless subnetting in which we are not confined to the classes and can allocate as many bytes as we want in order to subnet a network, based on its needs.
In order to find the amount of subnets, we find 2 ** subnet bits
In order to find the amount of hosts per subnet, we find (2 ** host bits)-2
“**” represents finding the power, and we subtract 2 from the host bits, because one address is reserved for the network and the other is reserved for the broadcast IP
For example, you are given an IP address of 192.168.1.0/26:
This is a Class C IP address, meaning there are 24 bits allocated for the network id. Since the CIDR Block value indicates 26, this means that there are 2 bits left for the subnet, and 6 for the host. (24 + 2 + 6 = 32 bits total)
Amount of subnets = 2 ** 2 = 4 subnets in this network
Amount of hosts per subnet = (2 ** 6)-2 = 62 hosts per subnet
We purposely subtracted two from the amount of hosts from the amount of hosts per subnet, because there are two reserved addresses within the ranges of hosts available. Setting all the host bits to 0 represents the network ID, and setting all the host bits to 1 represents the subnet’s broadcast IP. So, for the example above:
We have already calculated that there are 4 subnets with 62 hosts per subnet on this network, so the host’s IP bits lie within the ranges of
0–63 on subnet 1
64–127 on subnet 2
128–191 on subnet 3
192–255 on subnet 4
Notice how I explained that the hosts lie WITHIN the ranges of these numbers. These numbers are the boundaries, meaning they are exclusive from the available host IP’s; therefore, on subnet 1:
Network ID: 192.168.1.0
Broadcast IP: 192.168.1.63
Available Host IP’s: 192.168.1.1–62
And so on and so forth for each subnet…
Subnetting is an especially tricky topic and takes a lot of practice to familiarize yourself with and eventually master. I hope this article provided a good overview on the subject. Thank you for reading, and let me know if you learned something useful here: www.linkedin.com/in/colton-gabertan-463836209 !