Public IPs, Default Outbound Access and NAT Gateway

Azure NAT Gateway gives a private subnet one controlled way out to the internet. All the VMs in the subnet go out through the same fixed public IP, and nothing on the internet can open a connection back in.

It matters more now, because since March 2026 new subnets are private by default, and a new VM can’t run apt update or Windows Update until its subnet has an outbound method. A lot of guides written before 2026 don’t mention this at all, so people assume their VM is broken.

In the lab you’ll build a small VM in a private subnet, show it has no internet, add a NAT Gateway and watch the same VM go out through your own fixed IP. After that come two surprises: a public IP that refuses to delete, and a VM public IP that isn’t used for outbound at all.

TimeYou needCostBy the end you can
About 45 minutesvnet-saat, the CLI, Run Command (built in)About USD 0.05 if you clean up within 1 hour (NAT Gateway USD 0.045/hour, public IP USD 0.005/hour; the VM is covered by the 12-month free hours)Explain default outbound access, add NAT Gateway to a subnet, and check which IP a VM really uses

What it is, in one line

NAT Gateway is a managed, outbound-only exit for a subnet. The VMs share its fixed public IP to reach the internet, and the internet can’t reach back to them.

In Simple Words

One gate with a guard, for going out only

Picture a hostel where the students can go out to the shops but strangers aren’t allowed in. The warden builds one exit gate with a guard, every student leaves through it, and the shopkeepers only ever write the hostel’s address in the visitor book, not each student’s room number.

Your private subnet is the hostel, the gate is the NAT Gateway and the hostel’s address is its public IP. Replies from the shops come back in through the same gate, but nobody gets in uninvited.

Before 2026, plenty of hostels had a hidden side door nobody had planned for. That door is gone by default now, so you build the gate deliberately.

Engineer's View

Outbound methods and who wins

A VM can get to the internet in a few ways, and Azure picks between them in this order:

  1. A route to a firewall or appliance (user-defined route, Lesson 47).
  2. NAT Gateway on the VM’s subnet, which wins over the VM’s own public IP and over load balancer outbound rules.
  3. Instance-level public IP on the VM’s network card.
  4. Load balancer outbound rules (Lesson 51).
  5. Default outbound access: a hidden IP that Microsoft owns and can change. You don’t get it in private subnets, and those are the default for new VNets since 31 March 2026.

A few NAT Gateway facts to remember:

  • One NAT Gateway serves subnets in one VNet and takes up to 16 public IPs or a /28 prefix. Each IP gives you roughly 64,000 SNAT ports, handed out as they’re needed.
  • The Standard SKU is zonal (or no zone). StandardV2 is zone-redundant and supports IPv6, needs StandardV2 public IPs and costs the same, but it isn’t offered in West India. You can’t upgrade a Standard one to StandardV2 in place.
  • Price (Standard, Central India): about USD 0.045 per hour plus 0.045 per GB processed, plus USD 0.005 per hour for each Standard public IP.
  • The default TCP idle timeout is 4 minutes, and you can raise it up to 120.

VMs in a private subnet can still reach Azure Storage in the same region and the Azure platform address 168.63.129.16, and that’s why the VM agent and Run Command carry on working with no internet path.

How it works, step by step

This is what goes on when a VM behind a NAT Gateway calls a website:

Azure NAT Gateway SNAT flow for one outbound request
  1. The VM sends a packet to the website from its private IP, 10.30.10.4 for example.
  2. The subnet’s NAT Gateway picks it up and swaps the source for its own public IP and a free source port (SNAT).
  3. The website only sees the NAT Gateway’s public IP, so that’s where it replies.
  4. NAT Gateway matches the reply against the mapping it saved and passes it back to 10.30.10.4.
  5. Anything coming in that doesn’t match an existing mapping gets dropped, so there’s no way in.

Since all the VMs share one public IP, a partner can allow-list a single address for your whole subnet, and that’s the most common business reason for NAT Gateway, more than “making the internet work”.

Azure NAT Gateway and other outbound methods in order of precedence

So the design rule is to give each subnet that needs internet an explicit outbound path, use NAT Gateway for plain outbound traffic, and bring in a firewall when you need to inspect or filter that traffic.

Hands-on lab: a private VM gets a way out

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

You’ll build one small Ubuntu VM in snet-mgmt with no public IP, test it with Run Command (it doesn’t need SSH or internet), then add a NAT Gateway. Load the network IDs first:

$v = Get-Content C:\azure-lab\vnet-saat.json | ConvertFrom-Json
az group create --name rg-saat-l13 --tags course=saatvedha-azure lesson=13 -o none

1Create a test VM in the private subnet

Run this (it takes around two minutes):

