Route Tables
Route tables decide where network traffic from a subnet is sent, which is what makes a subnet public or private.
A route table is a set of rules (routes) that determine where traffic leaving a subnet goes. Every subnet is associated with exactly one route table.
How a route works
Each route maps a destination CIDR to a target:
10.0.0.0/16 → local— traffic within the VPC (always present).0.0.0.0/0 → igw-xxxx— all other traffic to the internet gateway. This route is what makes a subnet public.0.0.0.0/0 → nat-xxxx— outbound-only internet for a private subnet via a NAT gateway.
AWS always chooses the most specific matching route for a packet.
Example
# Create a route table and add a default route to an internet gateway
aws ec2 create-route-table --vpc-id vpc-0a1b2c3d4e5f67890
aws ec2 create-route --route-table-id rtb-0123456789abcdef0 \
--destination-cidr-block 0.0.0.0/0 \
--gateway-id igw-0123456789abcdef0
# Associate it with the public subnet
aws ec2 associate-route-table \
--route-table-id rtb-0123456789abcdef0 \
--subnet-id subnet-0a1b2c3d4e5f67890When to use it
- A public subnet's route table has a 0.0.0.0/0 route to an internet gateway, making instances in it reachable from the internet.
- A private subnet's route table has a 0.0.0.0/0 route to a NAT gateway so instances can reach the internet for updates without being publicly reachable.
- A VPC peering connection is added to a route table so that two VPCs can communicate using private IP addresses.
More examples
Create Route Table and Add IGW Route
Creates a route table and adds a default route to an internet gateway, which makes associated subnets public.
RT=$(aws ec2 create-route-table \
--vpc-id vpc-0abc123 \
--query RouteTable.RouteTableId --output text)
# Add default route to internet gateway
aws ec2 create-route \
--route-table-id $RT \
--destination-cidr-block 0.0.0.0/0 \
--gateway-id igw-0abc123Associate Route Table with Subnet
Associates a route table with a subnet so traffic from that subnet follows the routes defined in the table.
aws ec2 associate-route-table \
--route-table-id rtb-0abc123 \
--subnet-id subnet-0abc123View Routes in a Route Table
Shows all routes in a route table, letting you confirm which traffic goes to the internet gateway vs. stays local.
aws ec2 describe-route-tables \
--route-table-ids rtb-0abc123 \
--query 'RouteTables[].Routes[].{Dest:DestinationCidrBlock,Target:GatewayId,State:State}' \
--output table
Discussion