IPv4 Subnetting

Introduction

As computer networks grow, managing IP addresses efficiently becomes increasingly important. IPv4 subnetting is a fundamental networking technique that helps network administrators divide large networks into smaller, more manageable segments called subnets.

Whether you’re preparing for networking certifications, managing enterprise networks, or simply learning how the Internet works, understanding subnetting is an essential skill.

This guide explains IPv4 subnetting, the formulas involved, and practical examples to help you master the concept.


Why Do We Need Subnetting?

Without subnetting, all devices would exist within a single large network, leading to:

  • Increased broadcast traffic that can lead to network congestion and unnecessary use of bandwidth.
  • Reduced performance may occur as a larger network experiences higher levels of traffic and communication overhead.
  • Poor network management makes it more difficult for administrators to monitor, troubleshoot, and maintain the network effectively.
  • Security challenges arise because a larger network provides more opportunities for unauthorized access and the spread of security threats.
  • Inefficient IP address allocation can result in wasted address space and difficulties in managing network resources.

Subnetting solves these issues by dividing a network into smaller logical networks.

Benefits include:

  • Better network performance is achieved by reducing broadcast traffic and limiting network congestion.
  • Improved security is provided by separating devices into different subnets, making it easier to control access and contain threats.
  • Efficient IP utilization allows IP addresses to be allocated according to the specific needs of each subnet, reducing waste.
  • Easier troubleshooting is possible because network issues can be isolated to a specific subnet, making diagnosis and resolution faster.
  • Simplified network management helps administrators organize, monitor, and maintain the network more effectively.

Components Required to Calculate Subnetting

  • An IP address uniquely identifies a device on a network and enables communication between devices.
  • A subnet mask is used to distinguish the network portion of an IP address from the host portion.
  • The prefix length indicates the number of bits allocated to the network portion of an IP address and is represented using CIDR notation (e.g., /24).
  • The number of subnet bits borrowed from the host portion determines how many subnets can be created within a network.
  • The number of subnets is calculated based on the number of borrowed bits using the formula 2n2^n2n, where nnn is the number of subnet bits.
  • The number of hosts per subnet is determined by the remaining host bits and is calculated using the formula 2h22^h – 2, where hh the number of host bits.

Once the above information is gathered or calculated from the given IP address, we can easily calculate the following:

  • New subnet mask
  • Number of subnets
  • Number of hosts per subnet
  • Network address
  • First usable host address
  • Last usable host address
  • Broadcast address
  • Block Size of IP Address Range

Key Subnetting Formulas

  • Number of Subnets = 2ⁿ, where n is the number of bits borrowed from the host portion.
  • Number of Hosts per Subnet = 2h – 2, where h is the number of host bits remaining after borrowing. The first and the last IP addresses are not included in the valid host IP address range. The first one is the network address, and the last one is the broadcast address.
  • Block Size = 256 – Last Octet of Subnet Mask

These three formulas solve most subnetting problems.

Subnetting is the process of dividing a larger IP network into smaller, more manageable sub-networks (subnets). Here’s a clear example to help you understand it step by step.


Example of Subnetting a Class C Network

Create 4 subnets from the following network.

Let’s start with this network:

  • IP address: 192.168.1.0
  • Default subnet mask: 255.255.255.0 (/24)

This means:

  • Total IP addresses = 256 (from 192.168.1.0 to 192.168.1.255) using default subnet mask

To create 4 subnets:

  • Use the formula: No of Subnets = ( 2n ) = ( 24 )
  • So, 2 host bits to be borrowed by the network portion.
  • The new network bits : 24 + 2 = 26
  • The new subnet mask : 11111111.11111111.11111111.11000000 = 255.255.255.192
  • Now, the remaining host bit : (32 – 26) = 6 host bits
  • Hence, the no. of hosts per subnets = ( 26 ) = 64

Each subnet will have the IP range as shown below.

