IP Addresses & Routing

Subnetting Explained From the Ground Up

Understand what a subnet is, how masks split an address, and how to divide a network into smaller ones with a worked example.

Key takeaways

  • An IPv4 address is 32 bits, split by the prefix length into a network part and a host part.
  • Devices on the same subnet talk directly, while traffic to any other subnet goes through a router.
  • Borrowing one bit from the host part doubles the number of subnets and halves the size of each.
  • In an ordinary subnet, the first and last addresses are reserved, so usable hosts equal the block size minus two.

Subnetting means dividing one block of IP addresses into several smaller blocks, each serving its own network segment. You do it by deciding how many bits of an address identify the network and how many identify a device on it. Move that dividing line to the right and you get more networks, each with fewer devices.

By the end of this article you can take a block such as 192.168.1.0/24, split it into equal pieces and say which addresses belong to each. The examples use IPv4, where subnetting does the most work.

What a subnet is

A subnet is a range of addresses that share the same leading bits and sit together on one network segment. Your laptop, phone and printer at home are probably in one subnet, perhaps everything from 192.168.1.0 to 192.168.1.255.

The distinction matters because a device treats neighbors and strangers differently. For a destination inside its own subnet, it finds the other device's hardware address and sends the frame straight there. For anything else, it hands the packet to its default gateway, which is a router.

Subnets exist for several reasons. They limit how far broadcast traffic travels. They give you places to apply firewall rules. They organize an address plan so routing stays simple. And they let you separate things that should not mix, such as guest phones and the accounting server.

Addresses are just 32 bits

192.168.1.77 is a friendly way to write 32 binary digits. Each of the four numbers, called an octet, is 8 bits and so ranges from 0 to 255.

The bit positions in an octet are worth 128, 64, 32, 16, 8, 4, 2 and 1. To write 77 in binary, pick the values that add up to it: 64 + 8 + 4 + 1, giving 01001101.

You do not need to convert whole addresses often. You do need to be comfortable with those eight values, because every subnet boundary comes from them.

The mask draws the line

A subnet mask is another 32-bit number made of a run of ones followed by a run of zeros. Ones mark network bits. Zeros mark host bits. The mask 255.255.255.0 is 24 ones then 8 zeros, usually written /24. The slash notation simply counts the ones.

192.168.1.77 with a /26 mask
192.168.1 1 01 2 001101 3 First 24 bits Network bits shared by the whole original /24. 1 2 borrowed bits Choose which of four subnets: here the second one. 2 6 host bits Identify the device inside that subnet: number 13. 3 192.168.1 1 01 2 001101 3 First 24 bits Network bits shared by the whole original /24. 1 2 borrowed bits Choose which of four subnets: here the second one. 2 6 host bits Identify the device inside that subnet: number 13. 3

To find the network a device belongs to, a computer compares the address with the mask bit by bit and keeps only the bits where the mask has a one. This operation is a logical AND. For 192.168.1.77 with /26:

address   192.168.1.01001101
mask      255.255.255.11000000
network   192.168.1.01000000   = 192.168.1.64

So .77 lives in the subnet that starts at .64.

Splitting a /24

Start with 192.168.1.0/24: 256 addresses, one network. Now borrow host bits to create subnets. Each borrowed bit doubles the count.

Prefix Bits borrowed Subnets from a /24 Addresses each Usable hosts each
/24 0 1 256 254
/25 1 2 128 126
/26 2 4 64 62
/27 3 8 32 30
/28 4 16 16 14

Splitting into four /26 blocks gives this:

Subnet Network address Usable range Broadcast
1 192.168.1.0 .1 to .62 .63
2 192.168.1.64 .65 to .126 .127
3 192.168.1.128 .129 to .190 .191
4 192.168.1.192 .193 to .254 .255

Notice the pattern. Each network address is a multiple of 64, and each broadcast address is one less than the next network. The first address names the subnet and the last one reaches everyone in it, so neither can be given to a device. Network, broadcast and host addresses explains the rule and its exceptions.

A method that works every time

When you are asked about any address and prefix, follow the same steps.

Finding the subnet for any address
1 Find the key octet The octet where the mask is neither all ones nor all zeros. 2 Get the block size Subtract that mask octet from 256. 3 Locate the block Take the largest multiple of the block size not above the address. 4 Mark the edges Network is the start; broadcast is just before the next block. Find the key octet The octet where the mask is neither all ones nor all zeros. 1 Get the block size Subtract that mask octet from 256. 2 Locate the block Take the largest multiple of the block size not above the address. 3 Mark the edges Network is the start; broadcast is just before the next block. 4

Try 192.168.1.200/27. The mask is 255.255.255.224. The block size is 256 minus 224, which is 32. Multiples of 32 are 0, 32, 64, 96, 128, 160, 192, 224. The largest one not above 200 is 192. So the network is 192.168.1.192, the broadcast is 192.168.1.223 and hosts run from .193 to .222.

You can confirm results with the CIDR calculator. It is a good habit while learning, as long as you work the answer by hand first.

Larger blocks work the same way

