Skip to Content

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/0 for "anywhere", or 122.149.196.85/32 for 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.0 to 192.168.0.63 (64 IP addresses).

A CIDR has two parts:

  • Base IP: an IP contained in the range, such as 10.0.0.0 or 192.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

CIDR subnet masks: /32 is one IP address, /24 is 256 addresses where the last octet changes, /16 is 65,536 addresses where the last two octets change, /8 is about 16.7 million addresses, and /0 is all IP addresses CIDR subnet masks: /32 is one IP address, /24 is 256 addresses where the last octet changes, /16 is 65,536 addresses where the last two octets change, /8 is about 16.7 million addresses, and /0 is all IP addresses

Each step down the mask doubles the addresses.

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.0 to 192.168.0.255 (256 IPs).
  • 192.168.0.0/16 → 192.168.0.0 to 192.168.255.255 (65,536 IPs).
  • 134.56.78.123/32 → just 134.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 uses 172.31.0.0/16 from 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: /16 is much bigger than /24.

Check yourself

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt