IPv4 Subnetting
IPv4 - Subnetting with CIDR
Section titled “IPv4 - Subnetting with CIDR”Historically, IPv4 addresses were managed using a classful system (Class A, B, C), where each class had a fixed default subnet mask. This system was inflexible and often led to inefficient use of IP addresses, as organizations were assigned blocks that were either too large or too small for their needs.
Classless Inter-Domain Routing (CIDR) was introduced to overcome these limitations. CIDR allows for the flexible allocation of IP addresses and the creation of subnets of various sizes, tailored to specific requirements. With CIDR, a network is identified by an IP address and a prefix length (e.g., 192.168.1.0/24), where the prefix length indicates the number of bits used for the network portion of the address.
Subnetting is the process of dividing a larger IP network into smaller, logical sub-networks or subnets. This is achieved by ‘borrowing’ bits from the host portion of the IP address and using them to extend the network portion. This allows for more efficient IP address utilization, improved network management, and enhanced security by isolating network segments.
Understanding CIDR Prefixes and Subnet Masks
Section titled “Understanding CIDR Prefixes and Subnet Masks”The prefix length in CIDR directly corresponds to the subnet mask. For example:
- A /24 prefix means 24 bits are for the network, leaving 32 - 24 = 8 bits for hosts. Subnet mask: 255.255.255.0.
- A /25 prefix means 25 bits are for the network, leaving 32 - 25 = 7 bits for hosts. Subnet mask: 255.255.255.128.
- A /16 prefix means 16 bits are for the network, leaving 32 - 16 = 16 bits for hosts. Subnet mask: 255.255.0.0.
Calculating Subnets and Hosts
Section titled “Calculating Subnets and Hosts”When you borrow ‘n’ bits from the host portion to create subnets:
- Number of Subnets: 2^n
- Number of Host Bits per Subnet (h): Original host bits - n
- Number of Usable Hosts per Subnet: 2^h - 2 (subtracting the network ID and the broadcast address for that subnet)
Example: Subnetting a /24 Network (e.g., 203.0.113.0/24)
A /24 network has 8 host bits (2^8 - 2 = 254 usable hosts).
- Borrow 1 bit (n=1) for subnets (prefix becomes /25):
-
- Number of Subnets: 2^1 = 2 subnets.
-
- Host Bits per Subnet (h): 8 - 1 = 7 bits.
-
- Usable Hosts per Subnet: 2^7 - 2 = 128 - 2 = 126 hosts.
-
- The two subnets would be 203.0.113.0/25 and 203.0.113.128/25.
- Borrow 2 bits (n=2) for subnets (prefix becomes /26):
-
- Number of Subnets: 2^2 = 4 subnets.
-
- Host Bits per Subnet (h): 8 - 2 = 6 bits.
-
- Usable Hosts per Subnet: 2^6 - 2 = 64 - 2 = 62 hosts.
-
- The four subnets would be 203.0.113.0/26, 203.0.113.64/26, 203.0.113.128/26, and 203.0.113.192/26.
Subnetting Example across Traditional Class Boundaries (CIDR in action):
Section titled “Subnetting Example across Traditional Class Boundaries (CIDR in action):”Consider a traditional Class A block like 10.0.0.0/8. Default mask 255.0.0.0.
If an organization needs many smaller networks, they can subnet this /8 block. For instance, creating /16 subnets:
- Original prefix: /8. New desired prefix: /16.
- Bits borrowed for subnets (n): 16 - 8 = 8 bits.
- Number of /16 Subnets: 2^8 = 256 subnets (e.g., 10.0.0.0/16, 10.1.0.0/16, …, 10.255.0.0/16).
- Each /16 subnet has 32 - 16 = 16 host bits, allowing 2^16 - 2 = 65,534 usable hosts per subnet.
Similarly, for a traditional Class B block like 172.16.0.0/16 (default mask 255.255.0.0):
Creating /24 subnets:
- Original prefix: /16. New desired prefix: /24.
- Bits borrowed for subnets (n): 24 - 16 = 8 bits.
- Number of /24 Subnets: 2^8 = 256 subnets (e.g., 172.16.0.0/24, 172.16.1.0/24, …, 172.16.255.0/24).
- Each /24 subnet has 32 - 24 = 8 host bits, allowing 2^8 - 2 = 254 usable hosts per subnet.
Key Considerations for Subnetting:
- The first IP address in any subnet is the Network ID (e.g., 192.168.1.0/24).
- The last IP address in any subnet is the Broadcast IP (e.g., 192.168.1.255 for 192.168.1.0/24).
- These two addresses cannot be assigned to individual hosts.
- Subnetting must leave at least 2 host bits to have usable host addresses (a /30 prefix provides 2 usable host IPs, often used for point-to-point links). Special cases like /31 exist for specific scenarios (RFC 3021).
Subnetting is a fundamental skill in network administration. Using online subnet calculators and practicing various scenarios can greatly help in mastering this concept. Search for ‘CIDR subnetting tutorial’ or ‘IP subnet practice questions’ for more resources.