CIDR and IP addressing
CIDR notation, base IPs and subnet masks, how many addresses a /24 or /16 holds, worked examples, and private vs public IPv4 ranges.
What CIDR is
CIDR (Classless Inter-Domain Routing) is a method for allocating IP addresses.
- Used in security group rules and AWS networking in general (for example
0.0.0.0/0for "anywhere", or122.149.196.85/32for one IP). - It defines an IP address range:
WW.XX.YY.ZZ/32→ one IP;0.0.0.0/0→ all IPs;192.168.0.0/26→192.168.0.0to192.168.0.63(64 IP addresses).
A CIDR has two parts:
- Base IP: an IP contained in the range, such as
10.0.0.0or192.168.0.0. - Subnet mask: defines how many bits can change in the IP. It takes two forms:
/8⇔255.0.0.0;/16⇔255.255.0.0;/24⇔255.255.255.0;/32⇔255.255.255.255.
Subnet masks
The mask says how many of the 32 bits are fixed. The rest can change: a /n holds 2^(32 − n) addresses.
/32→ 2⁰ = 1 IP (192.168.0.0);/31→ 2 IPs;/30→ 4 IPs;/29→ 8 IPs;/28→ 16 IPs;/27→ 32 IPs;/26→ 64 IPs;/25→ 128 IPs;/24→ 256 IPs (192.168.0.0→192.168.0.255);/16→ 65,536 IPs (192.168.0.0→192.168.255.255);/0→ all IPs.
Quick memo (octets are the four numbers of an IP):
/32: no octet can change;/24: the last octet can change;/16: the last 2 octets can change;/8: the last 3 octets can change;/0: all octets can change.
Little exercise
192.168.0.0/24→192.168.0.0to192.168.0.255(256 IPs).192.168.0.0/16→192.168.0.0to192.168.255.255(65,536 IPs).134.56.78.123/32→ just134.56.78.123.0.0.0.0/0→ all IPs.
When in doubt, use a CIDR calculator website.
Private vs public IPv4
The IANA (Internet Assigned Numbers Authority) reserved certain blocks of IPv4 addresses for private networks (LANs). Private IPs can only use these values:
10.0.0.0–10.255.255.255(10.0.0.0/8): in big networks;172.16.0.0–172.31.255.255(172.16.0.0/12): the AWS default VPC uses172.31.0.0/16from this range;192.168.0.0–192.168.255.255(192.168.0.0/16): for example, home networks.
All the rest of the IP addresses on the internet are public. See also IP addresses on EC2.
Exam tips
- "How many IPs in a /24?" → 256 (minus the 5 AWS reserves in a subnet).
- "Allow one IP in a security group" →
/32. "Allow everyone" →0.0.0.0/0. - "Private IP ranges" →
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16.
Common traps
- "A bigger mask number means more addresses." It's the opposite:
/16is much bigger than/24.
Check yourself
2^(32 − 22) = 1,024 addresses: 10.0.4.0 to 10.0.7.255.
AWS documentation
Networking: Amazon VPC
The Amazon VPC building blocks on one map, a one-line summary of each component, and the map of this group.
VPC and subnets
The default VPC, VPC limits and allowed CIDR ranges, public and private subnets across Availability Zones, and the five IP addresses AWS reserves in every subnet.