<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: madhuchamara</title>
    <description>The latest articles on DEV Community by madhuchamara (@madhuchamara).</description>
    <link>https://dev.to/madhuchamara</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4186269%2Fa590de8d-78e0-427a-9654-8555a56bc7f2.png</url>
      <title>DEV Community: madhuchamara</title>
      <link>https://dev.to/madhuchamara</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/madhuchamara"/>
    <language>en</language>
    <item>
      <title>AWS Security Groups vs. Network ACLs: Key Differences, Examples, and Best Practices</title>
      <dc:creator>madhuchamara</dc:creator>
      <pubDate>Sun, 18 Oct 2026 06:13:31 +0000</pubDate>
      <link>https://dev.to/madhuchamara/aws-security-groups-vs-network-acls-key-differences-examples-and-best-practices-4i8m</link>
      <guid>https://dev.to/madhuchamara/aws-security-groups-vs-network-acls-key-differences-examples-and-best-practices-4i8m</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When designing a secure network in Amazon Web Services (AWS), two important components of Amazon VPC networking are Security Groups (SGs) and Network Access Control Lists (NACLs).&lt;/p&gt;

&lt;p&gt;Both control network traffic entering and leaving an AWS environment, but they operate at different levels and follow different rule-evaluation models.&lt;/p&gt;

&lt;p&gt;Understanding their differences helps you design secure cloud infrastructure, troubleshoot connectivity issues, and avoid common networking mistakes.&lt;/p&gt;

&lt;p&gt;The key distinction is:&lt;/p&gt;

&lt;p&gt;Security Groups: Stateful firewalls associated with network interfaces and supported resources.&lt;br&gt;
Network ACLs: Stateless packet filters associated with VPC subnets.&lt;/p&gt;

&lt;p&gt;They are complementary security controls rather than direct alternatives.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is an AWS Security Group?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An AWS Security Group acts as a virtual firewall for supported resources, such as EC2 instances. It is associated with a resource's network interface and controls which inbound and outbound traffic is permitted.&lt;/p&gt;

&lt;p&gt;Security Groups use allow rules. Traffic that does not match an applicable allow rule is denied.&lt;/p&gt;

&lt;p&gt;Example: Web server Security Group&lt;/p&gt;

&lt;p&gt;Imagine an EC2 instance hosting a website.&lt;/p&gt;

&lt;p&gt;You could configure its Security Group with these inbound rules:&lt;/p&gt;

&lt;p&gt;Type    Protocol    Port    Source  Purpose&lt;br&gt;
HTTPS   TCP 443 0.0.0.0/0   Allow public HTTPS access&lt;br&gt;
SSH TCP 22  Your trusted IP /32 Allow restricted administration&lt;/p&gt;

&lt;p&gt;In production, expose only the services that need public access. If possible, use AWS Systems Manager Session Manager or another controlled administrative path instead of exposing SSH to the internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important characteristics&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stateful filtering&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Security Groups track connection state. When an inbound request is allowed, its response traffic is automatically permitted by the Security Group. You do not need a separate outbound rule solely to permit the response.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allow rules only&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Security Groups do not support explicit DENY rules. You allow the required traffic and leave other traffic unmatched.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;All applicable rules are considered&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Security Group rules do not use numbered, first-match evaluation. When multiple Security Groups are attached to a network interface, their allowed traffic is combined. A matching allow rule in one Security Group can permit traffic even if another Security Group has no matching allow rule.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Resource-level control&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Security Groups can reference other Security Groups as sources or destinations where supported. This makes it possible to grant access based on workload membership rather than maintaining static IP allowlists.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is an AWS Network ACL?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A Network Access Control List (NACL) controls traffic at the subnet boundary. Every VPC subnet is associated with one NACL at a time. A NACL can be associated with multiple subnets.&lt;/p&gt;

&lt;p&gt;Unlike Security Groups, NACLs support both ALLOW and DENY rules.&lt;/p&gt;

&lt;p&gt;Example: Subnet-level filtering&lt;/p&gt;

&lt;p&gt;Suppose a public subnet contains a web server. A NACL could include rules such as:&lt;/p&gt;

&lt;p&gt;Rule number Direction   Traffic Action&lt;br&gt;
100 Inbound TCP 443 from an approved source ALLOW&lt;br&gt;
110 Inbound TCP 22 from a prohibited CIDR   DENY&lt;br&gt;
120 Inbound Other required traffic  ALLOW, if appropriate&lt;/p&gt;

&lt;p&gt;These entries are illustrative, not a complete production NACL. A real configuration must account for the application’s required traffic, response traffic, and the default rule that denies unmatched traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important characteristics&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stateless filtering&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NACLs do not track connection state. Inbound and outbound packets are evaluated independently, including response traffic.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Explicit ALLOW and DENY&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A NACL can explicitly block a CIDR range at the subnet boundary. This is useful for coarse-grained subnet protection.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Numbered, first-match rules&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Rules are evaluated in ascending numerical order. The first matching rule determines the action, and later rules are not evaluated for that traffic.&lt;/p&gt;

&lt;p&gt;For example, a DENY rule numbered 100 is evaluated before an ALLOW rule numbered 200. If the traffic matches rule 100, the later ALLOW rule cannot override it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Subnet-level scope&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NACL rules apply to traffic entering or leaving the associated subnet. They are not a replacement for routing controls, Security Groups, or application-level authorization.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Security Groups vs. NACLs: Detailed Comparison
Feature Security Group  Network ACL
Primary scope   Resource/network interface  Subnet
Stateful or stateless   Stateful    Stateless
Rule actions    ALLOW   ALLOW and DENY
Rule evaluation All applicable rules contribute to the result   Lowest-numbered matching rule wins
Inbound rules   Yes Yes
Outbound rules  Yes Yes
Return traffic  Automatically permitted for tracked connections Must independently match the relevant rules
References to other Security Groups Supported in applicable rules   Not supported
Typical role    Primary workload-level firewall Additional subnet-level filtering
Common troubleshooting issue    Missing allow rule or overly restrictive outbound rule  Missing return-traffic rule or an earlier matching rule&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The two controls should be designed together. Passing a NACL does not guarantee that a Security Group permits traffic, and passing a Security Group does not bypass a restrictive NACL.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stateful vs. Stateless: A Practical Example&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Consider a client connecting to a web server over HTTPS.&lt;/p&gt;

&lt;p&gt;The client uses TCP source port 51514 and connects to destination port 443.&lt;/p&gt;

&lt;p&gt;The request travels as follows:&lt;/p&gt;

&lt;p&gt;The client sends a packet from source port 51514 to server port 443.&lt;br&gt;
The subnet's inbound NACL evaluates the request.&lt;br&gt;
The Security Group attached to the server's network interface evaluates the request.&lt;br&gt;
The web server responds from source port 443 to client port 51514.&lt;br&gt;
The outbound NACL evaluates the response packet.&lt;br&gt;
With a Security Group&lt;/p&gt;

&lt;p&gt;If the inbound HTTPS connection is permitted, the Security Group automatically permits the tracked response traffic. You do not need to add a Security Group rule solely for the client's response destination port.&lt;/p&gt;

&lt;p&gt;With a NACL&lt;/p&gt;

&lt;p&gt;The NACL does not remember the original connection. The outbound response must independently match an outbound ALLOW rule. If the NACL blocks the client's return port, the connection may time out even though inbound HTTPS was allowed.&lt;/p&gt;

&lt;p&gt;For internet-facing servers, carefully design the NACL's return-traffic rules and the ephemeral port ranges required by the client population. Do not assume that allowing inbound port 443 alone is sufficient.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How They Work Together in an AWS Architecture&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Consider a three-tier application:&lt;/p&gt;

&lt;p&gt;Internet → Public subnet (load balancer) → Private application subnet → Private database subnet&lt;/p&gt;

&lt;p&gt;Each subnet has an associated NACL, while resources use Security Groups appropriate to their roles.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Public load balancer&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The load balancer Security Group permits the required public listener traffic, such as HTTPS on port 443.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Application tier&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The application Security Group allows inbound traffic only from the load balancer Security Group on the application port.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Database tier&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The database Security Group allows the required database port only from the application Security Group.&lt;/p&gt;

&lt;p&gt;For example, if the application uses PostgreSQL, the database Security Group might allow TCP port 5432 from the application Security Group rather than from the entire VPC or internet.&lt;/p&gt;

&lt;p&gt;NACLs can provide additional subnet-level restrictions, such as blocking a prohibited CIDR range or enforcing a stable subnet boundary.&lt;/p&gt;

