AWS Builder Center

Security Groups vs. Network ACLs

A beginner-friendly breakdown of stateful vs. stateless traffic filtering in AWS VPC architectures.

When building architectures in Amazon Virtual Private Cloud (VPC), securing traffic flow requires understanding the distinction between two essential virtual firewalls: Security Groups and Network Access Control Lists (NACLs).
While both inspect and filter incoming and outgoing traffic, they operate at different layers of your cloud network and function under fundamentally different rules.



Key Architectural Differences

Feature
Security Groups (SG)
Network ACLs (NACL)
Operating Level
Instance / ENI level
Subnet level
Traffic State
Stateful (return traffic is automatically allowed)
Stateless (inbound & outbound rules evaluated independently)
Rule Processing
Evaluates all rules before making a decision
Evaluates rules in strict numerical order (lowest number first)
Default Configuration
Denies all inbound, allows all outbound
Default NACL allows all inbound & outbound traffic
Supported Rules
Allow rules only
Both Allow and Deny rules



Understanding Stateful vs. Stateless

The most critical mental model to master is traffic state:
  • Stateful (Security Groups): If you create an inbound rule allowing HTTPS traffic on port 443 to an EC2 instance, the response traffic leaving the instance is automatically permitted back to the client. You do not need an explicit outbound rule.
  • Stateless (NACLs): If you permit inbound traffic on port 443, the response traffic must explicitly match an outbound rule (often targeting ephemeral ports  1024–65535 ). If the outbound rule is missing, the client connection hangs and times out.



Recommended Defense-in-Depth Pattern

In production architectures, both firewalls should be used together to create a layered perimeter:
  1. Subnet Layer (NACLs): Use NACLs as a coarse, subnet-wide perimeter shield. Because NACLs support explicit Deny rules, they are the ideal tool to instantly block suspect IP ranges or malicious CIDR blocks before traffic ever reaches an instance.
  1. Instance Layer (Security Groups): Use Security Groups for fine-grained, micro-segmented application access. Best practice dictates referencing other Security Groups as source targets rather than hardcoded CIDR blocks (e.g., allowing port 3306 on your RDS database only from your web tier's Security Group).


What challenges did you face when first configuring subnets and route tables in AWS? Let's connect in the comments below!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article