Skip to Content

NACLs vs security groups

Network ACLs as stateless subnet firewalls, rule numbers and order, the default NACL, ephemeral ports, and how NACLs differ from security groups.

How traffic is checked

How NACLs and security groups check traffic: for an incoming request, the NACL inbound rules are checked, then the security group inbound rules; the response is allowed by the stateful security group, but the stateless NACL checks its outbound rules again; for an outgoing request, the security group outbound rules are checked, then the NACL outbound rules, and the response passes the security group automatically but must match the NACL inbound rules How NACLs and security groups check traffic: for an incoming request, the NACL inbound rules are checked, then the security group inbound rules; the response is allowed by the stateful security group, but the stateless NACL checks its outbound rules again; for an outgoing request, the security group outbound rules are checked, then the NACL outbound rules, and the response passes the security group automatically but must match the NACL inbound rules

The NACL checks both directions; the security group remembers.

Network ACLs

A network ACL (NACL) is like a firewall that controls traffic from and to subnets.

  • One NACL per subnet; new subnets are assigned the default NACL.
  • Each NACL holds NACL rules:
    • rules have a number (1 to 32766); a lower number has higher precedence;
    • the first rule that matches drives the decision;
    • example: with #100 ALLOW 10.0.0.10/32 and #200 DENY 10.0.0.10/32, the IP is allowed, because 100 comes first;
    • the last rule is an asterisk (*) that denies a request when no rule matches;
    • AWS recommends adding rules in increments of 100.
  • Newly created custom NACLs deny everything.
  • NACLs are a great way to block a specific IP address at the subnet level (security groups can't deny).

Default NACL

  • Accepts everything inbound and outbound for the subnets it's associated with (rule 100 ALLOW all, then * DENY).
  • Do NOT modify the default NACL; create custom NACLs instead.

Ephemeral ports

Ephemeral ports: the client 11.22.33.44 connects from a random ephemeral port such as 50105 to port 443 on the web server 55.66.77.88, and the response returns to port 50105; because NACLs are stateless, they must allow the ephemeral port range back, and 1024 to 65535 is the safe choice Ephemeral ports: the client 11.22.33.44 connects from a random ephemeral port such as 50105 to port 443 on the web server 55.66.77.88, and the response returns to port 50105; because NACLs are stateless, they must allow the ephemeral port range back, and 1024 to 65535 is the safe choice

Responses come back to a random high port.
  • For any two endpoints to establish a connection, they must use ports.
  • Clients connect to a defined port (such as 443), and expect a response on an ephemeral port: a random high port the client OS picks.
  • Different operating systems use different ranges:
    • IANA and Windows 10: 49152–65535;
    • many Linux kernels: 32768–60999.

NACL with ephemeral ports: for a web tier talking to a database on port 3306:

  • Web subnet NACL: allow outbound TCP 3306 to the DB subnet CIDR; allow inbound TCP 1024–65535 from the DB subnet CIDR (the responses).
  • DB subnet NACL: allow inbound TCP 3306 from the web subnet CIDR; allow outbound TCP 1024–65535 to the web subnet CIDR.
  • Create NACL rules for each target subnet CIDR (for example, both web subnets in AZ A and AZ B).

Security group vs NACL

Security group:

  • operates at the instance level (ENI);
  • supports allow rules only;
  • stateful: return traffic is automatically allowed, regardless of any rules;
  • all rules are evaluated before deciding;
  • applies to an EC2 instance when someone specifies it.

NACL:

  • operates at the subnet level;
  • supports allow and deny rules;
  • stateless: return traffic must be explicitly allowed (think of ephemeral ports);
  • rules are evaluated in order (lowest to highest); first match wins;
  • automatically applies to all instances in the subnets it's associated with.

See also security groups.

Real-world examples

  • A security team sees attacks from 198.51.100.23. Security groups can't deny, so they add NACL rule #50 DENY 198.51.100.23/32 on the public subnets.

Exam tips

  • "Block a specific IP address" → NACL deny rule (security groups can't deny).
  • "Allowed inbound but the response never arrives" → NACL outbound rules missing the ephemeral port range.
  • "Rule order" → NACLs evaluate lowest number first; security groups evaluate all rules.
  • "Stateful vs stateless" → security groups stateful, NACLs stateless.

Common traps

  • "A new custom NACL allows all traffic." It denies everything until rules are added; the default NACL allows all.
  • "Deny rules in a security group." Only allow rules exist.

Check yourself

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt