Historical Context & Motivation
Traditional data centers relied on physical firewalls, routers with access control lists, and demilitarized zones (DMZs) to segment and protect network traffic. These devices sat at well-defined perimeter boundaries, inspecting packets and enforcing policy through hardware appliances that administrators could physically rack, cable, and configure. When organizations began migrating workloads to cloud computing platforms in the late 2000s, the familiar perimeter dissolved: compute instances spun up in minutes, IP addresses were ephemeral, and the underlying physical network was entirely abstracted away. The question that confronted security engineers was straightforward yet profound — how do you enforce network segmentation and access control when you no longer own, or even see, the physical infrastructure?
The central challenge this lesson addresses is: how do cloud providers virtualize the packet-filtering functions of traditional firewalls, and what conceptual distinctions between stateful and stateless controls shape the way you design secure cloud networks? Understanding these controls is essential for anyone deploying or securing infrastructure in AWS, Azure, or GCP.
Core Principles & Definitions
Cloud network controls rest on a small set of foundational ideas that mirror classical network security but adapt them to virtualized, software-defined environments. Before diving into implementation details, it is critical to internalize these principles because they govern every rule you write, every troubleshooting session you face, and every compliance audit you navigate.
Defense in Depth
Least Privilege
Stateful vs. Stateless
Implicit Deny
Rule Evaluation Order
Visual Explanation — Traffic Flow Through Cloud Network Controls
The diagram above illustrates the layered evaluation model. When a packet arrives from the internet destined for an EC2 instance in a public subnet, it first encounters the subnet's NACL. The NACL evaluates its rules in ascending numeric order and either allows or denies the packet — this evaluation is entirely stateless, meaning the NACL has no memory of prior packets in the same TCP connection. If the NACL permits the packet, it next reaches the security group associated with the instance's Elastic Network Interface (ENI). The security group evaluates all its rules collectively — if any rule matches, the packet is allowed through. Crucially, because the security group is stateful, the return traffic for this connection is automatically permitted without requiring an explicit outbound rule. This two-layer architecture provides defense in depth: even if a security group rule is overly permissive, a restrictive NACL can act as a coarse-grained safety net.
How Cloud Network Controls Work — Rule Evaluation Deep Dive
Security Group Rule Evaluation
A security group acts as a virtual firewall for an individual instance (more precisely, for an Elastic Network Interface). It maintains a connection tracking table so that once a flow is established, return packets are allowed implicitly. Rules specify the protocol (TCP, UDP, ICMP, or All), the port range, and the source or destination — which can be a CIDR block or another security group ID. The evaluation model is aggregate allow: the engine considers all inbound rules together, and if the packet matches any one rule, it is permitted. There is no concept of rule ordering or explicit deny rules. If no rule matches, the implicit deny drops the packet. This design simplifies configuration but means that security groups cannot be used to block a specific IP while allowing a broader range — you must sculpt the CIDR blocks in your allow rules carefully.
NACL Rule Evaluation
A Network Access Control List (NACL) operates at the subnet boundary and is stateless — every packet is evaluated independently against the rule table, regardless of whether it belongs to an established connection. Each rule has a numeric priority (e.g., 100, 200, 300), and the engine processes rules from lowest number to highest, stopping at the first matching rule. This first-match semantics makes NACLs more expressive than security groups because you can insert a low-numbered deny rule (e.g., Rule 50: Deny 198.51.100.0/24) that takes precedence over a higher-numbered allow rule (e.g., Rule 100: Allow 0.0.0.0/0). The catch is complexity: because NACLs are stateless, you must define explicit outbound rules allowing return traffic, typically on ephemeral port ranges (1024–65535 for most operating systems).
Security Groups vs. NACLs — Detailed Comparison
While both security groups and NACLs filter traffic, they differ along several important dimensions. The table below provides a comprehensive feature-by-feature comparison that every cloud security practitioner should internalize. These distinctions directly affect how you troubleshoot connectivity issues, how you satisfy compliance requirements, and how you architect multi-tier applications.
| Attribute | Security Group | Network ACL (NACL) |
|---|---|---|
| Scope | Instance (ENI) level | Subnet level |
| Statefulness | Stateful — return traffic auto-allowed | Stateless — must allow return traffic explicitly |
| Rule Types | Allow rules only | Allow and Deny rules |
| Evaluation | All rules evaluated; any match permits | Rules processed in numeric order; first match wins |
| Default Behavior | Deny all inbound; allow all outbound | Default NACL allows all; custom NACLs deny all |
| Association | Multiple SGs per instance; SG shared across instances | One NACL per subnet; one NACL can span subnets |
| Source/Dest Reference | CIDR blocks or other security group IDs | CIDR blocks only |
| Typical Use Case | Fine-grained instance-level controls; micro-segmentation | Coarse-grained subnet guardrails; IP blocklisting |
One of the most powerful features of security groups is the ability to reference another security group as a traffic source. For example, you can create a rule that says "allow TCP 3306 from sg-web-tier," which automatically permits database access from any instance associated with the web-tier security group, regardless of that instance's IP address. This abstraction decouples policy from ephemeral addressing and is a cornerstone of cloud-native microsegmentation. NACLs, by contrast, can only reference CIDR blocks, making them more suitable for broad, network-range policies like blocking an entire suspicious IP range.
Worked Example — Designing Controls for a Three-Tier Web Application
Consider a classic three-tier architecture deployed in AWS: a web tier in a public subnet, an application tier in a private subnet, and a database tier in another private subnet. The goal is to configure security groups and NACLs so that internet users can reach the web servers on HTTPS (port 443), the web servers can reach the application servers on port 8080, and the application servers can reach the database on port 5432 (PostgreSQL). No other traffic should be permitted.
sg-web, sg-app, and sg-db. Each SG starts with the default implicit deny on inbound and allow-all on outbound. Assign sg-web to web instances, sg-app to app instances, and sg-db to database instances.sg-web inbound: TCP 443 from 0.0.0.0/0 → ALLOWsg-web. By referencing the web security group rather than a CIDR, the rule dynamically includes any instance in sg-web, even as instances scale in and out via auto-scaling. No internet traffic can reach sg-app because no rule allows 0.0.0.0/0.sg-app inbound: TCP 8080 from sg-web → ALLOWsg-app. This ensures only application-tier instances can reach the database. Web-tier instances cannot connect to the database directly because sg-web is not referenced.sg-db inbound: TCP 5432 from sg-app → ALLOWStrengths, Limitations, and Cross-Provider Comparison
No single network control is a silver bullet. Security groups and NACLs each have distinct strengths and limitations that influence architectural decisions. Understanding these trade-offs allows you to choose the right tool — or combination of tools — for each layer of your cloud infrastructure.
| Dimension | Strengths | Limitations |
|---|---|---|
| Security Groups | Stateful (simplifies rules), SG-to-SG references decouple policy from IPs, easy to manage at scale via IaC, multiple SGs per instance for composable policies | Cannot create deny rules, limited to ~60 inbound + 60 outbound rules per SG (varies by provider), no logging by default (requires VPC Flow Logs), cannot filter by domain name |
| NACLs | Supports explicit deny (IP blocklisting), subnet-wide enforcement, provides secondary layer independent of SGs, numbered rules offer ordered precedence | Stateless (requires ephemeral port management), CIDR-only references, harder to maintain at scale, applies uniformly to all instances in the subnet |
Cross-Provider Analogues
| Concept | AWS | Azure | GCP |
|---|---|---|---|
| Instance-Level Control | Security Group | Network Security Group (NSG) | VPC Firewall Rules (target tags/service accounts) |
| Subnet-Level Control | NACL | NSG (can attach to subnet) | VPC Firewall Rules (network tags) |
| Statefulness | SG: Stateful; NACL: Stateless | NSG: Stateful | Firewall Rules: Stateful |
| Deny Rules | NACL only | NSG supports Allow and Deny | Firewall Rules support Allow and Deny |
Connection to Advanced Network Security Architectures
Security groups and NACLs represent the foundational layer of cloud network security, but modern architectures extend well beyond these basic controls. As you advance in cloud security, you will encounter constructs that build on top of — or complement — these primitives to provide deeper inspection, broader policy expression, and stronger identity-awareness.
| Basic Control | Advanced Control | What It Adds |
|---|---|---|
| Security Groups (L3/L4 filtering) | AWS Network Firewall / Azure Firewall (L7 filtering) | Deep packet inspection, IDS/IPS signatures, domain-based filtering, TLS inspection |
| NACLs (CIDR-based deny) | AWS WAF / Azure Front Door WAF | Application-layer (HTTP) rule sets, bot detection, geo-blocking, rate limiting |
| SG-to-SG references (identity via group) | Service Mesh (Istio, Linkerd) / Zero-Trust mTLS | Workload identity via certificates, per-request authorization, encrypted service-to-service communication |
| VPC Flow Logs (passive logging) | Cloud SIEM / Traffic Mirroring | Real-time anomaly detection, behavioral analytics, full packet capture for forensics |
The concept of microsegmentation represents the logical evolution of security group policies. Instead of broadly segmenting by subnet (a "zone-based" approach), microsegmentation assigns unique policies to every individual workload, often combining security group rules with service mesh policies and identity-aware proxies. In a zero-trust architecture, the network is assumed hostile, and every communication must be authenticated, authorized, and encrypted — regardless of whether it originates from inside or outside the VPC. Security groups and NACLs remain the bedrock on which these advanced architectures are built, enforcing coarse network reachability while higher-layer controls handle identity and application-level authorization.
Practice Problems
Summary — Cloud Network Controls
Cloud network controls replicate the packet-filtering functions of traditional firewalls in software-defined form. Security groups operate at the instance (ENI) level and are stateful, meaning they track connection state and automatically allow return traffic. They support only allow rules, evaluate all rules collectively (aggregate match), and can reference other security group IDs — enabling powerful microsegmentation patterns decoupled from IP addresses. NACLs operate at the subnet boundary and are stateless, requiring explicit rules for both directions of a flow and careful management of ephemeral ports.
The layering of these controls embodies the principle of defense in depth: security groups provide fine-grained, instance-level precision, while NACLs add a coarse-grained subnet-level safety net with the ability to explicitly deny traffic — a capability security groups lack. Both controls default to implicit deny, enforcing a fail-closed posture. Understanding the interplay between stateful and stateless evaluation, aggregate vs. first-match rule processing, and instance-level vs. subnet-level scope is essential for designing secure, compliant cloud architectures — and for diagnosing the connectivity issues that inevitably arise in production environments.