DEV Community

Cover image for Networking 101: Part 3
Himanshu Bhatt
Himanshu Bhatt

Posted on

Networking 101: Part 3

IP Addressing, Subnetting & CIDR: A Comprehensive Guide to Network Design

Networking forms the backbone of all modern IT systems, enabling communication between devices across vast networks. In this guide, we’ll explore IP addressing, subnetting, and CIDR notation—the fundamental building blocks that ensure efficient, secure, and scalable network communication. Whether you're new to networking or looking to refine your skills, this guide will walk you through everything from the basics to advanced concepts.

Why It Matters:

Without proper addressing and network segmentation, data transmission can become inefficient, insecure, and hard to manage. These concepts enable you to structure your network, optimize resource allocation, and troubleshoot effectively.


1. What is an IP Address?

An IP address (Internet Protocol address) is a unique identifier assigned to each device connected to a network. Think of it as a home address for a device—just as a postal address ensures your letters reach the right home, an IP address ensures that data reaches the correct device.

IPv4 vs. IPv6

  • IPv4:

    • 32-bit address, expressed as four decimal numbers separated by dots.
    • Example: 192.168.1.1
    • Address space: Approximately 4.3 billion addresses.
  • IPv6:

    • 128-bit address, expressed as eight groups of four hexadecimal digits separated by colons.
    • Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
    • Provides a significantly larger address space to meet growing demand.

IPv6 was introduced due to the exhaustion of available IPv4 addresses.


2. IP Address Classes & Public vs. Private IPs

IP Address Classes (A, B, C, D, E)

IPv4 addresses were originally divided into classes to simplify the assignment of addresses:

Class Range Purpose Example
A 0.0.0.0 – 127.255.255.255 Large networks (e.g., governments) 10.10.15.1
B 128.0.0.0 – 191.255.255.255 Medium-sized networks (e.g., universities) 172.16.0.1
C 192.0.0.0 – 223.255.255.255 Small networks (e.g., homes) 192.168.1.1
D 224.0.0.0 – 239.255.255.255 Multicast groups N/A
E 240.0.0.0 – 255.255.255.255 Reserved for experimental use N/A

Public vs. Private IP Addresses

  • Public IPs:

    • These are routable on the internet and assigned by your Internet Service Provider (ISP).
  • Private IPs:

    • These are used within private networks and cannot be routed over the internet.
    • Common private IP ranges (RFC 1918):
    • Class A: 10.0.0.0 – 10.255.255.255
    • Class B: 172.16.0.0 – 172.31.255.255
    • Class C: 192.168.0.0 – 192.168.255.255

3. Subnetting: Breaking Down Large Networks

Subnetting involves dividing a large network into smaller, more manageable subnetworks, or subnets. Think of it as breaking a big building into individual apartments, with each subnet representing a different unit.

Subnet Mask: Network vs. Host

A subnet mask defines which part of an IP address is the network portion (the building address) and which part is the host portion (the individual apartment number).

  • Example: IP: 192.168.1.10 Subnet Mask: 255.255.255.0
    • Network portion: 192.168.1
    • Host portion: 10

4. CIDR Notation: Simplifying Network Design

CIDR (Classless Inter-Domain Routing) provides a more flexible method to describe network addresses. Instead of the traditional class-based system, CIDR specifies the number of bits dedicated to the network portion of the address.

  • Example: 192.168.1.0/24
    • /24 indicates that the first 24 bits are for the network, leaving 8 bits for the host.

This notation simplifies network design and routing by removing the restrictions of the class-based addressing system.


5. Step-by-Step Subnetting Examples

Subnetting is a process that allows network administrators to divide a larger network into smaller, more manageable sub-networks. This helps improve efficiency, security, and IP address management.

Let's break down two examples of subnetting step-by-step.

