TCP/IP Subnetting
- Jamie Tyler
- Network
- December 11, 2024
Table of Contents
If you’ve ever dived into networking or IT, you’ve likely come across the concept of subnetting. For many folks, subnetting can feel like a maze of numbers, acronyms, and rules. But once you understand the logic behind it, it becomes a lot easier to understand and do without using online calculators.
The Basics
Subnetting is the process of dividing a larger network into smaller, more manageable chunks called subnets. This helps improve network performance, enhance security, and make efficient use of IP addresses.
Each network is represented by a range of IP addresses defined using CIDR notation (Classless Inter-Domain Routing). For example, 192.168.1.0/24 refers to a network where the /24 indicates how many bits are allocated for the network portion of the address.
In this article I will cover the following.
- Converting /XX to a subnet mask e.g. /26
- Calculate useable TCP/IP addresses in a CIDR range
- Calculate the number of /XX subnets that can reside in a /YY
Converting /XX to the Subnet Mask
For this example, I am going to use /26 which is deliberate so it is a little messy. The steps are.
- Understand the CIDR notation
- Convert the network portion to binary
- Convert each octet to decimal
- Bring it all together
Understand the CIDR Notation
The /26 means that the first 26 bits are used for the network portion, and the remaining 6 bits are for hosts and subnet masks use binary 1s for network bits and 0s for host bits.
The subnet mask is segmented into 4 octets i.e. 8 bits per segment.
Convert the Network Potion to Binary
As only 6 bits are not part of the subnet mask, this means that only 2 bits of the last octet is part of the network. This would mean that the binary representation of the subnet mask would like.
11111111.11111111.11111111.11000000
Convert Each Octet to Decimal
Let’s understand how the decimal representation is derived.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
In decimal, this would be 128 + 64 = 192. If all were 1s then it would be 255, look familiar?
Split the binary subnet mask into four octets and convert each to decimal.
- 11111111 = 255
- 11111111 = 255
- 11111111 = 255
- 11000000 = 192
Bring it all Together
Therefore the subnet mask is 255.255.255.192.
Calculate useable TCP/IP Addresses in a CIDR Range
Again, for this example, I am going to use /26. The steps are.
- Identify the subnet mask
- Calculate the total addresses
- Calculate usable addresses
Identify the Subnet Mask
As before the subnet based on CIDR notation, like /26, tells me how many bits are used for the network portion of the address. In IPv4, an IP address is 32 bits long.
So the calculation is \(32 - x\). Where x is the number of bits in the network portion of the CIDR notation. So in the case of /26, the calculation is \(32 - 26 = 6\) bits.
Calculate the Total Addresses
The number of unique addresses in a subnet is 2 raised to the power of the number of host bits. So for the example I am using it is \(2^6 = 64\) IP addresses.
Calculate Usable Addresses
In a traditional IPv4 network, 2 addresses are reserved.
- Network address (first address in the range) for identifying the subnet itself
- Broadcast address (last address in the range) for network-wide communications
Therefore \(64 - 2 = 62\) usable IP addresses.
In AWS, 3 additional IP addresses are reserved in each subnet (on top of the two standard reserved addresses), bringing the total number of reserved addresses to 5.
- Network Address: The first IP address of the subnet (e.g., .0 in 10.0.0.0/26) is reserved to identify the network
- AWS Router Address: The second IP address in the subnet (e.g., .1 in 10.0.0.0/26) is used by AWS as the VPC router
- AWS DNS Server Address: The third IP address (e.g., .2 in 10.0.0.0/26) is reserved by AWS for DNS services
- Future AWS Use: The fourth IP address (e.g., .3 in 10.0.0.0/26) is reserved for potential future use by AWS
- Broadcast Address: The last IP address in the subnet (e.g., .64 in 10.0.0.0/26) is reserved for broadcast communication within the subnet
Therefore \(64 - 5 = 59\) usable IP addresses.
Calculate the Number of /XX Subnets that can Reside in a /YY
So for this example I am trying to calculate how many /26 subnets are available in a /22 supernet. The Steps are.
- Calculate the total number of IP addresses in a /22 supernet
- Calculate the number of IP addresses in a /26 subnet
- Determine how many /26 subnets fit into a /22 supernet
Calculate the Total Number of IP Addresses in a /22 Supernet
A /22 subnet has 10 bits available for host addresses \(32 - 22 = 10\). So the total number of IP addresses in a /22 is \(2^{10} = 1024\).
Calculate the Number of IP Addresses in a /26 Subnet
A /26 subnet has 6 bits for host addresses \(32 - 26 = 6\). So the total number of IP addresses in a /26 is \(2^{6} = 64\).
Determine How Many /26 Subnets Fit into a /22 Supernet
\({1024 \over 64} = 16\). Therefore there are 16 /26 subnets in a /22 supernet.
Conclusion
The calculations above come in handy when designing an IP schema for the new deployment in AWS especially when using the AWS VPC IPAM solution. Going from the organisational level, to the region, SDLC environments, VPCs and subnets for each availability zone.