&lt;p&gt;This design follows least privilege: each workload receives only the network access it needs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When Should You Use Each?
Use Security Groups as your primary control when:
Restricting access to EC2 instances and other supported resources.
Allowing application traffic from specific workload Security Groups.
Controlling administrative access to instances.
Defining the allowed connections between application tiers.
Consider NACLs when:
You need explicit DENY rules for a subnet.
You need an additional coarse-grained security boundary.
You want a subnet-level safeguard against a known unwanted CIDR range.
Your security requirements call for a control that applies independently of individual resource Security Groups.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NACLs are not mandatory as a second restrictive firewall layer in every design. Overly complicated NACLs can increase operational overhead and cause unexpected connectivity failures.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Common Mistakes and Troubleshooting Tips
&lt;em&gt;Mistake 1&lt;/em&gt;: Allowing inbound traffic but forgetting NACL return traffic&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Symptom: A service accepts inbound requests in principle, but connections time out.&lt;/p&gt;

&lt;p&gt;Cause: The NACL allows the request but does not permit the response packet's destination port.&lt;/p&gt;

&lt;p&gt;Solution: Review both inbound and outbound NACL rules, including the relevant ephemeral port ranges.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Mistake 2&lt;/em&gt;: Expecting a Security Group to explicitly deny an IP&lt;/p&gt;

&lt;p&gt;Symptom: You want to block one IP address while allowing other traffic through the same port.&lt;/p&gt;

&lt;p&gt;Cause: Security Groups do not provide explicit DENY rules.&lt;/p&gt;

&lt;p&gt;Solution: Review whether a NACL, AWS Network Firewall, or another appropriate control is suitable for the requirement. Be careful: a NACL deny can affect every resource in the subnet.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Mistake 3&lt;/em&gt;: Assuming a NACL rule can override an earlier rule&lt;/p&gt;

&lt;p&gt;Symptom: A later ALLOW rule appears correct, but traffic remains blocked.&lt;/p&gt;

&lt;p&gt;Cause: An earlier matching DENY rule wins.&lt;/p&gt;

&lt;p&gt;Solution: Inspect the numbered rules in ascending order.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Mistake 4&lt;/em&gt;: Assuming network rules alone establish connectivity&lt;/p&gt;

&lt;p&gt;Symptom: Security Groups and NACLs appear correct, but the service is unreachable.&lt;/p&gt;

&lt;p&gt;Cause: Connectivity may also depend on route tables, gateways, DNS, host firewalls, service listeners, or application configuration.&lt;/p&gt;

&lt;p&gt;Solution: Verify the full network path and consider VPC Flow Logs to help investigate accepted and rejected traffic.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Best Practices&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Use Security Groups as the primary resource-level network access control.&lt;/li&gt;
&lt;li&gt;Apply least privilege to inbound and outbound rules.&lt;/li&gt;
&lt;li&gt;Prefer Security Group references for communication between supported workloads.&lt;/li&gt;
&lt;li&gt;Avoid unrestricted administrative access from the internet.&lt;/li&gt;
&lt;li&gt;Use NACLs for clearly defined subnet-level controls rather than duplicating every Security Group rule.&lt;/li&gt;
&lt;li&gt;Leave gaps between NACL rule numbers to make future changes easier.&lt;/li&gt;
&lt;li&gt;Document the purpose and owner of each rule.&lt;/li&gt;
&lt;li&gt;Review unused and overly broad rules periodically.&lt;/li&gt;
&lt;li&gt;Test restrictive NACL changes carefully, particularly return traffic.&lt;/li&gt;
&lt;li&gt;Use VPC Flow Logs and other AWS monitoring tools to help troubleshoot network connectivity.
Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AWS Security Groups and Network ACLs serve different purposes in VPC security.&lt;/p&gt;

&lt;p&gt;Security Groups provide stateful, resource-level filtering using allow rules. NACLs provide stateless, subnet-level filtering using numbered ALLOW and DENY rules.&lt;/p&gt;

&lt;p&gt;The practical rule is simple:&lt;/p&gt;

&lt;p&gt;Use Security Groups to control which workloads can communicate. Use NACLs when you need additional subnet-level filtering.&lt;/p&gt;

&lt;p&gt;When both are designed carefully, they can provide complementary layers of network protection without making connectivity unnecessarily difficult to manage.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>nacl</category>
      <category>devops</category>
      <category>networking</category>
    </item>
  </channel>
</rss>
