Skip to content
devfocus.app

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.

Open the CIDR / Subnet Calculator
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 it

An 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 out

Try 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.

Octet 1

128 + 64 = 192

Octet 2

128 + 32 + 8 = 168

Octet 3

1 = 1

Octet 4

8 + 2 = 10

Dotted decimal
192.168.1.10
Integer
3232235786
Hex
0xC0A8010A
Binary
11000000.10101000.00000001.00001010

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  →  10101100

Your turn: What is 11100000 in decimal?

Your turn: Write 100 in binary.

Your turn: What's the biggest number 5 bits can hold?

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.254

Try it · Move the prefix

Highlighted bits are the network part; the rest are the host part.

Address
Netmask (/24)

24 network bits, 8 host bits.

Block
192.168.1.0/24
Netmask
255.255.255.0
Network address
192.168.1.0
Broadcast address
192.168.1.255
Host range
192.168.1.1 – 192.168.1.254
Addresses
256
28
Usable hosts
254

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-bitsBinaryMask octetBlock size (256 − mask)
0000000000256
110000000128128
21100000019264
31110000022432
41111000024016
5111110002488
6111111002524
7111111102542
8111111112551
/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.255

Working 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:

  1. Block size = 256 − mask octet.
  2. Network = the largest multiple of the block size that isn't bigger than the address's octet.
  3. Broadcast = network + block size − 1.
  4. 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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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 hosts

Mental-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 → yes

Your turn: How many addresses are in a /21?

Your turn: Which block is 172.16.200.3/19 in?

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.

  1. 192.168.0.0/26
  2. 192.168.0.64/26
  3. 192.168.0.128/26
  4. 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 odd

VLSM (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.

RangeWhat it isNotes
10.0.0.0/8Private (RFC 1918)10.0.0.0 – 10.255.255.255
172.16.0.0/12Private (RFC 1918)172.16.0.0 – 172.31.255.255
192.168.0.0/16Private (RFC 1918)Home routers live here
127.0.0.0/8Loopback127.0.0.1 is “this machine”
169.254.0.0/16Link-localSelf-assigned when DHCP fails; cloud metadata (169.254.169.254)
100.64.0.0/10Carrier-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/4Multicast224.0.0.0 – 239.255.255.255
240.0.0.0/4ReservedFormer class E; not usable on the internet
192.0.2.0/24Documentation (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 examples

Try it · Shorten an IPv6 address

Paste a full or shortened address; the steps show how its standard short form is built.

  1. 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

  2. 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

  3. 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).

PrefixNetmaskWildcardAddressesUsable hostsTypical use
/00.0.0.0255.255.255.2554,294,967,2964,294,967,294Default route (everything)
/1128.0.0.0127.255.255.2552,147,483,6482,147,483,646
/2192.0.0.063.255.255.2551,073,741,8241,073,741,822
/3224.0.0.031.255.255.255536,870,912536,870,910
/4240.0.0.015.255.255.255268,435,456268,435,454
/5248.0.0.07.255.255.255134,217,728134,217,726
/6252.0.0.03.255.255.25567,108,86467,108,862
/7254.0.0.01.255.255.25533,554,43233,554,430
/8255.0.0.00.255.255.25516,777,21616,777,21410.0.0.0/8 private range
/9255.128.0.00.127.255.2558,388,6088,388,606
/10255.192.0.00.63.255.2554,194,3044,194,302
/11255.224.0.00.31.255.2552,097,1522,097,150
/12255.240.0.00.15.255.2551,048,5761,048,574172.16.0.0/12 private range
/13255.248.0.00.7.255.255524,288524,286
/14255.252.0.00.3.255.255262,144262,142
/15255.254.0.00.1.255.255131,072131,070
/16255.255.0.00.0.255.25565,53665,534192.168.0.0/16 private range; a large VPC
/17255.255.128.00.0.127.25532,76832,766
/18255.255.192.00.0.63.25516,38416,382
/19255.255.224.00.0.31.2558,1928,190
/20255.255.240.00.0.15.2554,0964,094AWS default-VPC subnet
/21255.255.248.00.0.7.2552,0482,046
/22255.255.252.00.0.3.2551,0241,022Medium office or Kubernetes node pool
/23255.255.254.00.0.1.255512510
/24255.255.255.00.0.0.255256254Typical LAN or office subnet
/25255.255.255.1280.0.0.127128126
/26255.255.255.1920.0.0.636462
/27255.255.255.2240.0.0.313230
/28255.255.255.2400.0.0.151614Smallest AWS subnet
/29255.255.255.2480.0.0.786Small static IP block from an ISP
/30255.255.255.2520.0.0.342Point-to-point link (classic)
/31255.255.255.2540.0.0.122Point-to-point link (RFC 3021)
/32255.255.255.2550.0.0.011Single host, loopback or host route
IPv6 prefix/64 subnetsTypical use
/324,294,967,296Allocation to an ISP or large organisation
/4865,536One site or organisation
/56256Home or small business connection
/641One LAN or VLAN (the standard subnet)
/128—Single address