IP addresses and CIDR, explained
Everything you need to read, size and split IP networks — from bits to subnetting in your head. Short explanations, worked examples and things to click. The calculator shows the same working for any block you type.
On this page
TL;DR#
The whole guide in ten lines. If these all make sense, skip to the cheat sheet.
// An IPv4 address is 32 bits, written as 4 octets (0–255 each)192.168.1.10 = 11000000.10101000.00000001.00001010// /24 means: the first 24 bits name the network, the other 8 name the host192.168.1.10/24 // network 192.168.1.0, host .10// The netmask is the prefix written as an address: 24 ones, then zeros/24 = 255.255.255.0// Block size = 2^(32 − prefix). First = network, last = broadcast/24 → 2^8 = 256 addresses, 254 usable hosts// Block size in the 'interesting' octet = 256 − mask octet/26 → mask 255.255.255.192 → 256 − 192 = 64 → blocks start at .0 .64 .128 .192192.168.1.77/26 lives in 192.168.1.64/26 (.64 – .127)// One more prefix bit halves the block; one fewer doubles itAn IP address is a 32-bit number#
Computers see an IPv4 address as one 32-bit number. People write it as four 8-bit chunks called octets, each turned into a decimal from 0 to 255 and joined with dots. That's why no part of an IPv4 address is ever above 255: eight bits can't hold more.
// The same address, four ways192.168.1.10 // dotted decimal (what people write)11000000.10101000.00000001.00001010 // binary (what the network compares)0xC0A8010A // hex3232235786 // one 32-bit integer// 2^32 ≈ 4.3 billion addresses in total — which is why IPv4 ran outTry it · Flip the bits
Click a bit to switch it between 0 and 1, or type an address. Each octet is the sum of its 1-bits.
Binary in two minutes#
Each of the 8 bits in an octet has a place value, doubling from right to left. A 1 means “add this value”. You only ever need these eight numbers.
// Place values of one octet128 64 32 16 8 4 2 1 1 1 0 0 0 0 0 0 = 128 + 64 = 192 0 0 0 0 1 0 1 0 = 8 + 2 = 10 1 1 1 1 1 1 1 1 = 255 // all ones: the maximum// Decimal → binary: subtract the biggest place value that fits, repeat172 − 128 = 44 → 44 − 32 = 12 → 12 − 8 = 4 → 4 − 4 = 0// used 128, 32, 8 and 4 → 10101100Your turn: What is 11100000 in decimal?
Your turn: Write 100 in binary.
01100100Your turn: What's the biggest number 5 bits can hold?
11111 = 16 + 8 + 4 + 2 + 1 = 31. In general n bits hold 2n values, 0 to 2n − 1.Network part vs host part#
Every address has two parts. The network part (the left bits) is shared by every device on the same network; routers only look at this part. The host part (the right bits) picks out one device on that network. The prefix says where the split is.
192.168.1.10/2411000000.10101000.00000001 | 00001010 network (24 bits) | host (8 bits)// Host bits all 0 → the network address: 192.168.1.0// Host bits all 1 → the broadcast address: 192.168.1.255// Everything between is a usable host: 192.168.1.1 – 192.168.1.254Try it · Move the prefix
Highlighted bits are the network part; the rest are the host part.
24 network bits, 8 host bits.
CIDR notation and netmasks#
/24 and 255.255.255.0 say the same thing. CIDR notation counts the 1-bits; the netmask writes them out as an address. The 1s are always contiguous from the left, so an octet of a mask can only be one of nine values. Learn this row and you can read any mask.
| 1-bits | Binary | Mask octet | Block size (256 − mask) |
|---|---|---|---|
| 0 | 00000000 | 0 | 256 |
| 1 | 10000000 | 128 | 128 |
| 2 | 11000000 | 192 | 64 |
| 3 | 11100000 | 224 | 32 |
| 4 | 11110000 | 240 | 16 |
| 5 | 11111000 | 248 | 8 |
| 6 | 11111100 | 252 | 4 |
| 7 | 11111110 | 254 | 2 |
| 8 | 11111111 | 255 | 1 |
/20 = 11111111.11111111.11110000.00000000 = 255 .255 .240 .0// 20 = 8 + 8 + 4 → two full octets, then 4 ones (240), then zeros// A wildcard mask (Cisco ACLs, OSPF) is the netmask flipped: 255 − each octet/20 wildcard = 0.0.15.255Working out a block by hand#
You never need to write out 32 bits. Only one octet is ever “interesting” — the one where the mask isn't 255 or 0. Octets before it are copied, octets after it become 0 (network) or 255 (broadcast). For the interesting octet:
- Block size = 256 − mask octet.
- Network = the largest multiple of the block size that isn't bigger than the address's octet.
- Broadcast = network + block size − 1.
- Usable hosts = 2host bits − 2.
Try it · Solve any block
Type an address with a prefix, or press Random and try it on paper before reading the steps.
Solving 192.168.10.77/26 → block 192.168.10.64/26
Step 1: Write the netmask. /26 means the first 26 of the 32 bits are network bits. Write them as 1s, then turn each octet into decimal.
/26 = 8 + 8 + 8 + 2 one-bits netmask = 255.255.255.192
Step 2: Find the interesting octet. It's the octet where the mask is neither 255 nor 0: the 4th one. The octets before it are copied as they are.
mask 255.255.255.192 → 4th octet is 192 address 4th octet is 77
Step 3: Work out the block size. Subtract the mask octet from 256. Blocks in this octet start at every multiple of that number.
256 − 192 = 64 blocks start at 0, 64, 128, 192
Step 4: Find the network address. Take the largest multiple of 64 that isn't bigger than 77. Octets after it become 0.
77 ÷ 64 = 1 (drop the remainder) 1 × 64 = 64
Step 5: Find the broadcast address. It's one less than where the next block starts. Octets after the interesting one become 255.
64 + 64 − 1 = 127 broadcast = 192.168.10.127
Step 6: List the usable hosts. The first address names the network and the last is the broadcast, so the hosts are everything in between.
network 192.168.10.64 first 192.168.10.65 last 192.168.10.126 broadcast 192.168.10.127
Step 7: Count the addresses. Each host bit doubles the block. Take away 2 for the network and broadcast addresses.
32 − 26 = 6 host bits 2^6 = 64 addresses 64 − 2 = 62 usable hosts
// Example: 192.168.10.77/26// 1. Write the netmask/26 = 8 + 8 + 8 + 2 one-bitsnetmask = 255.255.255.192// 2. Find the interesting octetmask 255.255.255.192 → 4th octet is 192address 4th octet is 77// 3. Work out the block size256 − 192 = 64blocks start at 0, 64, 128, 192// 4. Find the network address77 ÷ 64 = 1 (drop the remainder)1 × 64 = 64// 5. Find the broadcast address64 + 64 − 1 = 127broadcast = 192.168.10.127// 6. List the usable hostsnetwork 192.168.10.64first 192.168.10.65last 192.168.10.126broadcast 192.168.10.127// 7. Count the addresses32 − 26 = 6 host bits2^6 = 64 addresses64 − 2 = 62 usable hosts// Example: 172.16.45.9/20// 1. Write the netmask/20 = 8 + 8 + 4 one-bitsnetmask = 255.255.240.0// 2. Find the interesting octetmask 255.255.240.0 → 3rd octet is 240address 3rd octet is 45// 3. Work out the block size256 − 240 = 16blocks start at 0, 16, 32, 48, …// 4. Find the network address45 ÷ 16 = 2 (drop the remainder)2 × 16 = 32// 5. Find the broadcast address32 + 16 − 1 = 47broadcast = 172.16.47.255// 6. List the usable hostsnetwork 172.16.32.0first 172.16.32.1last 172.16.47.254broadcast 172.16.47.255// 7. Count the addresses32 − 20 = 12 host bits2^12 = 4,096 addresses4,096 − 2 = 4,094 usable hosts// Example: 10.20.30.203/29// 1. Write the netmask/29 = 8 + 8 + 8 + 5 one-bitsnetmask = 255.255.255.248// 2. Find the interesting octetmask 255.255.255.248 → 4th octet is 248address 4th octet is 203// 3. Work out the block size256 − 248 = 8blocks start at 0, 8, 16, 24, …// 4. Find the network address203 ÷ 8 = 25 (drop the remainder)25 × 8 = 200// 5. Find the broadcast address200 + 8 − 1 = 207broadcast = 10.20.30.207// 6. List the usable hostsnetwork 10.20.30.200first 10.20.30.201last 10.20.30.206broadcast 10.20.30.207// 7. Count the addresses32 − 29 = 3 host bits2^3 = 8 addresses8 − 2 = 6 usable hostsMental-math shortcuts#
Subnetting in your head is mostly powers of two and a few anchors. Know which octet you're in, then halve or double.
// Powers of two worth knowing by heart2^1=2 2^2=4 2^3=8 2^4=16 2^5=32 2^6=64 2^7=128 2^8=2562^10 = 1,024 2^16 = 65,536 2^20 ≈ 1 million 2^24 ≈ 16.7 million 2^32 ≈ 4.3 billion// Which octet is interesting?/1–/8 → 1st /9–/16 → 2nd /17–/24 → 3rd /25–/32 → 4th// Anchor on the octet boundaries…/8 = 16,777,216 /16 = 65,536 /24 = 256 /32 = 1// …then halve for each bit more/24 = 256 /25 = 128 /26 = 64 /27 = 32 /28 = 16 /29 = 8 /30 = 4// …or double for each bit less/24 = 256 /23 = 512 /22 = 1,024 /21 = 2,048 /20 = 4,096// Splitting /old into /new gives 2^(new − old) subnets/24 → /27 = 2^3 = 8 subnets of 32// Hosts needed → prefix: smallest power of two ≥ hosts + 250 hosts → 52 → 64 = 2^6 → 32 − 6 = /26// 'Is X in Y?' — check only the interesting octetIs 10.1.77.5 in 10.1.64.0/18?/18 → 3rd octet, mask 192, block size 64 → 64–127 → 77 is inside → yesYour turn: How many addresses are in a /21?
Your turn: Which block is 172.16.200.3/19 in?
172.16.192.0/19, broadcast 172.16.223.255.Your turn: What's the longest prefix that fits 500 hosts?
Splitting and combining#
Subnetting borrows host bits for the network: each borrowed bit doubles the number of subnets and halves their size. Subnets always start on a multiple of their own size.
Try it · Split a block
Each extra prefix bit doubles the number of subnets and halves their size.
22 = 4 subnets of /26, each 64 addresses.
- 192.168.0.0/26
- 192.168.0.64/26
- 192.168.0.128/26
- 192.168.0.192/26
Summarising (supernetting) is the reverse: neighbouring blocks that differ only in their last network bit merge into one block with a prefix one shorter. Routers do this to keep routing tables small.
192.168.0.0/24 = 11000000.10101000.0000000|0.00000000192.168.1.0/24 = 11000000.10101000.0000000|1.00000000// the first 23 bits match, so:192.168.0.0/23 // 192.168.0.0 – 192.168.1.255// But 192.168.1.0/24 + 192.168.2.0/24 can't merge:// a /23 must start on an even 3rd octet, and 1 is oddVLSM (variable-length subnet masks) means splitting one block into subnets of different sizes. Hand out the biggest subnets first so every piece stays aligned. For example 10.0.0.0/24 → 10.0.0.0/25 (126 hosts), 10.0.0.128/26 (62 hosts), 10.0.0.192/27 and 10.0.0.224/27 (30 hosts each).
Special ranges#
Some ranges have fixed meanings. The private ranges are the ones you'll use most: they're free to use inside any network but are never routed on the public internet, so devices reach the internet through NAT.
| Range | What it is | Notes |
|---|---|---|
| 10.0.0.0/8 | Private (RFC 1918) | 10.0.0.0 – 10.255.255.255 |
| 172.16.0.0/12 | Private (RFC 1918) | 172.16.0.0 – 172.31.255.255 |
| 192.168.0.0/16 | Private (RFC 1918) | Home routers live here |
| 127.0.0.0/8 | Loopback | 127.0.0.1 is “this machine” |
| 169.254.0.0/16 | Link-local | Self-assigned when DHCP fails; cloud metadata (169.254.169.254) |
| 100.64.0.0/10 | Carrier-grade NAT (RFC 6598) | Shared by ISPs between their NAT and customers |
| 0.0.0.0/8 | “This network” (RFC 1122) | 0.0.0.0 means “any address” when a server listens |
| 224.0.0.0/4 | Multicast | 224.0.0.0 – 239.255.255.255 |
| 240.0.0.0/4 | Reserved | Former class E; not usable on the internet |
| 192.0.2.0/24 | Documentation (RFC 5737) | Also 198.51.100.0/24 and 203.0.113.0/24 — use them in examples |
IPv6#
IPv6 addresses are 128 bits, written as 8 groups of 4 hex digits. The ideas are the same — a prefix splits network from host — but the numbers are so large that you count hex digits instead of hosts.
// 128 bits = 8 groups × 16 bits; each group is 4 hex digits2001:0db8:0000:0000:0000:ff00:0042:8329// Rule 1: drop leading zeros in each group2001:db8:0:0:0:ff00:42:8329// Rule 2: replace ONE run of all-zero groups with ::2001:db8::ff00:42:8329// Each hex digit is 4 bits, so /48 = the first 12 digits = 3 groups2001:db8:abcd::/48 // a typical site allocation2001:db8:abcd:12::/64 // one subnet: 2^64 addresses// Ordinary LANs are always /64 (SLAAC needs it). A /48 holds 65,536 of them; a /56 holds 256// No broadcast in IPv6 — multicast (ff00::/8) does that job::1 // loopbackfe80::/10 // link-local, on every interfacefc00::/7 // unique local (ULA), the IPv6 cousin of RFC 1918 — in practice fd00::/82001:db8::/32 // documentation and examplesTry it · Shorten an IPv6 address
Paste a full or shortened address; the steps show how its standard short form is built.
Full form. 8 groups of 4 lowercase hex digits. Every IPv6 address can be written this way.
2001:0db8:0000:0000:0000:ff00:0042:8329
Rule 1: drop leading zeros. In each group, leading zeros can go. A group of all zeros becomes a single 0.
2001:db8:0:0:0:ff00:42:8329
Rule 2: replace one run of zero groups with ::. The longest run of 0 groups (3 of them) becomes ::. Only one run may be replaced, or you couldn't tell how many zeros each :: stands for.
2001:db8::ff00:42:8329
Cheat sheet#
Every IPv4 prefix at a glance. Usable hosts leave out the network and broadcast addresses (except /31 and /32).
| Prefix | Netmask | Wildcard | Addresses | Usable hosts | Typical use |
|---|---|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 | 4,294,967,294 | Default route (everything) |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,648 | 2,147,483,646 | |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,824 | 1,073,741,822 | |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,912 | 536,870,910 | |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 | 268,435,454 | |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,728 | 134,217,726 | |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,864 | 67,108,862 | |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,432 | 33,554,430 | |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 | 10.0.0.0/8 private range |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 | |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 | |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 | |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 | 172.16.0.0/12 private range |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 | |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 | |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 | |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 | 192.168.0.0/16 private range; a large VPC |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 | |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 | |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 | |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 | AWS default-VPC subnet |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 | |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 | Medium office or Kubernetes node pool |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 | |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 | Typical LAN or office subnet |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 | |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 | |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 | |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 | Smallest AWS subnet |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 | Small static IP block from an ISP |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 | Point-to-point link (classic) |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 | Point-to-point link (RFC 3021) |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 | Single host, loopback or host route |
| IPv6 prefix | /64 subnets | Typical use |
|---|---|---|
| /32 | 4,294,967,296 | Allocation to an ISP or large organisation |
| /48 | 65,536 | One site or organisation |
| /56 | 256 | Home or small business connection |
| /64 | 1 | One LAN or VLAN (the standard subnet) |
| /128 | — | Single address |