DEV Community

Cover image for Getting Started with CIDR and Subnetting in AWS
Irfan Satrio
Irfan Satrio

Posted on • Edited on

Getting Started with CIDR and Subnetting in AWS

Understanding AWS networking can feel tricky at first, especially when it comes to organizing IP addresses. Concepts like CIDR and subnetting are the tools that help shape your VPC and manage traffic, and in this article, we’ll go through them step by step so you can follow along more easily.

Understanding CIDR in AWS

CIDR (Classless Inter-Domain Routing) defines the size of an IP address range. A block like 10.0.0.0/16 shows which part of the IP is the network and how many addresses are available. Smaller prefixes provide larger address spaces while larger prefixes give smaller networks.

In AWS, your VPC’s CIDR defines the total address space you have to work with. Choosing wisely is important. Picking a range too small can lead to running out of IPs as more subnets and services are added. Overly large ranges can cause overlap with other networks and complicate peering or hybrid connections.

Suppose a VPC 10.0.0.0/16 is divided into three /24 subnets across different Availability Zones for public, application, and database workloads. This provides enough addresses for medium workloads while leaving room for future growth.

It’s also useful to leave spare address space for unexpected growth or new services. For example, if you plan to add containerized applications later, remember that each container may consume multiple IPs per node, especially in AWS ECS or EKS using the awsvpc networking mode.

Subnetting and VPC Layout

Subnets divide your VPC into smaller segments. Each subnet belongs to a single Availability Zone, helping isolate failure domains and making traffic behavior more predictable.

Subnets are tied to routing:

  • Public subnets route through an Internet Gateway for external access.
  • Private subnets route through a NAT Gateway or VPC endpoint for controlled outbound traffic.
  • Database subnets remain isolated, often without direct internet access.

Keeping subnets simple and well-labeled makes your architecture easier to understand and operate. Once subnets are defined, it is important to consider traffic flow and security rules.

Additionally, naming conventions can help a lot. For example, naming subnets like public-us-east-1a-web, private-us-east-1b-app, or db-us-east-1c immediately communicates their purpose and AZ, reducing mistakes when applying security groups or route tables later.

Routing and Security Considerations

CIDR directly affects routing. Route tables rely on clear, non-overlapping ranges to deliver traffic correctly. As environments grow with Transit Gateway, PrivateLink, or multi-account setups, predictable CIDR allocations prevent confusion.

Security controls also depend on CIDR:

  • Security Groups define which IP ranges can reach your instances.
  • Network ACLs apply rules at the subnet level.
  • Interface Endpoints like S3 or DynamoDB private connections consume IP addresses from subnets, so leave room for future connections.

Leaving buffer IPs in each subnet prevents future deployments from being blocked.

It is also a good practice to visualize which subnets need which level of access. For example, a public web server might only allow inbound HTTP/HTTPS, while a database subnet may only allow inbound traffic from private application subnets. This planning reduces accidental exposure and simplifies troubleshooting later.

Scaling and Connectivity

Good CIDR and subnet planning simplifies hybrid and multi-VPC environments. Direct Connect or VPNs need non-overlapping ranges. VPC peering and Transit Gateway connections also rely on clear boundaries. Poor planning can lead to workarounds such as NAT routing or IP translation.

Standardizing CIDR patterns across accounts makes automation and monitoring easier, reduces mistakes, and simplifies route propagation when adding new workloads or Availability Zones. For instance, using a consistent scheme like 10.X.Y.0/24 for each subnet type makes it much easier to predict where new subnets should go and reduces the risk of overlapping addresses in multi-account setups.

Common VPC Use Cases and Examples

Here are some practical scenarios to illustrate how CIDR and subnets work together:

  • Web server on a public subnet: Needs a route to the IGW and public IP for internet access.
  • Backend application on a private subnet: Uses NAT Gateway to reach external APIs while remaining hidden from the internet.
  • Database server: Fully isolated; route table only includes the local VPC range.
  • Hybrid cloud access: Some subnets connect to on-prem via VPN or Direct Connect, while others rely on IGW for internet connectivity.

Seeing these patterns repeatedly in labs or real-world projects helps internalize routing behavior and subnet design principles.

Operational and Cost Implications

CIDR choices impact operations and cost in subtle ways:

  • Poorly sized subnets can increase cross-AZ NAT traffic, raising costs.
  • Fragmented ranges may require extra endpoints or Transit Gateway attachments.
  • Clear address planning reduces operational overhead for monitoring, logging, and troubleshooting.

Another consideration is automation. Many teams use Infrastructure as Code tools like Terraform or AWS CloudFormation. Well-planned CIDR ranges and subnet layouts make it much easier to template VPCs, reducing errors and deployment time.

Tips for Planning

  • Visualize your VPC: Even a simple diagram helps understand where subnets and routes interact.
  • Leave buffer IPs: Reserve extra addresses for future scaling, new workloads, or temporary needs.
  • Use descriptive naming: Makes it easier to track subnets and route table associations.
  • Document everything: Keep a spreadsheet or diagram of CIDR blocks, subnets, and their purpose.

These small practices save a lot of time when scaling, auditing, or troubleshooting.

Conclusion

CIDR and subnetting are the foundation of AWS networking. Choosing the right VPC range and organizing subnets carefully ensures smooth routing, security, and scalability. Planning these fundamentals early makes future growth and operations much easier.

Top comments (0)