Skip to main content

CIDR Calculator

Understanding CIDR in Depth​

CIDR (Classless Inter-Domain Routing) is the system used to define IP address ranges in AWS.

CIDR Reference Table​

┌─────────────────────────────────────────────────────────────┐
│ COMPLETE CIDR TABLE │
├─────────────────────────────────────────────────────────────┤
│ │
│ Prefix │ Mask │ Addresses │ Usable │
│ ────────┼──────────────────┼───────────┼──────────────────│
│ /16 │ 255.255.0.0 │ 65,536 │ 65,531 │
│ /17 │ 255.255.128.0 │ 32,768 │ 32,763 │
│ /18 │ 255.255.192.0 │ 16,384 │ 16,379 │
│ /19 │ 255.255.224.0 │ 8,192 │ 8,187 │
│ /20 │ 255.255.240.0 │ 4,096 │ 4,091 │
│ /21 │ 255.255.248.0 │ 2,048 │ 2,043 │
│ /22 │ 255.255.252.0 │ 1,024 │ 1,019 │
│ /23 │ 255.255.254.0 │ 512 │ 507 │
│ /24 │ 255.255.255.0 │ 256 │ 251 │
│ /25 │ 255.255.255.128 │ 128 │ 123 │
│ /26 │ 255.255.255.192 │ 64 │ 59 │
│ /27 │ 255.255.255.224 │ 32 │ 27 │
│ /28 │ 255.255.255.240 │ 16 │ 11 │
│ │
│ Note: "Usable" = Total - 5 (reserved by AWS) │
│ │
└─────────────────────────────────────────────────────────────┘

Calculation Formula​

┌─────────────────────────────────────────────────────────────┐
│ MAGIC FORMULA │
├─────────────────────────────────────────────────────────────┤
│ │
│ Number of addresses = 2^(32 - prefix) │
│ │
│ Examples: │
│ │
│ /16 : 2^(32-16) = 2^16 = 65,536 addresses │
│ /24 : 2^(32-24) = 2^8 = 256 addresses │
│ /28 : 2^(32-28) = 2^4 = 16 addresses │
│ │
│ Powers of 2 to remember: │
│ 2^4 = 16 2^8 = 256 2^12 = 4,096 │
│ 2^5 = 32 2^9 = 512 2^16 = 65,536 │
│ 2^6 = 64 2^10 = 1,024 │
│ 2^7 = 128 2^11 = 2,048 │
│ │
└─────────────────────────────────────────────────────────────┘

Subnetting Examples​

Example 1: Standard VPC​

┌─────────────────────────────────────────────────────────────┐
│ VPC SUBNETTING 10.0.0.0/16 │
├─────────────────────────────────────────────────────────────┤
│ │
│ VPC: 10.0.0.0/16 (65,536 addresses) │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Possible /24 subnets: 256 │ │
│ │ Addresses per subnet: 251 (usable) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Suggested Subnetting: │
│ │
│ Public (10.0.0.0 - 10.0.9.255) │
│ ├── 10.0.1.0/24 public-1a 251 IPs │
│ ├── 10.0.2.0/24 public-1b 251 IPs │
│ └── 10.0.3.0/24 public-1c 251 IPs │
│ │
│ Private App (10.0.10.0 - 10.0.19.255) │
│ ├── 10.0.11.0/24 private-1a 251 IPs │
│ ├── 10.0.12.0/24 private-1b 251 IPs │
│ └── 10.0.13.0/24 private-1c 251 IPs │
│ │
│ Private DB (10.0.20.0 - 10.0.29.255) │
│ ├── 10.0.21.0/24 database-1a 251 IPs │
│ ├── 10.0.22.0/24 database-1b 251 IPs │
│ └── 10.0.23.0/24 database-1c 251 IPs │
│ │
│ Reserved for expansion: 10.0.30.0 - 10.0.255.255 │
│ │
└─────────────────────────────────────────────────────────────┘

Example 2: Small VPC​