SubnetsNetwork AddressUsable IP RangeBroadcast Address
1192.168.1.0192.168.1.1
to
192.168.1.62
192.168.1.63
2192.168.1.64192.168.1.65
to
192.168.1.126
192.168.1.127
3192.168.1.128192.168.1.129
to
192.168.1.190
192.168.1.191
4192.168.1.192192.168.1.193
to
192.168.1.254
192.168.1.25

Variable Length Subnet Masking (VLSM)

VLSM (Variable Length Subnet Mask) is a subnetting technique that allows you to use different subnet masks for different subnets within the same network. This helps use IP addresses more efficiently.

Why VLSM is needed

With traditional subnetting (fixed-length subnet mask), all subnets must be the same size, even if some need only a few hosts and others need many.

VLSM Rules

  1. Start with the largest host requirement.
  2. Assign the appropriate subnet.
  3. Move to the next available address block.
  4. Continue until all requirements are met.

A common formula used when designing VLSM is:

2h – 2 >= Required Hosts

where h is the number of host bits and -2 indicates the network address and broadcast address

Example:

  • Department A needs 100 hosts
  • Department B needs 50 hosts
  • Department C needs 10 hosts

Using the same subnet mask for all three wastes many IP addresses.

With VLSM:

  • Department A gets a larger subnet.
  • Department B gets a medium subnet.
  • Department C gets a smaller subnet.

Example

Suppose you have the network:

192.168.1.0/24

Requirements: You need three different subnets:

  • Department A with 100 hosts
  • Department B with 50 hosts
  • Department C with 25 hosts

Use the following formula to calculate number of host bits required to

2h−2 ≥ Required Hosts

The following table contains binary-to-decimal conversions and will be of great help while calculating the required host bits for each subnet.

2827262524272221
256128643216842

Step 1: Allocate the largest subnet first

For a department A with 100 hosts

2h−2 ≥ 100

or 27−2 ≥ 100

Using 7 host bits, the maximum host address available will be given by 27 = 128 hosts

Hence, the available network bits will be 32 – 7 = 25

The new subnet for Department A:

  • The network ID will be 192.168.1.0/25
  • The new subnet mask will be 11111111.11111111.11111111.10000000 = 255.255.255.128
  • Block size = 256 – 128 = 128
  • Host range is from 192.168.1.0 to 192.168.0.127
  • Network address = 192.168.1.0
  • Broadcast address = 192.168.1.127
  • Usable host range:192.168.1.1 – 192.168.1.126

Step 2: Allocate the next largest subnet

For a department B with 50 hosts

2h−2 ≥ 50

or 26−2 ≥ 50

Using 6 host bits, the maximum host address available will be given by 26 = 64 hosts

Hence, the available network bits will be 32 – 6 = 26

The new subnet for Department B:

  • The network ID will be 192.168.1.128/26
  • The new subnet mask will be 11111111.11111111.11111111.11000000 = 255.255.255.192
  • Block size = 256 – 192 = 64
  • Host range is from 192.168.1.128 to 192.168.0.191
  • Network address = 192.168.1.128
  • Broadcast address = 192.168.1.191
  • Usable host range:192.168.1.128 – 192.168.1.190

Step 3: Allocate the smallest subnet

For a department C with 25 hosts,

2h−2 ≥ 50

or 26−2 ≥ 25

Using 5 host bits, the maximum host address available will be given by 25 = 32 hosts

Hence, the available network bits will be 32 – 5 = 27

The new subnet for Department B:

  • The network ID will be 192.168.1.192/26
  • The new subnet mask will be 11111111.11111111.11111111.11100000 = 255.255.255.224
  • Block size = 256 – 224 = 32
  • Host range is from 192.168.1.192 to 192.168.0.223
  • Network address = 192.168.1.192
  • Broadcast address = 192.168.1.223
  • Usable host range: 192.168.1.193 – 192.168.1.222
