Skip to content
Hopfluent

Module 05

IPv4 addressing and subnetting

The topic most people get stuck on, taught by moving the boundary yourself. Work in binary, split addresses into network and host parts, size subnets for real needs and pack them with VLSM.

Start lesson 1

Addresses are 32 switches · 5 min · free, no account

NetworkOpen nowFree, no account

What you'll operate

  • Binary and dotted decimal
  • Prefix lengths and masks
  • Subnetting and VLSM
lessons
7
minutes
43
no account
Free
Start lesson 1Read the guide

Practice mode

Lessons in this module

  1. 1Addresses are 32 switchesSee an IP address the way a computer stores it: as on and off switches (binary), eight at a time.Free, no account5 min
  2. 2Network part, host partSplit an address with a prefix length and write the same split as a mask.Free, no account6 min
  3. 3How many hosts fit?Turn host bits into address counts, and learn which two addresses you can't use.Free, no account6 min
  4. 4Same subnet, or through a router?Compare prefix bits to decide whether two hosts can talk directly.Free, no account6 min
  5. 5Cutting a network into subnetsFind any address's subnet quickly using block sizes.Free, no account7 min
  6. 6Right-sizing with VLSMGive each group a subnet that fits, and pack them into one block without waste.Free, no account7 min
  7. 7Addresses with special jobsRecognize private, loopback, link-local and shared addresses on sight, and know what each one tells you.Free, no account6 min

Every lesson in this module is open to everyone, with no account, and stays that way.

The guide

Subnetting, explained simply

What an IP address really is

An IPv4 address is a number 32 bits long. Nothing more. We write it as four smaller numbers separated by dots, such as 192.168.1.130, purely because people are bad at reading 32 ones and zeros.

Each of the four numbers is an octet: eight bits. Each bit is a switch with a fixed value, and the octet is the sum of the switches that are on. Try it. Make 192, then 10, then 255.

128
64
32
16
8
4
2
1

128 + 64 =

192

Two things fall out of this. No octet can be larger than 255, because that is all eight bits on. And every size in networking is a power of two, because each extra bit doubles the possibilities. Keep the sequence 2, 4, 8, 16, 32, 64, 128, 256 in your head and most of subnetting becomes arithmetic you already know.

One address, two jobs

An address does two jobs at once. The left part says which network a device is on. The right part says which device on that network. It works like a street name and a house number.

The prefix length, the number after the slash, says where the split falls. In 192.168.1.130/26, the first 26 bits are the network and the last 6 are the host. Move the split and watch what changes.

192.168.1.130/26

/26

Drag the slider or tap a bit below to move the split.

Mask
255.255.255.192
Network address
192.168.1.128
Broadcast address
192.168.1.191
Usable hosts
62
192
168
1
130

Why split addresses at all? Because a router cannot remember where every device on the internet is. It remembers networks. One line in its table covers every host that shares a prefix, and only the last router on the path needs to know the individual machines.

The mask is the same idea, written differently

A subnet mask is the prefix written out as an address: a 1 for every network bit and a 0 for every host bit. So /26 is twenty-six 1s then six 0s, which reads as 255.255.255.192. Operating systems still show masks, so you need both forms.

The mask exists because of how computers find the network part. They line the address up with the mask and keep a bit only where both have a 1. This is a bitwise AND, one of the cheapest operations a processor has, so a router can do it millions of times a second. The zeros in the mask wipe out the host bits, and what is left is the network address.

How many devices fit

The host bits decide how big a subnet is. With 6 host bits there are 2⁶ = 64 addresses. Two of them are spoken for:

  • The first, with every host bit 0, is the network address. It names the subnet itself.
  • The last, with every host bit 1, is the broadcast address. A packet sent to it reaches every device on the subnet.

That leaves 62 for actual devices. The rule is always the same: usable hosts = 2 to the power of the host bits, minus 2. Shrink and grow the subnet below; the dark squares are the two reserved addresses.

/26

64 − 2 = 62 usable

Network and broadcastUsable

There is one exception worth knowing. A link between two routers only has two ends and never needs a broadcast address, so a /31, which has exactly two addresses, may use both. Before that was allowed, such links used a /30 and threw two addresses away.

Same subnet, or through a router?

Before a device sends anything, it asks one question: is the destination on my subnet? It answers by comparing network bits. If they match, it delivers the packet directly. If they differ, it hands the packet to its default gateway, a router, and lets that deal with it.

This is why a wrong mask causes such confusing faults. A host set to /24 on a network that is really /25 believes the other half of the range is local. It tries to reach those machines directly, hears nothing, and half the network appears dead while the rest works.

Finding any subnet in seconds

You do not need binary for everyday subnetting. You need the block size.

  1. Find the first mask octet that is not 255 (the interesting octet). For /26 the mask is 255.255.255.192, so it is the fourth: 192.
  2. Subtract it from 256. 256 − 192 = 64. That is the block size.
  3. In that octet, subnets start at every multiple of the block size: 0, 64, 128, 192.
  4. Your address sits in the block that starts at the largest multiple not above it. For .130 that is .128.

From there everything follows. The network address is 192.168.1.128. The next block starts at .192, so the broadcast address is one below it, 192.168.1.191. The usable hosts are everything in between: .129 to .190.

Different sizes for different needs

Cutting a network into equal pieces wastes addresses. A link between two routers needs 2 addresses, not 62. Variable-length subnet masks let each group have the size it needs.

Say you have 192.168.10.0/24 and four groups: 100, 50, 25 and 2 devices.

  1. Size each one: 100 needs a /25 (126 usable), 50 needs a /26 (62), 25 needs a /27 (30), and 2 needs a /30.
  2. Place the largest first. A block can only begin on a multiple of its own size, so going largest to smallest never leaves a gap.
  3. The result: .0/25, then .128/26, then .192/27, then .224/30. That uses 228 addresses and leaves .228 to .255 free in one piece.

Addresses with special jobs

  • Private ranges: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. Free for anyone to use internally and never routed on the internet. Millions of networks reuse them, which is how IPv4 has lasted.
  • 169.254.x.x: a device gave itself this address because no DHCP server answered. Seeing it tells you where to look.
  • 127.0.0.1: loopback. The machine talking to itself, without touching the network.
  • 100.64.0.0/10: shared space between a provider and its customers. If your router's outside address is in here, you are behind the provider's NAT.

Mistakes almost everyone makes

  • Forgetting the minus 2. A /27 has 32 addresses but 30 usable hosts.
  • Assigning the network or broadcast address to a device. In a /26 block starting at .128, neither .128 nor .191 can be used.
  • Assuming the split is on a dot. /20 and /27 split inside an octet. That is where the block-size method earns its keep.
  • Confusing more subnets with more hosts. Every bit you borrow doubles the subnets and halves the hosts in each.
  • Placing small subnets first in VLSM. It strands address space that the large ones then cannot use.

Sources

Everything here follows the published standards: RFC 791 (IPv4), RFC 950 (subnetting), RFC 1122 (host requirements), RFC 4632 (CIDR), RFC 3021 (/31 links), RFC 1918 (private addresses), RFC 3927 (link-local) and RFC 6598 (shared address space). Want numbers for a specific address? Use the subnet calculator or the CIDR cheat sheet.