AWS · Comparison

Security groups vs network ACLs

Should I filter VPC traffic with security groups, network ACLs, or both?

Decision summary

Use security groups as the main control: they attach to each network interface, are stateful (return traffic is allowed automatically), contain only allow rules, and can reference other security groups. Use network ACLs as a coarse, subnet-wide second layer, mainly to deny specific addresses or ranges, remembering that they are stateless, so return traffic (ephemeral ports) must be allowed explicitly.

Best fit for each option

Security groups

Per-resource access control, allowing only what each tier needs, and referencing other security groups instead of IP ranges.

Network ACLs

Subnet-wide guardrails and explicit deny rules, such as blocking a malicious IP range quickly.

Side by side

 Security groupsNetwork ACLs
Best forPer network interface allow rulesSubnet-wide allow and deny rules
SecurityStateful; allow only; can reference other groupsStateless; allow and deny; evaluated in number order
Limits60 inbound and 60 outbound rules by default20 rules per direction by default
Operational complexitySimple; return traffic automaticMust allow ephemeral ports for responses
CostNo chargeNo charge

Scaling and topology

Client203.0.113.7VPCSubnet (network ACL at the edge)EC2 instancesecurity group around itTCP 443 inreply to port 49152NACL: stateless, needs an outboundrule for ephemeral ports 1024-65535SG: stateful, the replyis allowed automatically
Traffic passes the subnet's network ACL, then the instance's security group

Limits and constraints

ItemValueContextSource
Rules per security group 60 inbound and 60 outbound
Can be raised with a quota request
Source
checked
Rules per network ACL 20 per direction
Can be raised with a quota request
Can be raised to 40 inbound and 40 outbound. Source
checked

Quotas and limits change. Check the linked source before designing around a number.

When to avoid each option

Security groups

  • Blocking a specific IP address: security groups cannot deny.

Network ACLs

  • Fine-grained per-instance rules: they apply to the whole subnet and need return-traffic rules.

Example scenarios

SituationChooseWhy
Allow only the load balancer to reach the app servers.Security groupsReference the load balancer's security group.
Block one attacking IP range immediately for a whole subnet.Network ACLsNetwork ACLs support deny rules.
A response is blocked even though inbound is allowed.Network ACLsStateless: add an outbound rule for ephemeral ports.

Exam cues

  • Stateful vs stateless: security groups vs network ACLs.
  • Deny a specific IP: network ACL (or WAF for HTTP).
  • Rule order: network ACL rules by number, lowest first; security groups evaluate all rules.

Related

Courses and lessons

Services, comparisons and patterns

Sources

Independent study material, not affiliated with or endorsed by Amazon Web Services.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake