Microsoft Azure Documentation

Learn how to implement and manage Azure services.

Understanding Virtual Network Subnets

This article delves into the concept of subnets within Azure Virtual Networks (VNets). Subnets are fundamental to segmenting your VNet into smaller, manageable address spaces, allowing for granular control over network traffic and security.

What is a Subnet?

A subnet is a division of an IP address range within a Virtual Network. When you create a VNet, it is assigned a private IP address space. You can then divide this address space into multiple subnets. Each subnet must have a unique name and an address range that is a subset of the VNet's address space.

Consider a VNet with the address space 10.0.0.0/16. You could divide this into two subnets:

Resources deployed within Azure, such as virtual machines, will be assigned an IP address from one of these subnets.

Benefits of Using Subnets

Key Considerations for Subnets

Address Space Allocation

When defining a subnet, you must specify its address range. This range must be within the VNet's address space and cannot overlap with other subnets in the same VNet. Azure reserves the first four and the last IP address in each subnet for IP resolution and broadcast purposes. This means you cannot use these addresses.

For a subnet with a /24 prefix, there are 256 addresses in total. After reserving 5 addresses, you have 251 usable IP addresses available for resources.

Subnet Sizing

The size of your subnet depends on the number of IP addresses you anticipate needing for the resources within it. It's generally recommended to over-provision slightly to accommodate future growth. However, excessively large subnets can lead to IP address exhaustion within the VNet.

Default Subnet

When you create a VNet without specifying any subnets, Azure automatically creates a default subnet that encompasses the entire VNet address space. While convenient for initial setup, it's best practice to create custom subnets for better organization and security.

System Reserved Subnets

Azure reserves a small portion of the subnet address space for internal Azure services. The exact number of reserved IPs varies by subnet size, but always consider the first four and last IP addresses as unusable.

Creating and Managing Subnets

You can create and manage subnets using the Azure portal, Azure CLI, Azure PowerShell, or ARM templates.

Azure Portal Example

  1. Navigate to your Virtual Network resource in the Azure portal.
  2. Under "Settings", select "Subnets".
  3. Click "+ Subnet".
  4. Provide a "Name" for the subnet (e.g., AppSubnet).
  5. Specify the "Address range" (e.g., 10.0.1.0/24).
  6. Configure Network Security Group (NSG) and Route Table (RT) if needed.
  7. Click "OK" to create the subnet.
Tip: Plan your subnet strategy before deploying resources. Consider your application architecture, security requirements, and future scalability needs.

Subnets and Network Security Groups (NSGs)

NSGs are stateful packet security filters that you can associate with subnets or individual network interfaces. By applying an NSG to a subnet, you can control inbound and outbound traffic for all resources within that subnet.

For example, you might create an NSG for your web tier subnet that only allows inbound HTTP (port 80) and HTTPS (port 443) traffic from the internet, while blocking all other inbound traffic.

Subnets and User Defined Routes (UDRs)

UDRs allow you to override Azure's default system routes or add your own routes to a route table. Route tables can be associated with subnets, enabling you to direct traffic through specific network virtual appliances (NVAs) like firewalls or next-generation intrusion detection systems before it reaches its destination.

This is crucial for implementing centralized network security policies and traffic inspection.

Note: A subnet cannot have overlapping CIDR blocks with any other subnet in the same VNet.

Best Practices

Conclusion

Subnetting is a core concept for building robust, secure, and scalable virtual networks in Azure. By effectively segmenting your VNet and applying appropriate security and routing controls, you can create a well-organized and protected cloud infrastructure.