Stop 02 · Linux & Networking BasicsTopics · 6/9

IP Addresses & CIDR Notation

Part of the AWS Roadmap

In short

Every device on a network needs an address, and subnetting splits big networks into smaller neighbourhoods. You'll use this daily to read logs, write firewall rules and design cloud networks.

An IPv4 address identifies a device on a network, and CIDR notation like 10.0.0.0/16 describes a range of addresses, where the number after the slash is how many bits are fixed. You will use CIDR to size VPCs and subnets.

The blob drops a letter into one wing's mailbox at a three-wing apartment complex.

Think of it like this

An apartment complex with wings

The society's address gets mail to the gate. Wing A, B or C narrows it down, and the flat number finds the exact door. An IP address works the same: the network part is the society and wing, the host part is the flat.

Watch it happen

Reading 192.168.10.37/24

192
0
168
1
10
2
37
3

1/5An IPv4 address is four numbers from 0 to 255, called octets. Each octet is 8 bits, so 32 bits total.

The big ideas

What you need to know

CIDR notation

The /number says how many bits are the network. Bigger number, smaller subnet. /24 has 256 addresses, /28 has 16.

Private ranges

10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are for internal use. NAT translates them to a public IP.

Subnets as security zones

Putting servers, staff laptops and guests in different subnets lets firewalls control traffic between them.

IPv6 is coming

IPv6 uses 128-bit addresses written in hex, like 2001:db8::1. Same ideas, far more addresses.

See it in code

Walk through the code

bash
1# Show your own IP address and prefix2ip addr show          # Linux3ipconfig              # Windows4ifconfig | grep inet  # macOS5 6# Python can do subnet maths for you7python3 -c "import ipaddress as i; n=i.ip_network('10.0.5.0/26'); print(n.num_addresses, n[1], n[-2])"

1/2Each OS shows your address with a prefix or netmask. 255.255.255.0 is the same as /24.

A /26 has 64 addresses. The first is the network address and the last is broadcast, so usable hosts run from .1 to .62.

Save yourself the pain

Common mistakes

Oops

Thinking a /24 gives you 256 usable hosts.

Do this instead

Two addresses are reserved: the network address and the broadcast address. That leaves 254.

Oops

Writing firewall rules for single IPs when a range is meant.

Do this instead

Use CIDR blocks like 10.0.5.0/26 for a whole subnet. It's shorter and fewer rules get forgotten.

Your mission

Subnet your hostel

~25 min

Quick check

Which address is in the same subnet as 172.16.4.10/24?

Go deeper

  1. 1Work out how many addresses are in a /16, /24 and /28 range.
  2. 2Learn the private IPv4 ranges: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
  3. 3Use an online subnet calculator to split 10.0.0.0/16 into four /18 subnets and check your maths.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge