Card 02/ 10
IPv4 Addresses: A Network Part and a Host Part
An address is 32 bits, and a prefix length says where the network ends and the host begins.
An IPv4 address is 32 bits, written as four numbers from 0 to 255 separated by dots, and it is split into two parts: a network part that every address in the same network shares, and a host part that tells the machines inside that network apart. A prefix length, written after a slash, says how many bits belong to the network.
The four numbers are bytes, eight bits each, which is why none of them can exceed 255. The address 192.168.10.37/24 says that the first 24 bits, the first three numbers, name the network, and the last 8 bits name one machine in it.
| Form | Byte 1 | Byte 2 | Byte 3 | Byte 4 |
|---|---|---|---|---|
| Decimal | 192 | 168 | 10 | 37 |
| Binary | 11000000 | 10101000 | 00001010 | 00100101 |
| Part under /24 | Network | Network | Network | Host |
The boundary does not have to fall between two bytes. Under /26, the network part is the first three bytes plus the top two bits of the fourth, and only six bits are left for hosts. This is why prefixes are counted in bits: it lets a network be any power of two in size, not only 256 or 65,536.
A street address with a house number is a fair way to picture it. The prefix says how many digits are the street, and the rest is the house. The picture breaks in one useful place: a real street never changes length, but the same IP address belongs to a different network under a different prefix. 10.0.1.20 is on network 10.0.0.0 under /16 and on network 10.0.1.0 under /24.
Two addresses in every network are reserved. The one with every host bit set to zero is the network address, which names the network itself. The one with every host bit set to one is the broadcast address, which reaches every host in it. Neither can be given to a machine. In 192.168.10.0/24 they are 192.168.10.0 and 192.168.10.255.
A prefix is sometimes written as a subnet mask instead, with ones in every network bit: /24 is 255.255.255.0. The two notations say the same thing.
So every address question in networking comes down to one step: find where the prefix splits the address, then read each side.
← → move through sections and cards