az vm create --resource-group rg-saat-l13 --name vm-saat-l13 --image Canonical:ubuntu-24_04-lts:server:latest --size Standard_B2ats_v2 --subnet $v.'snet-mgmt' --public-ip-address '""' --nsg '""' --admin-username azureuser --generate-ssh-keys --os-disk-size-gb 64 --tags course=saatvedha-azure lesson=13 --query "{name:name, privateIp:privateIpAddress, publicIp:publicIpAddress}" -o table

You should see something like this:

Name         PrivateIp    PublicIp
-----------  -----------  ----------
vm-saat-l13  10.30.10.4

'""' passes an empty value from Windows PowerShell through to the CLI, meaning “no public IP” and “no NSG on the network card”. Leave the quotes out and PowerShell drops the empty value, so the CLI creates both. Standard_B2ats_v2 with a 64 GB disk stays within the free account’s 12-month amounts.

VMs get a proper lesson of their own in Lesson 15.

2Prove the VM has no internet

Run this:

az vm run-command invoke --resource-group rg-saat-l13 --name vm-saat-l13 --command-id RunShellScript --scripts "curl -s -m 10 https://ifconfig.me || echo NO-OUTBOUND" --query "value[0].message" -o tsv

You should see something like this:

Enable succeeded:
[stdout]
NO-OUTBOUND

[stderr]

The VM can’t get to the internet. Run Command still worked, because it talks to the VM agent through the Azure platform and not over the internet. Check why:

az network vnet subnet show --ids $v.'snet-mgmt' --query "{defaultOutbound:defaultOutboundAccess, natGateway:natGateway.id}" -o table

You should see something like this:

DefaultOutbound
-----------------
False

3Create a public IP and a NAT Gateway

Run this:

az network public-ip create --resource-group rg-saat-l13 --name pip-saat-nat --sku Standard --allocation-method Static --tags course=saatvedha-azure lesson=13 -o none
az network nat gateway create --resource-group rg-saat-l13 --name nat-saat-l13 --public-ip-addresses pip-saat-nat --idle-timeout 4 --tags course=saatvedha-azure lesson=13 -o none
$natId = az network nat gateway show --resource-group rg-saat-l13 --name nat-saat-l13 --query id -o tsv
az network vnet subnet update --ids $v.'snet-mgmt' --nat-gateway $natId -o none
az network public-ip show --resource-group rg-saat-l13 --name pip-saat-nat --query ipAddress -o tsv

You should see something like this:

20.204.118.57

The NAT Gateway sits in your lab resource group, but it’s attached to snet-mgmt in rg-saat-core, and that link across groups matters when you clean up.

4Test again

Give it about a minute, then run the same test again:

az vm run-command invoke --resource-group rg-saat-l13 --name vm-saat-l13 --command-id RunShellScript --scripts "curl -s -m 10 https://ifconfig.me || echo NO-OUTBOUND" --query "value[0].message" -o tsv

You should see something like this:

Enable succeeded:
[stdout]
20.204.118.57
[stderr]

Now the website sees the NAT Gateway’s public IP, the same one you printed in step 3, and every VM in snet-mgmt will go out on it. If you like, try sudo apt-get update through Run Command, and this time it works.

Azure NAT Gateway lab: no outbound, then the NAT public IP
Example output. Your IPs will be different.

✅ Checkpoint: The VM printed NO-OUTBOUND before the NAT Gateway, and the NAT Gateway’s public IP after.

Break It, Then Fix It

Both of these come from real teams. One blocks your cleanup, and the other changes the IP your partners see.

1Break it: delete the public IP while it’s in use

Run this:

az network public-ip delete --resource-group rg-saat-l13 --name pip-saat-nat

You’ll get an error like this:

(PublicIPAddressInUse) Public IP address /subscriptions/.../publicIPAddresses/pip-saat-nat can not be deleted since it is still
allocated to resource /subscriptions/.../natGateways/nat-saat-l13. In order to delete the public IP, disassociate/detach the
Public IP address from the resource. To learn how to do this, see aka.ms/deletepublicip.
Code: PublicIPAddressInUse

Azure won’t delete anything another resource depends on, and the same chain applies one level up, since the NAT Gateway is attached to a subnet in another resource group. So you clean up in reverse: the subnet link, then the NAT Gateway, then the IP.

You’ll do that at the end of the lab.

2Break it: give the VM its own public IP and expect it to be used

A partner tells you “we’ll allow-list your VM’s public IP”, so someone adds a public IP to the VM’s network card and sends that address over:

