Course outline · 0% complete

0/30 lessons0%

Course overview →

IPv4 addresses, binary, and CIDR

lesson 4-1 · ~13 min · 9/30

32 bits, written for humans

An IPv4 address is a 32 bit number. That is the entire truth of it. The dotted form you are used to exists only because 32 raw bits are unreadable, so we split them into four groups of 8 bits, called octets, and write each octet in decimal from 0 to 255. That form is called a dotted quad.

192.168.1.42
11000000 . 10101000 . 00000001 . 00101010

Every subnetting question in this course is answered in the second line, so you need to move between the two forms fluently. Each octet has 8 bit positions with these values:

Bit position12345678
Value1286432168421

To convert a decimal octet to binary, walk left to right and subtract greedily. Take 42:

128? 42 < 128  -> 0, remainder 42
 64? 42 < 64   -> 0, remainder 42
 32? 42 >= 32  -> 1, remainder 10
 16? 10 < 16   -> 0, remainder 10
  8? 10 >= 8   -> 1, remainder 2
  4?  2 < 4    -> 0, remainder 2
  2?  2 >= 2   -> 1, remainder 0
  1?  0 < 1    -> 0, remainder 0
42 = 00101010

Going the other way, just add the values under the 1s: 00101010 is 32 + 8 + 2 = 42. Memorize the eight values 128, 64, 32, 16, 8, 4, 2, 1 and you will never need a calculator for any of this.

Because there are 32 bits, the whole IPv4 space holds 2³² = 4,294,967,296 addresses, which sounded infinite in 1981 and ran out in 2011. That single fact drives Unit 6 (NAT) and half of Unit 8 (IPv6).

The split that makes routing possible

MAC addresses are flat, so they cannot be summarized. IP addresses are hierarchical, and that is their whole point. Every address is split into two parts:

- The network portion, the leading bits, which identify a network. - The host portion, the trailing bits, which identify one interface inside that network.

Where does the split fall? Wherever the prefix length says, written as a slash and a number after the address. 192.168.1.42/24 means the first 24 bits are network and the last 8 are host. This is CIDR notation (classless inter domain routing).

The same split can be written as a subnet mask, a 32 bit number with 1s over the network bits and 0s over the host bits.

address  192.168.1.42   11000000 10101000 00000001 00101010
mask     255.255.255.0  11111111 11111111 11111111 00000000
                        \____ network, 24 bits ___/\_ host _/

A mask always has its 1s contiguous and on the left, so only 33 masks exist, one per prefix length from /0 to /32. The ones you meet constantly:

PrefixMaskHost bits
/8255.0.0.024
/16255.255.0.016
/22255.255.252.010
/24255.255.255.08
/25255.255.255.1287
/26255.255.255.1926
/27255.255.255.2245
/28255.255.255.2404
/30255.255.255.2522
/32255.255.255.2550

Notice the pattern in the last octet: 128, 192, 224, 240, 248, 252, 254, 255. Each step adds the next bit value. That column is worth knowing by heart.

11000000 10101000 000000010010101011111111 11111111 1111111100000000addressmasknetwork portion, 24 bitshost, 8 bits192.168.1.42/24the prefix length is the position of this line
The prefix length draws a line through the 32 bits. Left of the line identifies the network, right of it identifies a host inside it.

How many hosts does a prefix hold

With h host bits there are 2ʰ addresses in the block. Two of them are reserved in every ordinary subnet, the network address and the broadcast address, which Lesson 4-2 derives. So:

addresses = 2^(32 - prefix)
usable    = 2^(32 - prefix) - 2
PrefixHost bitsAddressesUsable hosts
/30242
/29386
/2841614
/2753230
/2666462
/257128126
/248256254
/239512510
/22101,0241,022
/20124,0964,094
/161665,53665,534
/82416,777,21616,777,214

Two directions to read this table. Smaller prefix means bigger block, which feels backwards until you remember the prefix counts fixed bits, so fewer fixed bits leaves more room. A /8 is enormous, a /30 holds two hosts.

And every step of one bit doubles or halves. A /25 is exactly half of a /24. Two /26s make a /25. This is the arithmetic of Lesson 4-3.

What classes were, and why CIDR replaced them

Before 1993 the split was not free. The first bits of the address chose one of three fixed classes:

ClassFirst bitsFirst octetDefault prefixNetworksHosts each
A01 to 126/812616,777,214
B10128 to 191/1616,38465,534
C110192 to 223/242,097,152254
D1110224 to 239multicastn/an/a

The waste is obvious in the last column. An organization with 300 hosts was too big for a class C's 254 and got a class B, wasting 65,234 addresses. Meanwhile the routing tables of the internet grew one entry per assigned network with no way to combine them.

CIDR fixed both problems by making the prefix length explicit and arbitrary. That organization now gets a /23 with 510 usable hosts, a close fit. And a provider holding 192.0.2.0/24 through 192.0.15.0/24 can advertise the single summary route 192.0.0.0/20, which is called route aggregation and is the only reason the internet's routing table is millions of entries rather than hundreds of millions.

Class terminology survives in casual speech, so when someone says "a class C" in 2026 they usually just mean a /24. The classes themselves are gone.