Example 1: Subnetting 192.168.1.0/24

  1. Subnet Mask: /24255.255.255.0

    • The /24 indicates that the first 24 bits of the IP address are used for the network portion, and the remaining 8 bits are used for the host portion.
    • The subnet mask 255.255.255.0 in binary is:
     11111111.11111111.11111111.00000000
    

    This shows that the first 24 bits are for the network, and the last 8 bits are for hosts.

  2. Host Bits: 32 - 24 = 8 bits

    • There are 32 total bits in an IPv4 address, and since 24 bits are used for the network portion, the remaining 8 bits are used for hosts.
    • This means there are 8 bits available to assign to host addresses.
  3. Total Hosts: 2^8 = 256 addresses

    • The total number of addresses in this subnet is calculated by raising 2 to the power of the number of host bits. In this case, 2^8 = 256. This includes both usable host addresses and reserved addresses like the network address and broadcast address.
  4. Usable Hosts: 256 - 2 = 254 (subtracting network and broadcast addresses)

    • Out of the 256 addresses, 2 addresses are reserved:
      • One for the network address (the first address in the range).
      • One for the broadcast address (the last address in the range).
    • Therefore, the total number of usable addresses is 256 - 2 = 254.
  5. Range:

    • Network: 192.168.1.0 — This is the network address and represents the subnet itself.
    • First Host: 192.168.1.1 — The first usable IP address in the range.
    • Last Host: 192.168.1.254 — The last usable IP address in the range.
    • Broadcast: 192.168.1.255 — The broadcast address for this subnet.

Example 2: Subnetting 192.168.1.0/26

  1. Subnet Mask: /26255.255.255.192

    • The /26 indicates that the first 26 bits of the IP address are used for the network portion, and the remaining 6 bits are used for the host portion.
    • The subnet mask 255.255.255.192 in binary is:
     11111111.11111111.11111111.11000000
    

    This shows that the first 26 bits are for the network, and the remaining 6 bits are for hosts.

  2. Host Bits: 32 - 26 = 6 bits64 total addresses

    • With 6 host bits available, the total number of addresses in this subnet is 2^6 = 64. This includes both usable host addresses and reserved addresses.
  3. Usable Hosts: 64 - 2 = 62 hosts

    • Similar to the previous example, 2 addresses are reserved:
      • One for the network address.
      • One for the broadcast address.
    • Therefore, the total number of usable hosts is 64 - 2 = 62.
  4. Subnets:

    • Subnet 1: 192.168.1.0 - 192.168.1.63
      • Network Address: 192.168.1.0
      • First Host: 192.168.1.1
      • Last Host: 192.168.1.62
      • Broadcast Address: 192.168.1.63
    • Subnet 2: 192.168.1.64 - 192.168.1.127
      • Network Address: 192.168.1.64
      • First Host: 192.168.1.65
      • Last Host: 192.168.1.126
      • Broadcast Address: 192.168.1.127
    • Subnet 3: 192.168.1.128 - 192.168.1.191
      • Network Address: 192.168.1.128
      • First Host: 192.168.1.129
      • Last Host: 192.168.1.190
      • Broadcast Address: 192.168.1.191
    • Subnet 4: 192.168.1.192 - 192.168.1.255
      • Network Address: 192.168.1.192
      • First Host: 192.168.1.193
      • Last Host: 192.168.1.254
      • Broadcast Address: 192.168.1.255

6. Advanced Topics: VLSM and Supernetting

Variable Length Subnet Masking (VLSM)

VLSM allows you to create subnets of different sizes within the same network, optimizing the use of IP addresses. For example, you might use /30 for a small point-to-point link and /24 for a larger office network.

Supernetting (Route Aggregation)

Supernetting is the process of combining multiple smaller subnets into a larger network, which helps simplify routing. For example, instead of advertising multiple routes, you can aggregate them into a broader CIDR block like 192.168.0.0/22.


7. Key Takeaways

  • IP Addresses uniquely identify devices on a network.
  • Subnetting divides networks into smaller, more manageable parts.
  • CIDR Notation simplifies IP addressing and routing by using a flexible bit-length system.
  • VLSM allows for more efficient IP address allocation by varying subnet sizes.
  • Supernetting aggregates networks to reduce the complexity of routing tables.

8. Next Steps

  • Practice subnetting using online calculators (e.g., CIDR.xyz).
  • Try designing a mock network with various departments and assign appropriate subnets.
  • Dive deeper into binary conversion to enhance your understanding of subnetting.

With these fundamental concepts in hand, you are equipped to design, troubleshoot, and secure networks like a pro!
Happy subnetting!


Top comments (0)