AWS Fundamentals Series

🛡️ Understanding the Difference Between Security Groups and Network ACLs (NACLs) From a "Top 1%" Perspective: What Stateful and Stateless Really Mean

Introduction

This article is part of the Top 1% Series Complete Article Guide, the 16th article in the AWS Fundamentals Series.

The Big Picture

graph TB
    subgraph Subnet["A Subnet"]
        NACL["NACL<br/>(per-subnet, stateless)"]
        subgraph Instance["EC2 Instance"]
            SG["Security Group<br/>(per-instance, stateful)"]
        end
    end
    Internet["The Internet"] --> NACL --> SG

A Thorough, Grounds-Up Explanation

Difference in Scope: Per-Instance or Per-Subnet

This difference creates a natural division of labor: a NACL as “a broad seawall for the whole subnet,” and a security group as “fine-grained control per instance.”

Design-Philosophy Difference: Stateful or Stateless

This is the single biggest difference between the two.

What a Pro Sees Here (Top 1% Understanding)

Forget an Outbound NACL Rule, and a Connection Breaks for a “Mysterious” Reason

For someone unfamiliar with a stateless, on-premises firewall, the most common gotcha the first time they configure a NACL is assuming “permitting inbound alone should be enough to make the connection work.” Get used to a security group’s stateful behavior, and it’s easy to assume a NACL behaves the same way — but a NACL treats a response packet as its own independent piece of traffic, so unless you explicitly permit outbound traffic to the return port range (ephemeral ports, generally 1024-65535), the very traffic you thought you’d permitted fails because it can never receive a response. When troubleshooting connectivity issues, always keep the possibility “the security group let it through, but the NACL is blocking it” on the table.

Rule Evaluation Order: The Lowest-Numbered Rule Wins

Each NACL rule carries a number (a rule number). A NACL evaluates rules in ascending numeric order, and the first matching rule is the one applied. This is a fundamentally different mechanism from the “an explicit Deny always wins” evaluation logic of IAM policies, covered in The Top 1% Hands-On for Reproducing the Danger of an Overly Broad IAM Policy and Scoping It to Least Privilege. In a NACL, even a Deny rule gets overridden if a lower-numbered Allow rule matches first. Designing rule numbers with deliberate spacing, anticipating future rule additions, is a genuinely important real-world consideration in NACL operations.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. The security group should permit it, but traffic still doesn’t arrive: Check whether the NACL associated with the subnet correctly permits both inbound and outbound. In particular, check for a missing outbound permission for the ephemeral port range used for responses.
  2. You added a NACL rule, but it’s not behaving as intended: Check the rule numbers, and whether an unintended, lower-numbered rule is matching first.
  3. Only some instances can’t communicate: Check whether the security group attached to that instance differs from the others (a NACL should be common across the whole subnet).

Summary

Takeaways to Apply Today

  1. When configuring a NACL, always permit outbound for the return traffic (the ephemeral port range) as well, not just inbound.
  2. When troubleshooting connectivity, build the habit of checking both the security group and the NACL, independently.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).