The line can fall in any octet. With 172.16.0.0/16, borrowing eight bits gives 256 subnets of size /24: 172.16.0.0, 172.16.1.0 and so on up to 172.16.255.0.

With a /20, the key octet is the third one. The mask there is 240, so the block size is 16: subnets start at 172.16.0.0, 172.16.16.0, 172.16.32.0 and continue in steps of 16. Each holds 4,096 addresses, of which 4,094 are usable. Addresses such as 172.16.17.255 sit in the middle of a block and are ordinary hosts, even though they end in 255.

That last point catches many people. An address ending in .0 or .255 is only special when it falls on the edge of its subnet.

Planning in the other direction

So far you have started from a mask. In real planning you usually start from a need: "I need at least five networks" or "this segment needs 50 devices". Both turn into bit counting.

If you need a number of subnets, find the smallest power of two that covers it. Five subnets need three borrowed bits, which give eight. From a /24, that makes eight /27 blocks of 30 usable hosts each.

If you need a number of hosts, add two for the network and broadcast addresses, then round up to a power of two. Fifty hosts need 52 addresses, so you take a block of 64, which is a /26. Remember to include the router and any printers or access points in your count of fifty.

Which way are you planning?
Do you start with a required number of subnets? YES Borrow enough bits that 2 to that power covers the count. 1 NO Do you start with hosts per subnet? YES Add 2, round up to a power of two, then pick the prefix. 2 NO Start with an address and mask Use the block size method to find its subnet. Do you start with a required number of subnets? 1 IF YES Borrow enough bits that 2 to that power covers the count. NO Do you start with hosts per subnet? 2 IF YES Add 2, round up to a power of two, then pick the prefix. NO Start with an address and mask Use the block size method to find its subnet.

Sometimes both limits apply and they collide: eight subnets of 50 hosts will not fit in a single /24, because eight blocks of 64 need 512 addresses. That is your signal to use a larger starting block. On private networks that costs nothing, since ranges such as 10.0.0.0/8 leave plenty of room.

Moving between subnets needs a router

Once you split a network, devices in different subnets can no longer reach each other directly. Something must route between them: a router with an interface in each, or a switch with routing features. Each subnet gets its own gateway address on that device, often the first usable one.

On a physical network, subnets are usually paired with separate switches or with virtual LANs (VLANs), which divide one switch into several isolated segments. Putting two subnets on the same segment without VLANs "works" in a loose sense, but it offers little separation, since any device can change its own address. VLANs at home shows the pairing in practice.

A small worked design

Say your home office has a 192.168.20.0/24 block and you want four separate segments: work computers, family devices, guests and gadgets. Four needs two borrowed bits, so each segment is a /26.

Segment Subnet Gateway Devices can use
Work 192.168.20.0/26 .1 .2 to .62
Family 192.168.20.64/26 .65 .66 to .126
Guests 192.168.20.128/26 .129 .130 to .190
Gadgets 192.168.20.192/26 .193 .194 to .254

Each segment then needs three things on the router: an interface with the gateway address, a DHCP pool that stays inside the subnet and leaves room for fixed addresses, and firewall rules saying which segments may talk. A typical policy lets work and family devices reach the internet, lets guests reach only the internet, and stops gadgets from starting connections into the work segment.

The subnets alone enforce nothing. If the router forwards freely between all four, you have tidy numbering and no isolation. Write the rules, then test them from a device in each segment.

Not every home router can do this. Many offer only one main network plus a guest network. Check for VLAN or multiple network support before you plan around it. In a flat home with a handful of trusted devices, one subnet and a guest network is usually enough.

What goes wrong

  • Mismatched masks. If one device uses /24 and another on the same wire uses /26, they disagree about who is local. Some conversations fail in one direction only.
  • Gateway outside the subnet. A device with address 192.168.1.77/26 cannot use 192.168.1.1 as its gateway, because .1 is in the first block and the device is in the second.
  • Overlapping ranges. Two networks that use the same addresses cannot be routed to each other cleanly. This often appears when a VPN connects a home and an office that both use 192.168.1.0/24.
  • Sizing too tightly. A /28 with 14 usable addresses fills up as soon as someone adds a few phones. Leave room.
  • Forgetting the gateway counts. The router interface uses one of your usable addresses.

Practice problems

Work these out, then check the answers underneath.

  1. Which subnet holds 10.1.1.130/25?
  2. How many usable hosts does a /29 have?
  3. Are 192.168.5.62/26 and 192.168.5.65/26 on the same subnet?

Answers: 10.1.1.128/25, with broadcast 10.1.1.255. Six, since eight addresses minus two. No: .62 is in the block starting at .0, and .65 is in the block starting at .64, so they need a router between them.

When you check your own work, write down the network address first and the next block's start second. The broadcast and the host range follow from those two numbers, and a mistake in either one shows up immediately.

Where to go next

When equal-sized pieces waste too much space, you can cut a block into different sizes, a technique covered in variable length subnet masks. For a quick reference while you practice, keep a subnetting cheat sheet nearby. And if the addresses themselves are still unfamiliar, start with public vs. private IP addresses to learn which ranges you are free to carve up on your own network.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in IP Addresses & Routing →

Latest news on this topic