How to Calculate Subnets

Subnetting is an essential concept for managing IP addresses efficiently in a network. It allows you to split large networks into smaller subnets to manage traffic and increase security. Understanding how to calculate subnets and hosts is key to subnetting, and it’s important to understand how subnet masks work in this process.

Let’s break down how to calculate subnets and hosts in detail.


Understanding the Subnet Mask in Calculation

A subnet mask is a 32-bit number used to divide the IP address into two parts: the network part and the host part. The network part of the address is used to identify the subnet, while the host part is used for individual devices within that subnet.

When you perform a subnetting calculation, you're essentially determining how many bits will be used for the network portion and how many will be left for the host portion.

The formula for a subnet mask looks like this:

  • Network Address = IP Address AND Subnet Mask (using the bitwise AND operation)

Steps to Calculate Subnets and Hosts

1. Classify the IP Address

The first step in subnetting is identifying the class of the IP address:

  • Class A: 1.0.0.0 to 127.255.255.255, default subnet mask 255.0.0.0 or /8
  • Class B: 128.0.0.0 to 191.255.255.255, default subnet mask 255.255.0.0 or /16
  • Class C: 192.0.0.0 to 223.255.255.255, default subnet mask 255.255.255.0 or /24

For example, if your IP address is 192.168.1.10, it's a Class C IP address, and the default subnet mask is 255.255.255.0.


2. Determine the Subnet Mask

To begin subnetting, you need to decide how many subnets you want to create or how many host addresses you need in each subnet. This decision will dictate how many bits you borrow from the host portion of the address to extend the network portion.

For example, if you have a Class C IP address (192.168.1.0/24) and you want to create more subnets, you can borrow bits from the host part of the IP address.



3. Borrowing Bits for More Subnets

To borrow bits from the host portion, you extend the network part of the IP address. The more bits you borrow, the more subnets you create, but fewer hosts will be available per subnet.

Let’s take an example:

  • Original Subnet Mask for Class C: 255.255.255.0 (or /24).
  • You want 4 subnets: To create 4 subnets, you need to borrow 2 bits from the host portion.

Now, the subnet mask will change to /26, which is 255.255.255.192. This means:

  • The first 26 bits are used for the network portion.
  • The last 6 bits are used for the host portion.


4. Calculate the Number of Subnets and Hosts

To calculate the number of subnets and number of hosts available after subnetting, we use the following formulas:

  • Number of Subnets = 2^n (where n is the number of bits borrowed)
  • Number of Hosts per Subnet = 2^h - 2 (where h is the number of bits remaining for the host portion; subtract 2 to account for the network address and the broadcast address)

Example 1:

  • Given: A Class C IP address (192.168.1.0/24) and you borrow 2 bits for subnetting.
  • New Subnet Mask: /26 or 255.255.255.192
    • Number of Subnets: 2^2 = 4 subnets
    • Number of Hosts per Subnet: 2^6 - 2 = 62 hosts per subnet


So, with a /26 subnet mask:

  • You can create 4 subnets.
  • Each subnet can have 62 hosts.

Example 2:

  • Given: A Class B IP address (172.16.0.0/16) and you borrow 4 bits for subnetting.
  • New Subnet Mask: /20 or 255.255.240.0
    • Number of Subnets: 2^4 = 16 subnets
    • Number of Hosts per Subnet: 2^12 - 2 = 4094 hosts per subnet

With a /20 subnet mask:

  • You can create 16 subnets.
  • Each subnet can have 4094 hosts.



5. Subnet Calculation Example with CIDR Notation

Let’s walk through a full example where we want to calculate the subnets for a Class C network:

Given:

  • IP Address: 192.168.1.0/24
  • Desired number of subnets: 4

Steps:

  1. Determine how many bits to borrow:
    • To create 4 subnets, we borrow 2 bits from the host portion of the IP address (/24 becomes /26).

  2. Determine the new subnet mask:
    • The new subnet mask will be /26 or 255.255.255.192.

  3. Calculate the number of subnets:
    • 2^2 = 4 subnets.

  4. Calculate the number of hosts per subnet:
    • 2^6 - 2 = 62 hosts per subnet.

Subnet Breakdown:

Subnet Number Subnet Address Usable IP Range Broadcast Address Subnet Mask
1 192.168.1.0 192.168.1.1 - 192.168.1.62 192.168.1.63 255.255.255.192
2 192.168.1.64 192.168.1.65 - 192.168.1.126 192.168.1.127 255.255.255.192
3 192.168.1.128 192.168.1.129 - 192.168.1.190 192.168.1.191 255.255.255.192
4 192.168.1.192 192.168.1.193 - 192.168.1.254 192.168.1.255 255.255.255.192


Subnetting Formula Summary

  • Number of Subnets = 2^n (where n is the number of bits borrowed from the host portion).
  • Number of Hosts per Subnet = 2^h - 2 (where h is the number of bits remaining for the host portion; subtract 2 for the network and broadcast addresses).


Conclusion

Subnetting helps network administrators efficiently utilize IP addresses, organize networks, and improve network performance and security. By understanding how to calculate subnets, determine the number of available hosts, and choose the right subnet mask, you can optimize the way IP addresses are allocated across networks.

Post a Comment

Previous Post Next Post