๐Ÿฐ CIDR (Classless Inter-Domain Routing) & Subnetting

๐Ÿ“Œ Overview

CIDR (pronounced "Cider") is a method for allocating IP addresses and IP routing. It replaces the old "Classful" system (Class A, B, C) and allows for more flexible and efficient use of IP addresses.

Think of an IP network as a Pie or Pizza. CIDR tells you how many slices you are cutting the network into.


๐ŸŽญ What is a Subnet Mask?

A Subnet Mask is a 32-bit number that "masks" the IP address. It divides the IP into two parts:

  1. Network Part (Ones): 1111... (Fixed, do not touch).
  2. Host Part (Zeros): 0000... (Variable, you can assign these).

Logic: The computer looks at the mask to decide: "Does this IP belong to my local network, or do I need to send it to the Gateway?"

Hinglish Analogy (Masking Tape)
Imagine painting a wall. You put Masking Tape where you don't want paint.


๐Ÿ“ The "Slash" Notation (/N)

CIDR uses a suffix like /24 or /16. This number represents the Network Bitsโ€”the part of the address that is "fixed" or "frozen". The rest of the bits are "Host Bits" (available for your devices).

Formula: $2^{(32 - N)}$ = Total IPs

๐Ÿ“Š Common CIDR Cheat Sheet

CIDRSubnet MaskTotal IPsUsable IPs*Use Case
/32255.255.255.25511 (Host)Specific Device / Loopback
/31255.255.255.25420Point-to-Point Links (Rare)
/30255.255.255.25242Router-to-Router Links
/29255.255.255.24883 (Azure)Small Subnet
/28255.255.255.2401611 (Azure)Azure Bastion / GatewaySubnet
/27255.255.255.2243227 (Azure)Typical Small VNet Subnet
/24255.255.255.0256251 (Azure)Standard LAN / VNet Subnet
/16255.255.0.065,536~65kEntire VNet Address Space
/8255.0.0.0~16 MHugeEntire Large Org / ISP
/00.0.0.0~4 BAll IPv4The Update Internet

> Note: In standard networking, you lose 2 IPs (Network + Broadcast). In Azure, you lose 5 IPs (Network + Broadcast + Router + DNS + Future).


๐Ÿงฎ How to Calculate (Easy Method)

Don't do binary math if you don't have to. Remember the Power of 2:

  1. Start with /32 = 1 IP.
  2. Go down by 1, separate by doubling IPs.

Example:
If you need 50 VMs, which CIDR do you need?


๐Ÿ”ข How to Calculate Subnet Mask (Step-by-Step)

Want to turn /26 into 255.255.255.192? Follow these 3 steps.

Step 1: Find the "Interesting Octet"

Where does the CIDR number fall?

Example: /26

Step 2: Calculate "On" Bits

How many bits are "On" (1) in that octet?

Step 3: Add the Bit Values

Remember the Magic Binary Values:
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

Final Answer: 255.255.255.192

Hinglish Tip: "Jitne bit ON hain, magic table mein shuru se utne numbers ko jod lo."


โ˜๏ธ Azure Context

subnetting is CRITICAL in Azure. When you create a Virtual Network (VNet):

  1. VNet Address Space: Usually big, e.g., 10.0.0.0/16 (65k IPs).
  2. Subnets: You slice this existing VNet into smaller chunks.
    • 10.0.1.0/24 for Web Servers
    • 10.0.2.0/24 for Database Servers

Warning: Azure reserves 5 IP addresses in every subnet.
If you create a /29 (8 IPs), you only get 8 - 5 = 3 usable IPs.


๐Ÿ’ก Hinglish Explanation (The Pizza Logic)

1. CIDR Number (The Slices)

2. The /24 Magic (Standard)

3. Azure Rule (5 IPs Reserved)


โšก Exam Tips

  1. Smallest Subnet in Azure: technically /29, but realistically /27 or /28 is recommended for usefulness. GatewaySubnet usually needs /27 or /28 (if VPN + ExpressRoute).
  2. Overlap: VNets with overlapping CIDR blocks cannot be peered. (Do VNet 10.0.0.0/16 ki peering doosre 10.0.0.0/16 se nahi ho sakti).
  3. Notation: Lower CIDR value = More IPs (/16 > /24).