Examining IPv4 Subnets
What is a Subnet?
A subnet, or subnetwork, is a smaller, distinct network within a larger network. It divides a larger network into smaller, manageable segments. This is particularly useful for organizing a network, improving performance, and enhancing security.
Key Components of Subnets
- IP Address: Each device on a network is assigned a unique identifier known as an IP address (e.g., 192.168.1.1).
- Subnet Mask: A subnet mask determines which part of the IP address refers to the network and which part refers to the host. For example, in the subnet mask 255.255.255.0, the first three octets identify the network, while the last octet identifies individual hosts.
- CIDR Notation: Subnets can also be represented in CIDR (Classless Inter-Domain Routing) notation (e.g., /24), indicating the number of bits used for the network portion of the address.
How Subnets are Used
- Network Organization: Subnets help organize a large network into smaller, logical groups. For example, a company might have different subnets for different departments (e.g., HR, Sales, Engineering), which makes it easier to manage and troubleshoot.
- Improved Performance: By segmenting a network into subnets, broadcast traffic is limited to each subnet. This reduces network congestion and improves overall performance.
- Enhanced Security: Subnets can help contain security breaches. For example, if one subnet is compromised, it can be isolated from others, preventing the spread of a security issue across the entire network.
- Efficient IP Address Management: Subnetting allows organizations to use their IP address space more efficiently. Instead of having a flat network, addresses can be allocated based on specific needs.
- Routing: Routers use subnet information to direct traffic. When a packet is sent, routers use the subnet information in the destination IP address to determine the best path for delivery.
Class A, B, and C IP Addresses and CIDR Notation
IP addresses are categorized into different classes to support various types of networks and their requirements. The most common IP address classes are Class A, Class B, and Class C. Each class defines a range of IP addresses, the default subnet mask, and how the address is divided into network and host portions.
1. Class A IP Addresses
- Range: 1.0.0.0 to 126.255.255.255
- Default Subnet Mask: 255.0.0.0
- CIDR Notation: /8 (the first 8 bits are for the network, the remaining 24 bits are for hosts)
Class A networks are designed for very large networks because they have a large number of host bits available. The first octet (8 bits) is used to identify the network, and the remaining 24 bits are used for host addresses within that network.
Example:
- IP Address: 10.0.0.0
- Subnet Mask: 255.0.0.0 (/8 in CIDR notation)
- Number of Hosts: 2(32-8)-2 = 16,777,214
2. Class B IP Addresses
- Range: 128.0.0.0 to 191.255.255.255
- Default Subnet Mask: 255.255.0.0
- CIDR Notation: /16 (the first 16 bits are for the network, the remaining 16 bits are for hosts)
Class B networks are used for medium to large-sized networks. The first two octets (16 bits) represent the network portion, and the remaining two octets (16 bits) represent the host portion.
Example:
- IP Address: 172.16.0.0
- Subnet Mask: 255.255.0.0 (/16 in CIDR notation)
- Number of Hosts: 2(32-16)-2 = 65534
3. Class C IP Addresses
- Range: 192.0.0.0 to 223.255.255.255
- Default Subnet Mask: 255.255.255.0
- CIDR Notation: /24 (the first 24 bits are for the network, the remaining 8 bits are for hosts)
Class C networks are used for smaller networks. The first three octets (24 bits) represent the network, and the last octet (8 bits) is used for the host portion.
Example:
- IP Address: 192.168.1.0
- Subnet Mask: 255.255.255.0 (/24 in CIDR notation)
- Number of Hosts: 2(32-24)-2 = 254
Class D and E IP Addresses
4. Class D IP Addresses
- Range: 224.0.0.0 - 239.255.255.255
- Default Subnet Mask: (none)
IP address belonging to class D is reserved for multicasting. The higher-order bits of the first octet of IP addresses belonging to class D is always set to 1110. The remaining bits are for the address that interested hosts recognize.
4. Class E IP Addresses
- Range: 240.0.0.0 - 255.255.255.255
- Default Subnet Mask: (none)
IP addresses belonging to class E are reserved for experimental and research purposes.
What happened to the 127.0.0.0 network?
The 127.0.0.0 network is reserved for loopback and localhost functions, which is why it doesn't fall under any classful IP address scheme for typical network use. This range is used for special purposes rather than communication over a network.
- Range: 127.0.0.0 to 127.255.255.255
- Purpose: Loopback or localhost (used to test network software locally)
- Loopback Address: Typically, 127.0.0.1 is the most commonly used loopback address, but any address within the 127.0.0.0/8 range can technically be used for loopback purposes.
How the Loopback Address Works:
- When a computer uses a loopback address (such as 127.0.0.1), the traffic is directed back to itself, bypassing any physical network hardware like routers or switches.
- It is used to test network software (e.g., web servers, database servers, etc.) on the local machine without needing to connect to an external network.
Key Characteristics:
- 127.0.0.1 is the most commonly used loopback address, and it is often referred to as "localhost."
- The loopback network provides an IP address that always points back to the host device itself, so network services can be tested locally without affecting the wider network.
- Since this range is reserved for internal use, no traffic with a destination IP in the 127.x.x.x range will ever leave the host device. All communications in this range remain internal to the system.
CIDR Notation (Classless Inter-Domain Routing)
CIDR (Classless Inter-Domain Routing) was introduced to replace the rigid class system and provide more flexibility in IP address allocation. It allows network administrators to specify any number of bits for the network and host portions, not just the fixed /8, /16, and /24 boundaries.
CIDR notation represents the IP address and its associated routing prefix. It is written as an IP address, followed by a forward slash /
, and then the number of bits used for the network portion.
CIDR Components:
- Network Bits: The number of bits used for the network portion (can range from 1 to 31).
- Host Bits: The remaining bits used for hosts.
Example:
- IP Address: 192.168.10.0 / 28
- Subnet Mask: 255.255.255.240 (equivalent to /28 in CIDR notation)
- Number of Hosts: 2(32-28)-2 = 14
This notation is flexible and allows the creation of subnets of different sizes, which is useful for efficient IP address management.
Comparison of Classful vs CIDR Notation
In traditional classful addressing, the IP address classes (A, B, C) and subnet masks were fixed:
- Class A: /8 subnet mask (255.0.0.0)
- Class B: /16 subnet mask (255.255.0.0)
- Class C: /24 subnet mask (255.255.255.0)
With CIDR, we can create more specific subnets, for example:
- 192.168.1.0/25: Provides a subnet mask of 255.255.255.128, splitting a typical Class C network into two smaller subnets, each allowing 126 hosts.
- 172.16.0.0/18: Provides a subnet mask of 255.255.192.0, allowing more hosts within a single subnet than the default Class B allocation.
CIDR Benefits:
- Efficient IP Address Utilization: By using CIDR, we can allocate IP addresses according to the actual size of the network, avoiding waste.
- Flexible Subnetting: Networks of any size can be created, which is essential for efficient use of IP address space in large or complex networks.
Summary Table of Classes and CIDR Notation
Class | Range of IP Addresses | Default Subnet Mask | CIDR Notation | Host Range |
---|---|---|---|---|
A | 1.0.0.0 - 126.255.255.255 | 255.0.0.0 | /8 | 16,777,214 hosts |
B | 128.0.0.0 - 191.255.255.255 | 255.255.0.0 | /16 | 65,534 hosts |
C | 192.0.0.0 - 223.255.255.255 | 255.255.255.0 | /24 | 254 hosts |
Flexible (e.g., 192.168.0.0/27) | Variable | Variable (e.g., /27) | Any number of hosts/subnets |
This flexibility provided by CIDR allows for better management and scalability of IP address space in modern networking environments.
With all this being said, let's see how to calculate the number of hosts and the number of networks available.
Calculating the Number of Hosts (IPv4)
The number of hosts is determined by the number of bits left for the host portion of the address.
Steps:
- Identify the number of host bits: 32-CIDR prefix length
- Calculate the number of hosts: 2host bits-2
The "-2" is necessary because one address is reserved for the network address and one for the broadcast address.
Example:
- CIDR Address: 192.168.1.0/24
- Number of Network Bits: 24
- Number of Host bits: 32-24=8
- Number of Hosts:28-2 = 256-2 = 254
There are 254 usable hosts in this subnet.
Calculating the Number of Networks (Subnets)
The number of subnets depends on the subnet bits created by CIDR. CIDR allows flexibility in subnetting by creating subnet bits, which are the bits between the default classful boundary and the CIDR prefix.
Steps:
- Identify the default subnet mask for the class (A, B, or C)
- Calcuate the number of subnet bits: Subnet bits = Default prefix length - CIDR length: (The default prefix length is based on classful addressing: /8 for Class A, /16 for Class B, and /24 for Class C)
- Calculate the number of subnets: 2subnet bits
Example:
- CIDR Address: 192.168.1.0/18
- Number of Subnet Bits: 24 - 18 = 6
- Number of Subnets: 26 = 64
- Number of Hosts: 2(32-18) - 2=2(14) - 2 = 16382
Calculating the Subnet, Network Address, and Broadcast Address
Steps:
Step 1: Calculate the subnet mask: The CIDR prefix /18 means that the first 18 bits of the IP address are used for the network portion, and the remaining 14 bits are for hosts.
-
Convert this to a subnet mask:/18 in binary is
11111111.11111111.11000000.00000000
(18 ones followed by 14 zeros) -
Convert the four binary octets to decimal.
255.255.192.0
Step 2: Calculate the Network Address: The network address is found by performing a bitwise AND operation between the IP address and the subnet mask. In binary, this means that all the host bits will be set to 0.
For this example, we are going to use the IP address 192.168.1.0/18-
Convert the IP address 192.168.1.0to binary
11000000.10101000.00000001.00000000
-
Convert the subnet mask 255.255.255.192 to binary
11111111.11111111.11000000.00000000
-
Perform a bitwise AND operation:
11000000.10101000.00000001.00000000 (IP address)
AND
11111111.11111111.11000000.00000000 (Subnet Mask)
-------------------------------------------
11000000.10101000.00000000.00000000
-
Convert the result to decimal.
192.168.0.0
So in this example, with 192.168.1.0/18, the network address is 192.168.0.0
Step 3: Calculate the Broadcast Address The broadcast address is the last address in the subnet. It can be calculated by setting all the host bits to 1. In our example of 192.168.1.0/18
-
The network address is 192.168.0.0. In binary
11000000.10101000.00000000.00000000
-
Set all the host bits (the last 14 bits) to 1
11000000.10101000.00111111.11111111
-
Convert the result to decimal.
192.168.63.255
So, for a host of 192.168.1.0/18, we have
Host: 192.168.1.0
Subnet Range: 192.168.0.1 (first host) to 192.168.63.254 (last host)
Network: 192.168.0.0
Broadcast: 192.168.63.255
Subnet: 192.168.0.0 (first address) - 192.168.63.255 (last address) with 16,382 usable addresses.