Filtering VPC Traffic with Security Groups and Network ACLs
This lesson explains how security groups and network ACLs, the two traffic filters built into every VPC, differ, which is essential for design and troubleshooting questions.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish stateful security groups from stateless network ACLs.
- Explain how security groups and network ACLs work together.
- Explain how VPC Flow Logs and Reachability Analyzer reveal blocked paths.
- Write tier-to-tier rules that reference security groups instead of IP addresses.
Side by side
Security groups and network ACLs both filter traffic in a VPC, but work differently. A security group is attached to network interfaces, so it protects individual resources such as instances, load balancers, RDS databases, Lambda functions in a VPC and endpoints. It is stateful: when a request is allowed, the response is allowed automatically. It has only allow rules, so anything not allowed is denied, and its rules can reference other security groups, for example allowing the database group to accept traffic only from the application group.
A network ACL is attached to a subnet and filters all traffic entering or leaving it. It is stateless, so return traffic must be allowed explicitly, usually on the ephemeral ports 1024–65535 that clients use for responses. It has both allow and deny rules, evaluated in number order with the first match winning, which makes it the tool for blocking a specific IP range. Its rules use CIDR ranges only. The default network ACL allows all traffic, while a new custom one denies all until rules are added. The following table summarises the differences.
Security group or network ACL?
Using them together
Security groups and network ACLs complement each other. The following list describes how they are used together.
- Security groups give fine-grained workload rules, e.g. the database allows 5432 only from the app tier's group.
- NACLs give coarse subnet guardrails and explicit denies, e.g. blocking a malicious IP range.
- During containment, security group changes may not break existing tracked connections; NACL changes apply to all traffic immediately.
The following diagram shows a chain of security groups in a three-tier application that reference each other instead of CIDR ranges, and the second layer of defence.

Choosing the right filter
Troubleshooting
VPC Flow Logs show REJECT records; Reachability Analyzer names the security group, NACL or route blocking a path.
Troubleshooting blocked traffic
Tier-to-tier rules without IP addresses
A three-tier application must allow only the load balancer to reach the web tier, only the web tier to reach the application tier, and only the application tier to reach the database. Referencing security groups instead of CIDR ranges keeps the rules correct as instances scale and change IP:
aws ec2 authorize-security-group-ingress --group-id $SG_WEB \
--ip-permissions "IpProtocol=tcp,FromPort=8080,ToPort=8080,UserIdGroupPairs=[{GroupId=$SG_ALB}]"
aws ec2 authorize-security-group-ingress --group-id $SG_APP \
--ip-permissions "IpProtocol=tcp,FromPort=9000,ToPort=9000,UserIdGroupPairs=[{GroupId=$SG_WEB}]"
aws ec2 authorize-security-group-ingress --group-id $SG_DB \
--ip-permissions "IpProtocol=tcp,FromPort=5432,ToPort=5432,UserIdGroupPairs=[{GroupId=$SG_APP}]"A compromised web server still cannot reach the database directly, because it is not in SG_APP. The subnets' network ACLs add a coarse second layer, for example denying all traffic from the internet to the database subnets, and are where an emergency block on a malicious address range goes, because security groups cannot deny.
Inbound traffic is allowed, but the responses are dropped. What is the likely cause?
Show answer
The network ACL has no outbound rule for the ephemeral ports used by the responses, because network ACLs are stateless.
Exam Tips
Remember for the exam
- To block one IP address or range, use a network ACL deny rule, because security groups cannot deny.
- To allow only the web tier to reach the application tier, use a security group rule that references the web tier's group.
- If inbound traffic is allowed but responses are dropped, the NACL is missing an outbound rule for ephemeral ports.
- Security groups are stateful; network ACLs are stateless.
- Network ACL rules are evaluated from the lowest number first.