Ravindra BagaleCourses & study guides मराठी Track your progress

How to Create Public and Private Subnets in AWS VPC

A VPC on its own is just a big range of private IPs. To put web, app and database servers in it, you split it into subnets, decide which subnets can reach the internet, and tell the VPC where to send traffic. This chapter carves 10.0.0.0/16 into /20 subnets one after another in binary, shows why AWS refuses overlapping subnets, places one subnet in each Availability Zone, explains where a server's private IP comes from, lists the 5 IPs AWS keeps in every subnet, counts how many subnets fit, and then makes one subnet public with an internet gateway and route tables, while the others stay private. The CIDR basics are in the previous chapter, What Is AWS VPC and How to Calculate CIDR IP Ranges.

What you'll learn in this class

  • Carving /20 subnets one after another, in binary
  • The shortcut: /20 blocks step by 16
  • Why overlapping subnets are refused
  • One subnet lives in one Availability Zone
  • The default VPC and its default subnets
  • Tenancy: default, dedicated instance and Dedicated Host
  • Lab: a public IP is not enough without a route to the internet gateway
  • Private IP ranges (RFC 1918), public IPs and DHCP
  • The 5 IPs AWS keeps in every subnet
  • Usable IPs, and how many subnets fit in a VPC
  • Internet gateway: public vs private subnets
  • Route tables: Destination and Target, and the main route table
  • Building it in the console

1. Why the VPC needs subnets

Why: the three tiers need separate places in the VPC: the web servers must be reachable from the internet, the app and database servers must not. A subnet is a block of the VPC's range, and each subnet gets its own rules.

The plan for this chapter: VPC 10.0.0.0/16 (65,536 IPs, 10.0.0.0 to 10.0.255.255), split into /20 subnets of 4,096 IPs each. How /16 and /20 are counted is in Worked example: 10.0.0.0/20 and its last IP.

Classroom line

How do we decide? It's simple: look at the CIDR block.

2. Subnet 1: 10.0.0.0/20

  1. /20 means the first 20 bits stay fixed in every IP of the subnet: two full octets and the first 4 bits of the 3rd octet.
  2. The 3rd octet is 0 = 0000 0000. Set its 4 free bits to 1: 0000 1111 = 15.
  3. Subnet 1 = 10.0.0.0 to 10.0.15.255, 4,096 IPs.

Classroom line

When I convert to binary, the first 20 bits stay fixed in every IP.

3. Subnet 2: start at the last IP + 1

Rule: the next subnet starts right after the last IP of the previous one.

  1. Last IP of subnet 1: 10.0.15.255. Add 1: the 4th octet rolls over to 0 and the 3rd goes up by 1, so 10.0.16.0.
  2. Subnet 2 = 10.0.16.0/20. Now find its last IP.
  3. Write the binary places by doubling eight times from 1: 1, 2, 4, 8, 16, 32, 64, 128. From the left: 128 64 32 16 8 4 2 1.
  4. Pick the places that add up to 16: only 16. So 16 = 0001 0000.
  5. Keep the first 4 bits 0001, set the last 4 to 1: 0001 1111 = 16 + 8 + 4 + 2 + 1 = 31.
  6. Subnet 2 = 10.0.16.0 to 10.0.31.255.

Classroom line

Keep doubling until you have done it eight times.

Classroom line

From these, find the numbers whose sum gives this number.

The second /20 subnet, found in binary 1. Start after the last IP: 10.0.15.255 + 1 = 10.0.16.0 10.0.16.0/20 0 0 0 1 128 64 32 16 0 0 0 0 8 4 2 1 2. 3rd octet 16 in binary: 16 = 0001 0000 16 = 0001 0000 0 0 0 1 128 64 32 16 0 0 0 0 8 4 2 1 3. Keep the 4 fixed bits, set the 4 free bits to 1: 0001 1111 =31 0001 1111 = 16+8+4+2+1 = 31 0 0 0 1 128 64 32 16 1 1 1 1 8 4 2 1 4. Range 10.0.16.0 - 10.0.31.255. The next one starts at10.0.32.0 10.0.16.0 - 10.0.31.255 0 0 0 1 128 64 32 16 1 1 1 1 8 4 2 1 blue = fixed bits, green = free bits, orange = free bits set to 1 Shortcut: /20 blocks step by 16 in the 3rd octet: 0, 16, 32, 48 ...

