> For the complete documentation index, see [llms.txt](https://mamawhocode.gitbook.io/aws/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mamawhocode.gitbook.io/aws/services/network/vpc/subnet.md).

# Subnet

## Overview

<figure><img src="https://2259236002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fuh9xZDZ53qGqmMCM44PU%2Fuploads%2FiT91VFgzoaLvaYy80KSj%2Fimage.png?alt=media&amp;token=0aa32a75-f9b2-4620-9e7a-eaa5319ea9b2" alt="" width="198"><figcaption><p>a subnet</p></figcaption></figure>

* Subnet is a sub of VPC network, which you can group resources based on security or operational needs. ***A range*** ***of IP addresses.***
* 2 types of subnet (with its `route table`)
  * private subnet: ![](https://2259236002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fuh9xZDZ53qGqmMCM44PU%2Fuploads%2Fgit-blob-cb2e8536a5c87eea4dc143ce0c4584c4676bd050%2Ffigure_20230416145739.png?alt=media)
  * public subnet: ![](https://2259236002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fuh9xZDZ53qGqmMCM44PU%2Fuploads%2Fgit-blob-3fadb747d82818e3102968fe6c231bfc5a313fca%2Ffigure_20230416145513.png?alt=media)

### NAT Gateway

[NAT Gateway](/aws/services/network/vpc/nat.md)

### Route table

* The rule for traffic inside the VPC
* An important property of subnet. It contains ***set of rules***, called routes. Routes are used to determine where network traffic, from your subnet or gateway, is directed.
* By default, it will contain rules of
  * local traffic.
  * 0.0.0.0/0 if a gateway is attached.

<figure><img src="https://2259236002-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fuh9xZDZ53qGqmMCM44PU%2Fuploads%2Fgit-blob-37db1abe7c6e158a18d67d3fa27386650f852f95%2Ffigure_20230416145839.png?alt=media" alt=""><figcaption></figcaption></figure>

## Trivia

* Each subnet must reside *<mark style="color:red;">entirely</mark>* within one [AZ](/aws/services/network/region/az.md) and cannot span zones.
* Every subnet that you create, automatically associated with the [Main route table](#concepts) of the VPC.

## Concepts

* ***Main route table***: when you create a VPC, this table is automatically created. This control the routing of all the subnets that do not have a Custom route table associated with them.
  * Cannot be deleted.
  * Can be customized.
