AWS › VPC & Networking
What is the difference between a public subnet and a private subnet within a VPC?
BeginnerAnswer
A public subnet has a route table entry directing traffic to an internet gateway, allowing resources within it to communicate directly with the internet, while a private subnet lacks this direct route, meaning resources within it cannot be reached from or initiate outbound connections directly to the internet, unless traffic is routed through something like a NAT Gateway, making private subnets the appropriate choice for resources like databases that should never be directly exposed to the public internet.
aws ec2 create-route --route-table-id rtb-12345 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-12345Real-world example A company places its web servers in a public subnet so customers can reach them directly over the internet, while placing its database servers in a private subnet, ensuring the database can never be directly accessed from outside the VPC.