az network public-ip create --resource-group rg-saat-l13 --name pip-saat-vm --sku Standard --allocation-method Static --tags course=saatvedha-azure lesson=13 -o none
$nic = az vm show --resource-group rg-saat-l13 --name vm-saat-l13 --query "networkProfile.networkInterfaces[0].id" -o tsv
az network nic ip-config update --ids "$nic/ipConfigurations/ipconfigvm-saat-l13" --public-ip-address pip-saat-vm -o none
az network public-ip show --resource-group rg-saat-l13 --name pip-saat-vm --query ipAddress -o tsv
az vm run-command invoke --resource-group rg-saat-l13 --name vm-saat-l13 --command-id RunShellScript --scripts "curl -s -m 10 https://ifconfig.me" --query "value[0].message" -o tsv

You should see something like this:

20.207.65.140
Enable succeeded:
[stdout]
20.204.118.57
[stderr]

The VM’s own public IP is 20.207.65.140, but its outbound traffic still leaves from the NAT Gateway’s 20.204.118.57, because NAT Gateway takes precedence over an instance-level public IP for outbound. The partner allow-lists the wrong address, and the integration times out on their side while you see no error at all.

To fix it, give partners the NAT Gateway’s IP and remove the VM’s public IP, which only adds risk:

az network nic ip-config update --ids "$nic/ipConfigurations/ipconfigvm-saat-l13" --remove publicIpAddress -o none
az network public-ip delete --resource-group rg-saat-l13 --name pip-saat-vm
Azure NAT Gateway lab errors: PublicIPAddressInUse and the VM public IP not used
Example output of both surprises.

3Clean up in the right order

Run this:

az network vnet subnet update --ids $v.'snet-mgmt' --remove natGateway -o none
az group delete --name rg-saat-l13 --yes
az network vnet subnet show --ids $v.'snet-mgmt' --query natGateway
C:\azure-lab\Find-LabResources.ps1 -Lesson 13

You should see this:

Nothing tagged course=saatvedha-azure is left.

The natGateway query prints nothing, so the subnet is private again. If you skip the first line, deleting the resource group fails, because the NAT Gateway is still attached to a subnet in rg-saat-core.

✅ Checkpoint: Both surprises reproduced, the subnet is back to private, and nothing from Lesson 13 is left.

This happened at work

The payment partner who saw a different IP every week

A travel company built its booking servers in 2023, before private subnets were the default. The VMs had no public IPs and no NAT Gateway but still got to the internet, so nobody gave outbound a second thought. Their card payment partner needed an allow-listed source IP, so the team checked one server, saw it going out from a Microsoft address, and sent that address to the partner.

It worked fine for months. Then routine maintenance moved some of the VMs to new hosts and payments started failing for part of the fleet, because the “default outbound” IP had changed, which Microsoft warns can happen. Half the servers were going out from the old address and half from a new one, the partner’s firewall dropped the new one, and bookings failed for hours before anyone connected it to outbound IPs.

What they changed: every subnet got an explicit outbound path, NAT Gateway with a public IP prefix for the app subnets and Azure Firewall for the ones that need filtering, and partners were given the prefix instead of single IPs. The subnets were switched to private so no VM could fall back on default outbound again, and a Resource Graph query in the monthly review lists any subnet that has no explicit outbound method.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
New VM in a private subnet with no outbound methodapt or Windows Update times outAdd a NAT Gateway (or another explicit method) to the subnet.
Giving partners the VM’s public IPTheir firewall drops your trafficNAT Gateway wins for outbound, so give them the NAT IP or prefix.
Relying on default outbound IPsIP changes break allow-listsMake the subnets private and use an explicit outbound method.
Deleting resources in the wrong orderPublicIPAddressInUse, NAT still attachedDetach it from the subnet, delete the NAT Gateway, and then delete its IPs.
Empty PowerShell argumentsThe CLI creates a public IP you didn’t wantUse ‘””‘ to pass an empty value in Windows PowerShell.
One IP for very busy outboundSNAT port exhaustion, random connection failuresAdd more IPs or a /28 prefix to the NAT Gateway, and look at the SNAT metrics.

Interview questions

Click a question to open it. Each one is worded the way an interviewer would put it, and underneath you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. What does NAT Gateway do in Azure?

Why they ask this: A basic networking service question.

How you might answer: It gives a subnet outbound internet access through one or more fixed public IPs. The VMs share those IPs through source NAT, and nothing on the internet can open a connection back in.

2. Why can a new VM in Azure suddenly not reach the internet when older ones could?

Why they ask this: They’re checking that your knowledge is current for 2026.

How you might answer: Since 31 March 2026, new VNets get private subnets, so there’s no hidden default outbound access any more. You need an explicit method, like NAT Gateway, a public IP, a load balancer outbound rule or a firewall. Older VNets kept the old behaviour.

3. How can a VM with no public IP still run Run Command or report to Azure?

Why they ask this: They want to know about the platform address.