Figure 1. Animation: 10.0.15.255 + 1 = 10.0.16.0; 16 in binary is 0001 0000; keep the 4 fixed bits and set the 4 free bits to 1, 0001 1111 = 31; so subnet 2 is 10.0.16.0 to 10.0.31.255 and the next one starts at 10.0.32.0.

4. Subnet 3 and the shortcut

  1. Last IP of subnet 2 + 1: 10.0.31.255 + 1 = 10.0.32.0.
  2. 32 = 0010 0000. Keep 0010, set the rest to 1: 0010 1111 = 32 + 8 + 4 + 2 + 1 = 47.
  3. Subnet 3 = 10.0.32.0 to 10.0.47.255.

The shortcut: a /20 has 4 free bits in the 3rd octet, so each block covers 16 values of it. The blocks start at 0, 16, 32, 48, 64, and so on, and each ends 15 later.

Subnet CIDR First IP Last IP
1 10.0.0.0/20 10.0.0.0 10.0.15.255
2 10.0.16.0/20 10.0.16.0 10.0.31.255
3 10.0.32.0/20 10.0.32.0 10.0.47.255
4 10.0.48.0/20 10.0.48.0 10.0.63.255
16 10.0.240.0/20 10.0.240.0 10.0.255.255

Classroom line

You must be able to do this; they ask it in interviews.

5. Overlapping subnets are refused

What: two subnets of one VPC can't share any IP. If you try to create 10.0.14.0/24 while 10.0.0.0/20 exists, AWS refuses it with a message that the CIDR conflicts with another subnet: 10.0.14.0 to 10.0.14.255 lies inside 10.0.0.0 to 10.0.15.255.

How to avoid it:

  1. Carve the subnets in order, each starting at the last IP + 1 of the one before.
  2. Don't leave gaps. A gap of odd-sized space between blocks is hard to use later, and those IPs are wasted.
  3. Keep a small table like the one above for every VPC you design.

Classroom line

You'll get an IP overlap error.

Classroom line

The IPs in between got wasted, right?

Overlapping subnets are refused 3rd octet of the VPC 10.0.0.0/16 10.0.0.0/20 0 – 15 10.0.16.0/20 16 – 31 10.0.32.0/20 32 – 47 new subnet 10.0.14.0/24 lies inside 10.0.0.0/20: overlap, refused next free: 10.0.48.0/20 carve in order, with no gaps

Figure 2. Along the 3rd octet, 10.0.0.0/20 takes 0 to 15, 10.0.16.0/20 takes 16 to 31 and 10.0.32.0/20 takes 32 to 47. A new 10.0.14.0/24 lies inside the first block, so it is refused; the next free block is 10.0.48.0/20.

6. One subnet lives in one Availability Zone

What:

  1. The VPC covers the whole Region, but each subnet is in exactly one AZ. You choose the AZ when you create the subnet.
  2. A common layout: 10.0.0.0/20 in ap-south-1a, 10.0.16.0/20 in ap-south-1b, 10.0.32.0/20 in ap-south-1c.
  3. A server is launched into a subnet, so the subnet decides its AZ. To spread servers over AZs, create subnets in each AZ.
  4. Each tier can have its own subnets: web subnets, app subnets and database subnets.
One VPC across the Region, each subnet in one AZ Region ap-south-1 VPC 10.0.0.0/16 ap-south-1a 10.0.0.0/20 usable for servers: 10.0.0.4 - 10.0.15.254 ap-south-1b 10.0.16.0/20 usable for servers: 10.0.16.4 - 10.0.31.254 ap-south-1c 10.0.32.0/20 usable for servers: 10.0.32.4 - 10.0.47.254

Figure 3. VPC 10.0.0.0/16 across Region ap-south-1, one subnet per AZ: 10.0.0.0/20 in 1a, 10.0.16.0/20 in 1b, 10.0.32.0/20 in 1c, each with its usable range for servers.

7. The default VPC and its subnets

What AWS made for you: every Region of your account has a default VPC 172.31.0.0/16, with one default /20 subnet in each AZ: 172.31.0.0/20, 172.31.16.0/20, 172.31.32.0/20, and so on.

  1. When you launch an instance and don't choose a subnet, AWS puts it in one of the default subnets.
  2. To control where it goes, open Network settings > Edit in the launch wizard and pick the VPC and the Subnet.