┌─────────────────────────────────────────────────────────────┐
│ VPC SUBNETTING 10.0.0.0/20 │
├─────────────────────────────────────────────────────────────┤
│ │
│ VPC: 10.0.0.0/20 (4,096 addresses) │
│ Range: 10.0.0.0 - 10.0.15.255 │
│ │
│ Subnetting in /24: │
│ │
│ 10.0.0.0/24 → public-1a │
│ 10.0.1.0/24 → public-1b │
│ 10.0.2.0/24 → private-1a │
│ 10.0.3.0/24 → private-1b │
│ 10.0.4.0/24 → database-1a │
│ 10.0.5.0/24 → database-1b │
│ 10.0.6.0/24 - 10.0.15.0/24 → Reserved │
│ │
│ Total used: 6 subnets = 1,506 usable IPs │
│ Reserve: 10 subnets = 2,510 IPs │
│ │
└─────────────────────────────────────────────────────────────┘

Practical Exercises​

Exercise 1: Basic Calculation​

Question: How many addresses in a /22?

💡 Solution
2^(32-22) = 2^10 = 1,024 addresses
Usable: 1,024 - 5 = 1,019 addresses

Exercise 2: Subnetting​

Question: You have a VPC 172.16.0.0/16. Create 4 equal subnets.

💡 Solution
VPC: 172.16.0.0/16 (65,536 IPs)
Division by 4 = 65,536 / 4 = 16,384 IPs each

To have 16,384 addresses: /18

Subnets:
172.16.0.0/18 → 172.16.0.0 - 172.16.63.255
172.16.64.0/18 → 172.16.64.0 - 172.16.127.255
172.16.128.0/18 → 172.16.128.0 - 172.16.191.255
172.16.192.0/18 → 172.16.192.0 - 172.16.255.255

Exercise 3: Overlap Check​

Question: Do these two ranges overlap?

  • 10.0.0.0/24
  • 10.0.1.0/24
💡 Solution
10.0.0.0/24 : 10.0.0.0 - 10.0.0.255
10.0.1.0/24 : 10.0.1.0 - 10.0.1.255

NO, they do not overlap.
They are contiguous but distinct.

Exercise 4: Actual Overlap​

Question: Do these two ranges overlap?

  • 10.0.0.0/16
  • 10.0.5.0/24
💡 Solution
10.0.0.0/16 : 10.0.0.0 - 10.0.255.255
10.0.5.0/24 : 10.0.5.0 - 10.0.5.255

YES! 10.0.5.0/24 is CONTAINED within 10.0.0.0/16

You cannot have these two CIDR at the same level.
10.0.5.0/24 can be a SUBNET of 10.0.0.0/16.

Online Tools​

Free CIDR Calculators​

  1. CIDR.xyz - https://cidr.xyz/

    • Graphical visualization
    • Simple and fast
  2. IP Address Guide - https://www.ipaddressguide.com/cidr

    • Detailed calculation
    • Automatic division
  3. Visual Subnet Calculator - https://www.davidc.net/sites/default/subnets/subnets.html

    • Very visual
    • Ideal for planning

AWS CLI Command​

# Check a CIDR before creation
aws ec2 describe-vpcs --filters "Name=cidr,Values=10.0.0.0/16"

# Create a VPC with CIDR validation
aws ec2 create-vpc --cidr-block 10.0.0.0/16

# Add a secondary CIDR
aws ec2 associate-vpc-cidr-block --vpc-id vpc-xxx --cidr-block 10.1.0.0/16

Best Practices​

┌─────────────────────────────────────────────────────────────┐
│ CIDR BEST PRACTICES │
├─────────────────────────────────────────────────────────────┤
│ │
│ ✅ TO DO │
│ │
│ • Document your addressing plan │
│ • Leave room for growth │
│ • Use standard CIDR (/16, /24) │
│ • Avoid overlaps between VPCs │
│ • Plan for VPC Peering (distinct CIDR) │
│ │
│ ❌ TO AVOID │
│ │
│ • CIDR too small (hard to extend) │
│ • CIDR overlapping another VPC │
│ • Using 192.168.x.x (home network conflict) │
│ • Forgetting the 5 reserved IPs per subnet │
│ │
└─────────────────────────────────────────────────────────────┘

Summary​

ConceptFormula/Value
IP Calculation2^(32-prefix)
/1665,536 IPs
/24256 IPs
AWS reserved IPs5 per subnet
Min AWS/28 (16 IPs)
Max AWS/16 (65,536 IPs)

Return: MODULE 5 Overview