How you might answer: The VM agent talks to the Azure platform through 168.63.129.16, and that works with no internet access. Run Command goes through the agent, so it works even in a completely private subnet.

2–5 years experience

4. A VM has both its own public IP and a NAT Gateway on its subnet. Which IP do websites see?

Why they ask this: They want the outbound precedence rules.

How you might answer: The NAT Gateway’s IP, because NAT Gateway takes precedence over an instance-level public IP for outbound. The VM’s own public IP is then only good for inbound connections, which we usually don’t want anyway.

5. Users report random connection failures to an external API from many VMs behind one NAT Gateway. What do you check?

Why they ask this: They’re testing SNAT exhaustion awareness.

How you might answer: I’d look at the NAT Gateway metrics for SNAT connection counts and dropped packets. If one IP is running short of ports for that destination, I’d add more public IPs or a prefix, and check whether the app reuses its connections or opens a new one for each request.

6. When would you choose Azure Firewall over NAT Gateway for outbound traffic?

Why they ask this: They want trade-off thinking.

How you might answer: When I need to inspect or filter what goes out, like allowing only certain domains, logging what’s accessed or blocking threats, because NAT Gateway only translates and doesn’t filter anything. Firewall costs a lot more, though, so for subnets that need plain outbound access, NAT Gateway is the simpler pick.

Senior level

7. How would you plan outbound connectivity for a company moving 200 VMs into new VNets in 2026?

Why they ask this: They want an end-to-end plan that includes partners and governance.

How you might answer: Each subnet gets an explicit outbound path at design time, NAT Gateway with a public IP prefix for the app tiers and a firewall in the hub for subnets that need filtering. I’d give partners the prefix early and test their allow-lists before migration day. I’d also add a policy or report that flags any subnet without an outbound method, so nobody finds out in the middle of a cutover.

8. Standard or StandardV2 NAT Gateway for a new production design?

Why they ask this: They want you to know the newer SKU and its limits.

How you might answer: StandardV2, if the region has it. It’s zone-redundant by default, supports IPv6 and costs the same, but it needs StandardV2 public IPs and you can’t upgrade a Standard one in place, so it’s a decision to make at the start. Standard is zonal, so for zone resilience you’d need one per zone with matching subnets.

9. A team wants every VM to have a public IP “so outbound works”. How do you respond?

Why they ask this: They want security judgement and a better alternative.

How you might answer: I’d explain that a public IP on every VM opens up inbound attack surface and leaves us with lots of outbound addresses to track. A NAT Gateway on the subnet gives them outbound access through one controlled address with no way in, and for admin access they’d use Bastion, which comes up in Lesson 27.

Quick quiz

Q1. Since 31 March 2026, what do new VNets do by default?

  1. Give every VM a public IP
  2. Use private subnets with no default outbound access
  3. Block all traffic inside the VNet
  4. Create a NAT Gateway
Show answer

B — New VNets get private subnets; you add an explicit outbound method.

Q2. A VM has a public IP and its subnet has a NAT Gateway. Which IP is used for outbound?

  1. The VM’s public IP
  2. The NAT Gateway’s public IP
  3. A random Microsoft IP
  4. Both alternately
Show answer

B — NAT Gateway takes precedence for outbound traffic.

Q3. Why did deleting pip-saat-nat fail?

  1. It was a Basic IP
  2. It was still attached to the NAT Gateway
  3. The VM was running
  4. Wrong region
Show answer

B — Detach it first, or delete the NAT Gateway first.

Q4. How did Run Command work in a subnet with no internet?

  1. Through SSH
  2. Through the VM agent and the platform address 168.63.129.16
  3. Through the NAT Gateway
  4. Through Bastion
Show answer

B — The agent talks to the platform without internet access.

Q5. Which NAT Gateway SKU is zone-redundant?

  1. Basic
  2. Standard
  3. StandardV2
  4. Premium
Show answer

C — StandardV2 is zone-redundant; Standard is zonal.

Quick recap

You’ve given a private subnet a controlled way out, and you know which IP the rest of the world sees.

  • New subnets are private since March 2026: no internet without an explicit outbound method.
  • NAT Gateway gives a subnet outbound access through fixed public IPs, with no way in.
  • NAT Gateway wins over a VM’s own public IP for outbound traffic.
  • Clean up in order: detach from the subnet, delete NAT Gateway, then its IPs.
  • StandardV2 is zone-redundant, needs StandardV2 IPs, and costs the same as Standard.

Next lesson

Lesson 14: Azure DNS: public and private DNS zones → You give your servers friendly names inside the VNet with a private DNS zone.

Further reading: Azure NAT Gateway

Want to go deeper into Azure NAT Gateway? Read Microsoft’s What is Azure NAT Gateway? and Default outbound access in Azure. You can also see the full plan for this course on the Azure Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.