Why it exists: so that you can launch a server in the first minute, without designing a network. AWS builds the same network in every Region that is turned on in your account.

What is inside a default VPC:

  1. CIDR 172.31.0.0/16 in every Region.
  2. One default subnet per Availability Zone, each a /20. A Region with 6 AZs, like us-east-1, has 6 default subnets.
  3. One internet gateway, already attached.
  4. A main route table with 0.0.0.0/0 to that internet gateway, so all default subnets are public.
  5. A main network ACL that allows everything, and a DHCP option set that hands each server its private IP.
  6. Regions launched after March 2019 (for example Cape Town or Hyderabad) are opt-in: they stay disabled, with nothing in them, until you enable them for your account.

Worked example: the default /20 subnets in us-east-1

  1. A /20 holds 2^(32−20) = 2^12 = 4,096 IPs, which is 16 values of the 3rd octet.
  2. Subnet 1: 172.31.0.0/20 (172.31.0.0 to 172.31.15.255).
  3. Subnet 2: 172.31.16.0/20.
  4. Subnet 3: 172.31.32.0/20.
  5. Subnet 4: 172.31.48.0/20.
  6. Subnet 5: 172.31.64.0/20.
  7. Subnet 6: 172.31.80.0/20 (ends at 172.31.95.255).
  8. Next free block for your own subnet: 172.31.96.0/20, then 172.31.112.0/20.
  9. Usable IPs in each: 4,096 − 5 = 4,091.

Tenancy: who else is on the same hardware

An Availability Zone is one or more data centers. A data center has racks, and a rack has physical servers (hosts). Your EC2 instance runs on one host.

  1. Default (shared) tenancy: your instance may run on a host that also runs other customers' instances. Each instance is isolated, and this is the cheapest option. Most workloads use it.
  2. Dedicated instance: your instances run on hardware used only by your account. Use it when a rule (compliance) says no sharing.
  3. Dedicated Host: one whole physical server is given to you, and you see and control it. Use it for software licences counted per physical server.
  4. Dedicated options cost more, so pick Default unless a rule asks otherwise.

8. Where a server's private IP comes from

  1. The private IP always comes from the range of the server's subnet. A server in 10.0.16.0/20 gets an IP between 10.0.16.4 and 10.0.31.254.
  2. You don't type it. The VPC's DHCP service offers the instance one free address from the subnet, and the instance uses it. You can also choose a specific free IP from the range when you launch.
  3. Who hands out addresses at home is in Who hands out IP addresses.

9. Private and public IPs

Private IP ranges (RFC 1918): these three ranges are kept for private networks and are never used on the internet. Use them for VPCs.

Range CIDR Size
10.0.0.0 to 10.255.255.255 10.0.0.0/8 16,777,216
172.16.0.0 to 172.31.255.255 172.16.0.0/12 1,048,576
192.168.0.0 to 192.168.255.255 192.168.0.0/16 65,536

Public IPs are owned by internet providers and clouds. In AWS a server gets one from the EC2 public IP pool (auto-assigned) or as an Elastic IP (What an Elastic IP is). AWS charges for every public IPv4 address by the hour, so only the servers that must be reached from the internet get one.

Classroom line

You don't get them for free; there are charges.

10. The 5 IPs AWS keeps in every subnet

Example: subnet 10.0.32.0/20 (10.0.32.0 to 10.0.47.255):

  1. 10.0.32.0: the network address.
  2. 10.0.32.1: the VPC router.
  3. 10.0.32.2: the Amazon DNS server.
  4. 10.0.32.3: kept by AWS for future use.
  5. 10.0.47.255: the last IP. AWS keeps it because a VPC doesn't support broadcast.

So the first server can get 10.0.32.4, and the last usable IP is 10.0.47.254.

Classroom line

Now five IPs of this one go away.

AWS keeps 5 IPs in every subnet: 10.0.32.0/20 10.0.32.0 network address 10.0.32.1 VPC router 10.0.32.2 Amazon DNS 10.0.32.3 future use 10.0.32.4 first usable ... plain | 10.0.47.254 last usable 10.0.47.255 last IP, reserved 4,096 IPs - 5 reserved = 4,091 usable /24: 256 - 5 = 251 /28: 16 - 5 = 11 /16: 65,536 - 5 = 65,531

Figure 4. In 10.0.32.0/20, AWS keeps 10.0.32.0 (network), 10.0.32.1 (VPC router), 10.0.32.2 (Amazon DNS), 10.0.32.3 (future use) and 10.0.47.255 (last IP). Usable: 10.0.32.4 to 10.0.47.254, 4,096 − 5 = 4,091.

11. Usable IPs and how many subnets fit

Usable IPs = total − 5:

Subnet Total Usable
/16 65,536 65,531
/20 4,096 4,091
/24 256 251
/28 16 11

/16 is the largest and /28 the smallest block AWS allows, for a VPC and for a subnet. A VPC that needs more can get extra CIDR blocks later.

How many subnets fit in a /16 VPC: divide the sizes, or use 2 to the power (subnet prefix − 16).

  1. /20: 65,536 ÷ 4,096 = 16 (2 to the power 4).
  2. /22: 65,536 ÷ 1,024 = 64 (2 to the power 6).
  3. /24: 65,536 ÷ 256 = 256 (2 to the power 8).

Classroom line

How many subnets can I create inside this VPC?

An architect's design for Mumbai:

  1. VPC 172.31.0.0/16 in ap-south-1.
  2. 172.31.0.0/20 in ap-south-1a, 172.31.16.0/20 in ap-south-1b, 172.31.32.0/20 in ap-south-1c.
  3. 4,091 usable IPs in each, and 13 more /20 blocks free for later.

Classroom line

Who are we? We are the architects.

12. Internet gateway: public and private subnets

Why: a new VPC has no way to the internet at all. In a 3-tier app only the web tier gets public IPs; the app and database tiers stay private.

What:

  1. An internet gateway (IGW) connects a VPC to the internet. A VPC can have one internet gateway attached.
  2. A subnet is public if its route table sends 0.0.0.0/0 to the internet gateway. Otherwise it is private.
  3. So "public" and "private" are not settings of the subnet itself: the route table decides.

Classroom line

Each VPC gets one internet gateway: think of one internet cable going to that VPC's router.

13. Route tables: Destination and Target

What: a route table is a list of routes. Each route has two columns:

  1. Destination: the IP range the traffic is going to, as a CIDR.
  2. Target: where to send that traffic.

The public route table:

Destination Target
10.0.0.0/16 local
0.0.0.0/0 igw-0abc (the internet gateway)

The private route table:

Destination Target
10.0.0.0/16 local
  1. The local route is in every route table and can't be removed: all subnets of the VPC can talk to each other.
  2. When several routes match, the most specific one wins: traffic to 10.0.16.7 matches both rows of the public table, and 10.0.0.0/16 (a /16 is more specific than /0) sends it locally.
  3. Traffic for the internet matches only 0.0.0.0/0. In the private table nothing matches, so it isn't sent.
Public subnet vs private subnet: it is the routetable Internet Internet gateway to the internet: 0.0.0.0/0matches, sent to the IGW VPC 10.0.0.0/16 Public subnet 10.0.0.0/20: web public route table Destination Target 10.0.0.0/16 local 0.0.0.0/0 igw-0abc Private subnet 10.0.16.0/20: app private route table Destination Target 10.0.0.0/16 local ✗ to the internet: no matching route, not sent

Figure 5. Animation: the public subnet's route table has 0.0.0.0/0 to the internet gateway, so internet traffic leaves through it; the private subnet's route table has only the local route, so internet traffic has nowhere to go.

14. The main route table

What: every VPC has a main route table. Any subnet that you have not explicitly associated with another route table uses the main one automatically.

  1. Default VPC: its main route table has 0.0.0.0/0 to the internet gateway, so every default subnet is public.
  2. A new custom VPC: its main route table has only the local route, so every new subnet starts private.
  3. Good practice: keep the main route table private. Create a separate public route table and associate only the web subnets with it. Then a subnet that someone forgets to associate stays private, not public.

Classroom line

There's one route table that spreads like a virus: the main route table.

The main route table catches every subnet you didnot associate Default VPC (made by AWS) main route table Destination Target 172.31.0.0/16 local 0.0.0.0/0 igw-... Every default subnet uses it, so every default subnet is public. Custom VPC (made by you) main route table: keep it private Destination Target 10.0.0.0/16 local your public route table Destination Target 10.0.0.0/16 local 0.0.0.0/0 igw-... Associate only the web subnet with it.

Figure 6. In the default VPC the main route table sends 0.0.0.0/0 to the internet gateway, so every default subnet is public. In a custom VPC keep the main route table private (local only) and associate only the web subnet with your own public route table.

15. Build it in the console

Part A: subnets (in the VPC 10.0.0.0/16 from the previous chapter)

  1. VPC > Subnets > Create subnet. Pick the VPC ID of my-vpc.
  2. Subnet name web-a, Availability Zone ap-south-1a, IPv4 subnet CIDR block 10.0.0.0/20.
  3. Add new subnet: app-b, ap-south-1b, 10.0.16.0/20.
  4. Add new subnet: db-c, ap-south-1c, 10.0.32.0/20.
  5. Create subnet. Each shows Available IPv4 addresses 4091.

Part B: internet gateway

  1. Internet gateways > Create internet gateway, name my-igw, Create.
  2. Actions > Attach to VPC, pick my-vpc, Attach internet gateway.

Part C: public route table

  1. Route tables > Create route table, name public-rt, VPC my-vpc, Create.
  2. Routes > Edit routes > Add route: Destination 0.0.0.0/0, Target Internet Gateway my-igw. Save changes.
  3. Subnet associations > Edit subnet associations: tick web-a only. Save associations.
  4. Select web-a, Actions > Edit subnet settings, tick Enable auto-assign public IPv4 address, Save, so servers launched there get a public IP.

app-b and db-c stay on the main route table: private.

Part D: lab in the default VPC: a public IP is not enough

Why: many people think a server with a public IP is reachable from the internet. This lab shows that the route table decides.

  1. VPC > Subnets > Create subnet in the default VPC: DefaultVpcPublicSubnet, us-east-1a, 172.31.96.0/20.
  2. Add new subnet: DefaultVpcPvtSubnet, us-east-1b, 172.31.112.0/20. Create subnet.
  3. Both new subnets attach to the main route table automatically, and in the default VPC that table is public.
  4. Route tables > Create route table: CustomPvtRouteTable in the default VPC. It has only the local route.
  5. Subnet associations: associate DefaultVpcPvtSubnet with CustomPvtRouteTable. DefaultVpcPublicSubnet stays on the main route table.
  6. Launch a t2.micro Amazon Linux 2023 instance public ec2 in DefaultVpcPublicSubnet with Auto-assign public IP enabled and a security group that allows SSH (22) and HTTP (80).
  7. Connect: ssh -i key.pem ec2-user@<public-ip>.
  8. Install and start Nginx:

sudo yum install nginx -y sudo service nginx start

  1. Put a page in /usr/share/nginx/html/ and open http://<public-ip>/ in the browser: it loads.
  2. Launch a second instance pvt ec2 in DefaultVpcPvtSubnet, and on purpose enable Auto-assign public IP here too, with the same security group.
  3. Try ssh -i key.pem ec2-user@<its-public-ip>: it times out. The server has a public IP, but its subnet's route table has no route to the internet gateway, so replies never leave the VPC.
  4. Add a route to CustomPvtRouteTable: Destination 0.0.0.0/0, Target the default VPC's internet gateway. SSH now works, and after installing Nginx the page loads.
  5. Remove that route again: the page stops loading.

Result: a public IP gives a server an address on the internet. The route 0.0.0.0/0 → igw gives it a way out. It needs both.

Classroom line

As soon as you create a new subnet, the main route table attaches to it automatically.

Classroom line

Until there is a route to the internet gateway, your request will never reach that server.

16. When something goes wrong

  1. "conflicts with another subnet": the new CIDR overlaps an existing subnet. Take the next free block from your table.
  2. The CIDR is refused as outside the VPC: the subnet must lie inside the VPC's range, for example 10.0.x.x in 10.0.0.0/16.
  3. A server in the "public" subnet can't be reached: check that it has a public IP, that the subnet's route table has 0.0.0.0/0 to the IGW, that the IGW is attached, and that the security group allows the port.
  4. A subnet you meant to be private is public: it is associated with the public route table, or the main route table has an IGW route. Fix the association.
  5. You can't create more servers in a subnet: it ran out of usable IPs; remember the 5 that AWS keeps.

