Cloud & Data Centers

Virtual Private Clouds Explained

What a virtual private cloud is, how its address ranges, subnets, routes and gateways fit together, and how to design one.

Key takeaways

  • A VPC is a software-defined private network with an address range you choose.
  • Subnets divide that range, and route tables decide where each subnet's traffic can go.
  • A subnet is public or private mainly because of its routes and whether its machines have public addresses.
  • Peering, transit hubs, VPNs and dedicated links connect a VPC to other networks, provided addresses don't overlap.
  • Planning generous, non-overlapping ranges early avoids painful rebuilds later.

A virtual private cloud, or VPC, is your own isolated network inside a public cloud provider's infrastructure. You choose its private IP address range, divide it into subnets, decide what can reach the internet and set rules about which machines may talk to each other. The physical equipment is shared with other customers, but your network behaves as if it were separate.

Almost every virtual server and managed database you create lives in one, even if the provider made a default network for you and you never looked at it. Understanding it prevents two common problems: things that should connect but can't, and things that shouldn't be reachable but are.

What makes it virtual and private

In a physical office, a network is defined by cables, switches and routers. In a cloud, software creates the same ideas on top of shared hardware. The provider tags and encapsulates your traffic so it stays separate from everyone else's, even when two virtual machines belonging to different customers run on one physical server.

"Private" means isolated by default and addressed from private ranges. It doesn't automatically mean encrypted or secure. A badly written rule can expose a database to the whole internet from inside a perfectly isolated VPC.

Major providers use slightly different names and structures. Amazon Web Services and Google Cloud call it a VPC; Microsoft Azure calls it a virtual network. Scope differs too: in AWS a VPC belongs to one region and each subnet to one availability zone, while Google's VPC networks span regions with regional subnets. Check your provider's documentation before copying a design.

Address ranges

You assign the VPC a block in CIDR notation, such as 10.20.0.0/16. The /16 means the first 16 bits are fixed, leaving 65,536 addresses. Private ranges set aside by RFC 1918 are the normal choice:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16

Choose a block that doesn't collide with your office network, your VPN users' likely home ranges or other VPCs you might connect. Overlapping ranges can't be routed between cleanly, and renumbering a live network is tedious.

Providers reserve a few addresses in each subnet for their own routing and services. AWS, for instance, reserves five per subnet, so a /24 offers 251 usable addresses instead of 256. The CIDR calculator helps with the arithmetic, and subnetting from the ground up explains why it works.

Subnets and availability zones

A subnet is a slice of the VPC's range where you place resources. Typical designs split by role and by availability zone, so the loss of one zone leaves a copy elsewhere. Regions and zones explains the geography.

Subnet (example) Range Holds Internet route
public-a 10.20.0.0/24 Load balancer In and out
public-b 10.20.1.0/24 Load balancer In and out
app-a 10.20.10.0/24 Application servers Out only, via NAT
app-b 10.20.11.0/24 Application servers Out only, via NAT
data-a 10.20.20.0/24 Database None
data-b 10.20.21.0/24 Database replica None

Leaving gaps between groups, as here, gives you room to add zones or tiers without a messy numbering scheme.

Routes and gateways

Each subnet follows a route table, a list saying which destinations go where. There's always a route for traffic within the VPC. The most specific matching entry wins.

  • An internet gateway lets resources with public addresses exchange traffic with the internet.
  • A NAT gateway lets machines with only private addresses start outbound connections, for updates or external APIs, while blocking new connections coming in. It works like the network address translation in a home router.
  • A VPN gateway or dedicated-link attachment leads to your own premises.
  • Private endpoints reach provider services such as storage without going over the public internet.

A "public subnet" is simply one with a route to an internet gateway, holding resources that have public addresses. Remove either and they're no longer directly reachable.

Doors in and out of a VPC
Your VPC Private address range and subnets Private endpoint Provider services, kept internal Peering Another virtual network Internet gateway Public inbound and outbound NAT gateway Outbound only for private hosts VPN or dedicated link Your office or data center Your VPC Private address range and subnets Internet gateway Public inbound and outbound NAT gateway Outbound only for private hosts VPN or dedicated link Your office or data center Peering Another virtual network Private endpoint Provider services, kept internal

