Subnetting
In computer networking, a subnet (short for "subnetwork") is a logical subdivision of an IP network. Subnetting allows you to divide a larger network into smaller, more manageable segments. This is done using a subnet mask, which defines the boundaries of the subnet.
Key Concepts:
IP Address: An IP address (e.g.,
192.168.1.1) is a unique identifier for a device on a network. It consists of two parts:Network portion: Identifies the network.
Host portion: Identifies the specific device within the network.
Subnet Mask: A subnet mask (e.g.,
255.255.255.0) is used to determine which part of the IP address is the network portion and which part is the host portion. It is a 32-bit number, typically written in dotted-decimal notation (like an IP address).The
1s in the subnet mask represent the network portion.The
0s represent the host portion.
For example:
IP Address:
192.168.1.1Subnet Mask:
255.255.255.0This means the first 24 bits are the network portion (
192.168.1), and the last 8 bits are the host portion (1).
CIDR Notation: Subnets are often represented using Classless Inter-Domain Routing (CIDR) notation, which combines the IP address and the subnet mask into a single format. For example:
192.168.1.0/24means the subnet mask is255.255.255.0(24 bits for the network portion).
Subnetting: Subnetting involves borrowing bits from the host portion of the IP address to create smaller subnets. For example:
A
/24subnet (255.255.255.0) allows for 256 IP addresses (254 usable for hosts).A
/26subnet (255.255.255.192) allows for 64 IP addresses (62 usable for hosts).
Example:
IP Address:
192.168.1.0Subnet Mask:
255.255.255.0(or/24in CIDR notation)Network Address:
192.168.1.0Usable Host Range:
192.168.1.1to192.168.1.254Broadcast Address:
192.168.1.255
Why Subnetting?
Efficient use of IP addresses: Prevents wasting IP addresses.
Improved network performance: Reduces congestion by limiting broadcast domains.
Enhanced security: Isolates network segments.
How to calculate the subnet mask:
Calculating a subnet mask involves determining how many bits are allocated to the network portion and how many are left for the host portion of an IP address. Here's a step-by-step guide to calculating a subnet mask:
1. Understand CIDR Notation
CIDR (Classless Inter-Domain Routing) notation represents the subnet mask in the format
IP Address/Prefix Length. For example:192.168.1.0/24means the first 24 bits are the network portion, and the remaining 8 bits are for hosts.The prefix length (
/24) directly corresponds to the number of1s in the subnet mask.
2. Convert Prefix Length to Subnet Mask
A subnet mask is a 32-bit number, written in dotted-decimal notation (e.g.,
255.255.255.0).Each
1in the subnet mask represents a bit in the network portion, and each0represents a bit in the host portion.
Example:
For
/24:The first 24 bits are
1s, and the last 8 bits are0s.In binary:
11111111.11111111.11111111.00000000In decimal:
255.255.255.0
3. Use a Subnet Mask Chart
Here’s a quick reference chart for common subnet masks:
/24
255.255.255.0
254
/25
255.255.255.128
126
/26
255.255.255.192
62
/27
255.255.255.224
30
/28
255.255.255.240
14
/29
255.255.255.248
6
/30
255.255.255.252
2
4. Calculate Subnet Mask Manually
If you need to calculate a subnet mask for a specific number of hosts or subnets, follow these steps:
Step 1: Determine the Number of Hosts or Subnets
Decide how many hosts or subnets you need.
Use the formula:
Number of hosts = 2(32−Prefix Length)−22(32−Prefix Length)−2
Number of subnets = 2(Prefix Length−Original Prefix Length)2(Prefix Length−Original Prefix Length)
Step 2: Find the Prefix Length
For hosts:
Calculate the number of host bits required: Host Bits=log2(Number of Hosts+2)Host Bits=log2(Number of Hosts+2).
Subtract the host bits from 32 to get the prefix length.
For subnets:
Calculate the number of subnet bits required: Subnet Bits=log2(Number of Subnets)Subnet Bits=log2(Number of Subnets).
Add the subnet bits to the original prefix length.
Step 3: Convert Prefix Length to Subnet Mask
Use the prefix length to determine the subnet mask (as shown in Step 2).
5. Example Calculations
Example 1: Calculate Subnet Mask for 60 Hosts
You need at least 60 usable hosts.
Use the formula: 2(32−Prefix Length)−2≥602(32−Prefix Length)−2≥60.
Solve for the prefix length:
2(32−Prefix Length)≥622(32−Prefix Length)≥62.
32−Prefix Length=632−Prefix Length=6 (since 26=6426=64).
Prefix Length = 32−6=2632−6=26.
Subnet Mask:
/26or255.255.255.192.
Example 2: Calculate Subnet Mask for 4 Subnets
You need 4 subnets from a
/24network.Use the formula: 2(Prefix Length−24)≥42(Prefix Length−24)≥4.
Solve for the prefix length:
Prefix Length−24=2Prefix Length−24=2 (since 22=422=4).
Prefix Length = 24+2=2624+2=26.
Subnet Mask:
/26or255.255.255.192.
6. Tools for Subnetting
Use online subnet calculators or tools like:
Last updated