Ravindra Bagale's Tip

Before you open the console, write the plan on paper: one row per subnet with its name, AZ, CIDR, first and last IP, and public or private. Then the overlap error never comes, and when someone asks why a server is public, the answer is one line in your table: which route table its subnet uses.

17. The whole class on one page

  1. A subnet is a block of the VPC's range; /20 subnets of 10.0.0.0/16 start at 0, 16, 32 ... in the 3rd octet.
  2. Next subnet = last IP + 1. Binary: 16 = 0001 0000 → 0001 1111 = 31; 32 = 0010 0000 → 0010 1111 = 47.
  3. Overlapping subnets are refused ("conflicts with another subnet"); carve in order with no gaps.
  4. Each subnet is in exactly one AZ; the default VPC 172.31.0.0/16 has a default /20 in each AZ.
  5. A server's private IP comes from its subnet, handed out by DHCP. Private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Public IPv4 addresses are charged.
  6. AWS keeps 5 IPs per subnet: network, VPC router, DNS, future use, last. Usable = total − 5: /20 4,091, /24 251, /28 11.
  7. A /16 holds 16 × /20, 64 × /22, 256 × /24.
  8. One internet gateway per VPC. Public subnet = route table with 0.0.0.0/0 → IGW; private = no such route.
  9. Route table columns: Destination (CIDR), Target (local, igw-...).
  10. Subnets without an explicit association use the main route table; keep it private in a custom VPC.

18. Try at home

Try at home

Task 1: on paper

  1. Write the first five /20 subnets of 10.0.0.0/16 with first and last IPs. Check the 5th: 10.0.64.0 to 10.0.79.255.
  2. Split 10.0.0.0/16 into /22 subnets: write the first three. How many fit?

Task 2: in the console

  1. In your practice VPC, create web-a, app-b and db-c as in section 15.
  2. Try to create 10.0.14.0/24 and read the error.
  3. Attach an internet gateway, create public-rt, and associate only web-a.

Task 3: prove it

  1. Launch a small instance in web-a and one in app-b. Which one gets a public IP? Can you SSH to each from your laptop?
  2. Clean up: terminate the instances, delete the subnets, detach and delete the IGW, delete the route table and the VPC.

Recap

In short

  1. Carve subnets in order: the next one starts at the last IP + 1, and /20 blocks step by 16.
  2. Subnets can't overlap, and each lives in one AZ.
  3. AWS keeps 5 IPs in every subnet, so a /20 has 4,091 usable.
  4. A subnet is public only when its route table sends 0.0.0.0/0 to the internet gateway.
  5. Route tables read Destination then Target; local connects the whole VPC.
  6. Keep the main route table private and give web subnets their own public route table.

Practice Tasks

About this scenario

Hyderabad Biryani Hub is a cloud kitchen business in Hyderabad. Syed Imran looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 12

Easy How many addresses in a /16?

Why: Picking a VPC size needs this count.

What to do: Hyderabad Biryani Hub plans the VPC 10.152.0.0/16. How many IP addresses does it hold in total?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Create a VPC

Why: A VPC is your own private network in AWS. Everything else lives inside it.

What to do: Create a VPC with the CIDR block 10.3.0.0/16.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Create an internet gateway

Why: Without an internet gateway, nothing in the VPC can reach the internet.

What to do: Create a new internet gateway.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Create a subnet in one AZ

Why: Subnets split the VPC range and each one lives in exactly one AZ.

What to do: In vpc-0300e2a3f3deadbee, create subnet 10.3.1.0/24 in ap-south-2a.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Find the VPC router address

Why: AWS reserves base+1 for the router.

What to do: Which address does AWS reserve for the VPC router in subnet 10.152.4.0/24?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Usable IPs in an AWS /24 subnet

Why: AWS keeps 5 addresses in every subnet.

What to do: How many addresses can Hyderabad Biryani Hub use for servers in subnet 10.152.1.0/24 on AWS?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Add the internet route

Why: A subnet is "public" only when its route table sends 0.0.0.0/0 to an internet gateway.

What to do: In route table rtb-030300d2b3c3bb22, send all internet traffic (0.0.0.0/0) to igw-00300d2b3c3aa11.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Link a subnet to a route table

Why: Until you associate it, a subnet uses the main route table.

What to do: Associate subnet subnet-030300d2b3c3bb1 with route table rtb-030300d2b3c3bb22.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Attach the internet gateway

Why: A gateway does nothing until it is attached to a VPC.

What to do: Attach igw-00300d2b3c3aa11 to vpc-0300e2a3f3deadbee.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium First usable IP for a server

Why: The first 4 addresses are reserved by AWS.

What to do: What is the first IP address a server can get in 10.152.20.0/24 on AWS?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Pick the smallest prefix

Why: Right-sizing saves address space.

What to do: A subnet must hold 100 servers on AWS. What is the largest prefix number (smallest subnet) that fits? Answer like /25.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Split a /24 into two

Why: Public and private subnets often split one block.

What to do: Split 10.152.8.0/24 into two equal subnets. Write both CIDRs separated by a comma.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Quick revision cards

Revise this chapter in two minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens its lesson.

AWS reserves 5 IPs in subnet 10.0.0.0/20: .0 network, .1 VPC router, .2 DNS, .3 future use, 10.0.15.255 broadcast.
Card 1 of 5: The 5 reserved IPs in a subnet · Download PNG
Public vs private subnet: a public subnet has a route 0.0.0.0/0 to the internet gateway; a private subnet does not.
Card 2 of 5: Public vs private subnet · Download PNG
Internet gateway: one per VPC, attach it first, then add route 0.0.0.0/0 to the IGW in the public route table.
Card 3 of 5: Internet gateway (IGW) · Download PNG
Route tables: the local route 10.0.0.0/16 is always there; the public route table adds 0.0.0.0/0 to the internet gateway.
Card 4 of 5: Route tables · Download PNG
Internet gateway vs NAT gateway: IGW is two-way for public subnets and free; NAT is outbound-only for private subnets and billed hourly.
Card 5 of 5: IGW vs NAT gateway · Download PNG
Revision card: Carving /20 subnets in a VPC. Subnets must not overlap. You need a quick way to find where each one starts. A /20 has 4096 IPs, so in a /16 VPC the third number steps by 16. Start at 10.0.0.0/20 and add 16 to the third number each time. Put each subnet in one AZ. VPC 10.0.0.0/16:
Revision card: Carving /20 subnets in a VPC · Download PNG
Revision card: EC2 tenancy. Some companies must not share physical hardware with other customers, for rules or licences. Tenancy = who shares the physical server. Default (shared), dedicated instance, or Dedicated Host. Pick it in the VPC or under Advanced details at launch. Keep default unless a rule needs more. Bank with per-socket licences: Dedicated Host. Normal website: default.
Revision card: EC2 tenancy · Download PNG
Comparison: Dedicated instance vs Dedicated Host. Dedicated instance: An EC2 on hardware used only by your account. Dedicated Host: A whole physical server that you rent and see.
Comparison: Dedicated instance vs Dedicated Host · Download PNG
Interview card: How many usable IPs are in a /24 subnet in AWS?. 251. A /24 has 256 IPs and AWS keeps 5 in every subnet. AWS uses them for network, VPC router, DNS, future use and broadcast. 10.0.1.0/24: reserved .0 .1 .2 .3 .255.
Interview card: How many usable IPs are in a /24 subnet in AWS? · Download PNG
Interview card: An EC2 has a public IP but you still cannot reach it. Why?. Its subnet route table has no 0.0.0.0/0 route to an internet gateway. A public IP alone does nothing without a path to the internet. Attach an IGW to the VPC and add the route; also allow the port in the SG.
Interview card: An EC2 has a public IP but you still cannot reach it. Why? · Download PNG
Interview card: Why does AWS refuse overlapping subnets?. Two subnets with the same IPs would make routing ambiguous. A packet to 10.0.16.5 must belong to exactly one subnet. 10.0.0.0/20 covers up to 10.0.15.255; next starts 10.0.16.0/20.
Interview card: Why does AWS refuse overlapping subnets? · Download PNG
Interview card: Can one subnet span two Availability Zones?. No. A subnet lives in exactly one AZ. For high availability you need subnets in two AZs and servers in both. public-1a 10.0.0.0/20, public-1b 10.0.16.0/20.
Interview card: Can one subnet span two Availability Zones? · Download PNG

More cards: Ravi Sir's Cards: AWS VPC and Subnets.