Filtering traffic

Routes decide where packets can go; filters decide whether they're allowed. Providers offer firewall rules attached to individual resources, often called security groups, and sometimes a second set applied at the subnet boundary.

The key habit is to allow only what's needed: web traffic to the load balancer, the application's port from the load balancer to the app servers and the database port from the app servers to the database. Cloud networking basics walks through these rules in detail.

A web request through a layered VPC
Visitor Load balancer App server Database HTTPS request 1 Only public entry point Forward to a private address 2 Query on the database port 3 Rows returned 4 Page built 5 HTTPS response 6 Visitor Load balancer App server Database HTTPS request 1 Only public entry point Forward to a private address 2 Query on the database port 3 Rows returned 4 Page built 5 HTTPS response 6

Connecting networks together

Peering links two VPCs so they communicate over private addresses. It is usually not transitive: if A peers with B and B with C, A can't reach C through B.

With many networks, a mesh of peerings grows unwieldy. Providers offer transit hubs that each network attaches to once, with central route tables controlling who sees whom.

To reach an office, a site-to-site VPN builds encrypted tunnels over the internet. A dedicated connection offers a more predictable private path at higher cost and longer lead time. Private doesn't necessarily mean encrypted, so check whether you need to add encryption.

Sometimes you only want to share one service, not a whole network. Private service connection features expose a single endpoint into another VPC and work even where ranges overlap.

One VPC or several?

A single VPC with sensible subnets is enough for many projects. Separate networks start to pay off when you want harder boundaries than subnet rules give.

Common splits are by environment, keeping production apart from testing so an experiment can't touch live data; by team, so each can change its own network without coordinating every rule; and by sensitivity, isolating systems that handle payments or health records to narrow what an audit has to cover. Many organizations also place each environment in its own cloud account or project, which separates permissions and billing as well.

Every split has a price. You'll maintain more route tables, pay for connections between networks in some designs and need a record of who uses which address block. Start with production and non-production, and add more only for a reason you can name.

Following one packet

It helps to trace a single outbound request. Say an application server at 10.20.10.15 needs to download an update from an outside server at 203.0.113.40.

The server's subnet route table has no specific entry for that destination, so the default route sends the packet to the NAT gateway. The security group on the server must allow the outbound connection. The gateway, sitting in a public subnet, rewrites the source address to its own public one, notes the mapping and forwards the packet through the internet gateway.

The reply comes back to the NAT gateway, which looks up the mapping and delivers it to 10.20.10.15. The stateful security group recognizes it as part of a connection the server opened. If any step is missing, such as the default route or the outbound rule, the download simply times out.

Names and DNS

VPCs include a resolver so resources can find each other by name. You can add private zones whose records exist only inside your networks. When connecting to an office, decide which side answers which names, a form of split-horizon DNS. Many "network" faults turn out to be a name resolving to the wrong address.

A design checklist

  1. Pick a range larger than you think you need, and record it so no one reuses it.
  2. Create subnets in at least two zones for anything that must stay up.
  3. Put only entry points in public subnets.
  4. Give databases no route to the internet.
  5. Reach servers through a VPN or the provider's session service, not open remote-login ports.
  6. Turn on flow logs, records of which connections were allowed or refused, for the parts that matter.
  7. Define the network in code so changes are reviewed and repeatable.

Managed and serverless services

Not everything you use sits inside your VPC by default. Object storage, queues and many managed services have public endpoints operated by the provider, protected by identity permissions. Serverless functions often run outside your network until you attach them to it, and attaching them can change how they reach the internet.

For each service, answer two questions: which network path does the traffic take, and what stops someone else from using that path? Private endpoints narrow the first. Identity policies answer the second, and you generally need both.

Costs and common surprises

The VPC itself is often free or cheap, but pieces attached to it aren't necessarily: NAT gateways, VPN connections, transit hubs, public IP addresses and data crossing zones or leaving the cloud may all be billed. Prices change, so check the provider's pricing pages.

A frequent surprise is heavy traffic to the provider's own storage flowing through a NAT gateway when a private endpoint would keep it internal. Another is a forgotten test network with gateways still running. Reviewing the bill by network component catches both.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Cloud & Data Centers →

Latest news on this topic