TCP/IP Subnetting

TCP/IP Subnetting

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.

  1. Understand the CIDR notation
  2. Convert the network portion to binary
  3. Convert each octet to decimal
  4. 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.

1286432168421
11000000

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.

  1. Identify the subnet mask
  2. Calculate the total addresses
  3. 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.

  1. Network Address: The first IP address of the subnet (e.g., .0 in 10.0.0.0/26) is reserved to identify the network
  2. 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
  3. AWS DNS Server Address: The third IP address (e.g., .2 in 10.0.0.0/26) is reserved by AWS for DNS services
  4. Future AWS Use: The fourth IP address (e.g., .3 in 10.0.0.0/26) is reserved for potential future use by AWS
  5. 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.

  1. Calculate the total number of IP addresses in a /22 supernet
  2. Calculate the number of IP addresses in a /26 subnet
  3. 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.

Related Posts

How to use a Password Manager to Store AWS Credentials

How to use a Password Manager to Store AWS Credentials

I like to have a way of avoiding having to have access_key_ids and secret_access_keys locally configured on my Mac.

Read More
The AWS re:Invent 2024 Experience

The AWS re:Invent 2024 Experience

This was not the first time I had been to re:Invent and things have changed over the years. This is true of Las Vegas and re:Invent. In person, this is the third time with another time being the virtual event when the Covid pandemic was at its height.

Read More
Using AWS to Host a Static Website - Part 4

Using AWS to Host a Static Website - Part 4

In part 3 I walked through the creation of the Amazon S3 bucket where the static website content will reside. In this post I will walk through using CloudFormation to create an Amazon Route 53 public hosted zone. This is automatically created when a domain is registered using Amazon Route 53 so this is for completeness and is not required for this series of posts.

Read More