Dept ADept BDept C
No of Hosts1005025
Host Bit Required765
Maximum host Range1286432
IP Address Range192.168.1.0
to
192.168.1.127
192.168.1.128
to
192.168.1.191
192.168.1.192
to
192.168.1.223
Valid Host Range192.168.1.1
to
192.168.1.126
192.168.1.129
to
192.168.1.190
192.168.1.193
to
192.168.1.222
Subnet mask 255.255.255.128255.255.255.192255.255.255.224

Subnetting a Class B Address

A Class B IP address uses the default subnet mask:

  • Default Mask: 255.255.0.0
  • CIDR Notation: /16

Suppose we have:

  • Network Address: 172.16.0.0/16

Now we want to create 4 subnets out of the given Class B address.

To create 4 subnets:

  • 2 bits be borrowed from the host portion.
  • Number of subnets = 2n = 4 , where n=2 is the subnet bits borrowed from the host portion.
  • Now, the new subnet mask will be 16 +2 = 18 ( network bits)
  • In binary, written as 11111111 . 11111111 . 11000000 . 00000000
  • New Subnet mask for all subnets = 255.255.192.0

The subnet ranges are:

  • 1st subnet = 172.16.0.0 to 172.16.63.255
  • 2nd subnet = 172.16.64.0 to 172.16.127.255
  • 2nd subnet = 172.16.128.0 to 172.16.191.255
  • 2nd subnet = 172.16.192.0 to 172.16.63.255

The network address, broadcast address, and the valid host range are

SubnetNetwork AddressHost RangeBroadcast Address
1172.16.0.0/18172.16.0.1
to
172.16.63.254
172.16.63.255
2172.16.64.0/18172.16.64.1 to
172.16.127.254
172.16.127.255
3172.16.128.0/18172.16.128.1 to
172.16.191.254
172.16.191.255
4172.16.192.0/18172.16.192.1 to
172.16.255.254
172.16.255.255

Quick Reference Table for Class B Address

The following table is of great help while subnetting the Class B address.

CIDRSubnet MaskNumber of SubnetsHosts/Subnet
/17255.255.128.0232766
/18255.255.192.0416382
/19255.255.224.088190
/20255.255.240.0164094
/21255.255.248.0322046
/22255.255.252.0641022
/23255.255.254.0128510
/24255.255.255.0256254

Subnetting in Class A Address

A Class A IP address uses the default subnet mask:

  • Default Mask: 255.0.0.0
  • CIDR Notation: /8

Suppose we have:

  • Network Address: 10.0.0.0/8

Now we want to create 4 subnets out of the given Class A address.

To create 4 subnets:

  • 2 bits are borrowed from the host portion.
  • Number of subnets = 2n = 4 , where n=2 is the subnet bits borrowed from the host portion.
  • Now, the new subnet mask will be 8 +2 = 10 ( network bits)
  • In binary, written as 11111111 . 11000000 . 00000000 . 00000000
  • New Subnet mask for all subnets = 255.192.0.0

The subnet ranges are:

  • 1st subnet = 10.0.0.0 to 10.63.255.255
  • 2nd subnet = 10.64.0.0 to 10.127.255.255
  • 2nd subnet = 10.128.0.0 to 10.191.255.255
  • 2nd subnet = 10.192.0.0 to 10.255.255.255

The network address, broadcast address, and the valid host range are

SubnetNetwork AddressHost RangeBroadcast Address
110.0.0.0/1010.1.0.0 to 10.63.255.25410.63.255.255
210.64.0.0/1010.64.0.1 to 10.127.255.25410.127.255.255
310.128.0.0/10110.128.0.1 to 10.191.255.25410.191.255.255
410.192.0.0/1010.192.0.1 to 10.255.255.25410.255.255.255

Quick Reference Table for Class A Address

CIDRSubnet MaskSubnetsHosts/Subnet
/9255.128.0.028,388,606
/10255.192.0.044,194,302
/11255.224.0.082,097,150
/12255.240.0.0161,048,574
/13255.248.0.032524,286
/14255.252.0.064262,142
/15255.254.0.0128131,070
/16255.255.0.025665,534

Leave a Comment