Abekus — AI learning and job matching platform logo

Vpc, subnet and route table

Lesson 2 of 72 in AWS Interview Mastery. Free to read, with practice questions to try.

What a VPC is

A Virtual Private Cloud (VPC) is your own private network inside AWS, created in one Region. For Kiranakart, that means a network in ap-south-1 (Mumbai) that belongs to Kiranakart's account and is logically separated from other customers' networks.

You define a VPC with one CIDR block, an address range such as 10.0.0.0/16. The /16 gives the VPC 65,536 addresses to divide up among the subnets you build inside it.

Subnets live in one zone

A subnet is a smaller slice of the VPC's CIDR block, and each subnet is bound to exactly one Availability Zone. A subnet can never stretch across ap-south-1a and ap-south-1b, so to use both zones Kiranakart needs at least one subnet in each.

Splitting 10.0.0.0/16 into two /24 subnets works well: 10.0.1.0/24 in ap-south-1a and 10.0.2.0/24 in ap-south-1b. Each /24 holds 256 addresses (2 to the power of 8), of which AWS reserves five, so 251 are usable; both sit inside the VPC without overlapping.

Route tables and local routes

A route table is a list of routes, and each route pairs a destination CIDR with a target. Traffic leaving a subnet is checked against the route table that subnet is associated with, and the most specific matching route decides where it goes.

Every route table contains a local route for the VPC's own CIDR block, which lets subnets in the same VPC reach each other. Here is a route table for Kiranakart's app subnets:

Route tableDestinationTarget
rtb-app10.0.0.0/16local

A packet from 10.0.1.5 to 10.0.2.20 falls inside 10.0.0.0/16, so it follows the local route to the other subnet.

Associating subnets with route tables

Each subnet is associated with exactly one route table, but one route table can serve many subnets. A VPC also has a main route table, which any subnet without an explicit association uses. A new VPC starts with only the local route in its main table.

Here is how Kiranakart's three subnets are wired:

SubnetZoneRoute table used
10.0.1.0/24ap-south-1artb-app (explicit)
10.0.2.0/24ap-south-1brtb-app (explicit)
10.0.3.0/24ap-south-1amain (no association)

Predict it: a new subnet 10.0.4.0/24 is created with no association. Which route table does it use? The main route table, because it has no explicit association.

Overlapping CIDR ranges

Every subnet's CIDR block must fit inside the VPC's CIDR block, and no two subnets in the same VPC may overlap. Overlap means some addresses belong to both ranges, and that is not allowed. Kiranakart's planning has three candidates to check:

CandidateCheckResult
10.0.1.0/24 and 10.0.1.0/2510.0.1.0/25 sits inside 10.0.1.0/24Overlap, not allowed
10.1.1.0/24 in a 10.0.0.0/16 VPC10.1.x.x is outside 10.0.0.0/16Does not fit
10.0.1.0/24 and 10.0.2.0/24Separate ranges inside the VPCValid

Always check both rules before you build.

Practice questions

  1. 1.

    Which pair of subnet CIDR blocks can both exist in the same 10.0.0.0/16 VPC?

    • A.

      10.0.1.0/25 and 10.0.1.64/26

    • B.

      10.1.1.0/24 and 10.0.2.0/24

    • C.

      10.0.1.0/24 and 10.0.1.0/25

    • D.

      10.0.1.0/24 and 10.0.2.0/24

    Show answer
    Answer: D.

    10.0.1.0/24 and 10.0.2.0/24

    10.0.1.0/24 and 10.0.2.0/24 are separate ranges inside the VPC block, so they are valid. 10.0.1.0/25 and 10.0.1.64/26 overlap because the /26 sits inside the /25. 10.1.1.0/24 lies outside 10.0.0.0/16, and 10.0.1.0/25 sits inside 10.0.1.0/24.

  2. 2.

    Which statement about subnets is correct?

    • A.

      A subnet can span ap-south-1a and ap-south-1b

    • B.

      A subnet is bound to exactly one Availability Zone

    • C.

      A subnet belongs to a whole Region rather than a zone

    • D.

      A subnet may use a CIDR block outside its VPC's range

    Show answer
    Answer: B.

    A subnet is bound to exactly one Availability Zone

    Each subnet resides in one zone and cannot span two, which is why Kiranakart needs a subnet in each zone to use both. A subnet belongs to one zone, not to a Region, and its CIDR block must lie inside the VPC's block.

  3. 3.

    Kiranakart creates a VPC with the CIDR block 10.0.0.0/16. How many IP addresses does the VPC's block cover?

    • A.

      65,536

    • B.

      256

    • C.

      16,384

    • D.

      4,096

    Show answer
    Answer: A.

    65,536

    A /16 leaves 16 host bits, so 2 to the power of 16 gives 65,536 addresses. A /24 covers 256 addresses, and the other two options are other powers of two that do not match a /16.

4 more questions and the timed quiz for this lesson open with a free account.

Lessons in How AWS Pieces Fit Together

  1. Region vs availability zone
  2. Vpc, subnet and route table
  3. Public vs private subnet
  4. Security group vs network acl
  5. Shared responsibility model
  6. Iam user vs role for workloads
  7. Aws organizations and service control policies

72 lessons across 9 topics. See the full course