To Nha Notes | May 17, 2022, 6:52 p.m.
A network can be divided into subnetworks for easy maintenance and security concerns. These subnetworks are referred to as subnets. An IP address in CIDR format is divided into NID bits and host identifier (HID) bits. The netmask of the IP address represents the size of the NID bits. With subnetting, additional bits from the HID part will be used for subnetting. The netmask for a subnet will, therefore, represent the combination of NID bits and subnet identifier bits, and this combined bitmask is usually called a subnet mask.
We created a VPC with a CIDR block range of 10.0.0.0/16. Here, the netmask is /16 and represents NID bits. HID bits can be obtained by subtracting the netmask size from the total available 32 bits for an IPv4 address. So, there will be 16 HID bits, which means we can have up to (2^16) hosts, out of which five are reserved. We created subnets with a subnet mask of /24, so the HID bits for the subnet is 8. Therefore, we can have 2^8 IP addresses in each subnet, which is 256.
The first subnet has a block address of 10.0.1.0/24 and contains IP addresses from 10.0.1.0 to 10.0.1.255. The second subnet has an address of 10.0.2.0/24 and contains IP addresses from 10.0.2.0 to 10.0.2.255. In the Subnets page, however, we saw that there are only 251 available IP addresses. This is because five of the IP addresses are reserved by AWS.
We can also create a subnet with the same IP address range as that of the VPC. We selected Don't Assign Ipv6 for IPv6 CIDR block. Instead of doing this, we can provide a custom IPv6 address range here that is a subset of our VPC's IPv6 address range, or even the same as that of the VPC's IPv6 address range. We used the CIDR ranges in the subnet names. We can also add region details to the name. Since we selected No preference for Availability Zone, AWS will be selecting one for us.
Let's quickly go through some important concepts related to subnets in AWS:
https://heartin.tech/en/blog-entry/important-concepts-related-subnets