CIDR and subnets
tag: networking
In plain words
Section titled “In plain words”An IPv4 address is four 8-bit octets: 32 bits in all (see IP addresses). The prefix number says how many of those bits are locked, counting from the left.
In 10.34.0.0/16 the first 16 bits are fixed. The remaining 32 − 16 = 16 bits decide which addresses are in the block.

The two parts
Section titled “The two parts”- Base IP: the first address in the block.
- Prefix: how many bits are fixed. The same thing has two common spellings:
- slash notation:
/24(Linuxip addr, cloud consoles, IOC lists) - dotted mask:
255.255.255.0(Windowsipconfigcalls it “Subnet Mask”)
- slash notation:
Two special cases:
x.x.x.x/32 one single address0.0.0.0/0 every IPv4 addressHow to calculate a range
Section titled “How to calculate a range”Example: 192.134.0.0/29
- Free bits: 32 − 29 = 3.
- Addresses: 2³ = 8.
- Range: 192.134.0.0 – 192.134.0.7.
- In a normal subnet the first (.0) is the network address and the last (.7) the broadcast address, so 6 are usable by devices.

Ranges worth knowing
Section titled “Ranges worth knowing”| Range | What it is |
|---|---|
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
Private: never routed on the internet (Public and private addresses) |
127.0.0.0/8 |
Loopback, this machine (127.0.0.1 and localhost) |
169.254.0.0/16 |
Link-local: a Windows machine that didn’t get an address |
100.64.0.0/10 |
Carrier-grade NAT |
Analyst corner
Section titled “Analyst corner”- IOC lists and blocklists use CIDR: an attacker’s whole
/24instead of 256 single addresses. - “Is this IP in that range?” in Python:
import ipaddressnet = ipaddress.ip_network("192.134.0.0/29")print(net.num_addresses, net[0], net[-1]) # 8 192.134.0.0 192.134.0.7print(ipaddress.ip_address("192.134.0.5") in net) # True- Online helpers: a CIDR-to-range converter and a visual subnet calculator are listed in Tools, Feeds and Resources.
Check yourself
Section titled “Check yourself”How many addresses are in a /27?
- 2^(32 − 27) = 2⁵ = 32.
Is `10.34.200.7` inside `10.34.0.0/16`?
- Yes. Only the first two octets are fixed.
What's /20 as a dotted mask?
- 255.255.240.0 (20 ones: 8 + 8 + 4).
What's the smallest block that holds 192.168.1.0 to 192.168.1.63?
- 64 addresses = 2⁶, so /26.
Ports: one address, many conversations at once.

One Reverse Look
"A little learning is a dangerous thing." ~ A. Pope
One Reverse Look · Made with ❤ · Your friendly knowledge seeker

