Quick Summary
- An IP address has two parts: the network portion (which street you are on) and the host portion (which house you are in)
- A subnet mask determines where the split between network and host happens
- CIDR notation like /24 is shorthand for the subnet mask -- it tells you how many bits belong to the network
The Apartment Building Analogy
Think of an IP address like a mailing address for an apartment building. The building address (say, 742 Evergreen Terrace) tells the mail carrier which building to go to. The room number (say, Apartment 10) tells them which specific unit inside that building should receive the letter.
In networking, this works the same way. Every IP address is split into two halves: the network portion (the building address) and the host portion (the room number). The network portion tells routers which network to deliver traffic to. The host portion identifies the specific device on that network.
Subnetting is simply the process of deciding where that split happens. A large building might have hundreds of rooms. A small one might have just two. Similarly, a network can hold millions of devices or just a handful -- it all depends on how you draw the line between the network and host portions of the address.
Without subnetting, every device on the internet would be on one giant flat network. That would be like having every person in the world live in the same apartment building -- chaos. Subnetting lets you carve the internet into manageable, organized neighborhoods.
Visualizing an IP Address
Here is the IP address 192.168.1.10 with a /24 subnet mask. The colored sections show which bits belong to the network and which belong to the host:
Try It Yourself
Enter an IP address and adjust the prefix length to see how subnetting works.
The key takeaway is simple: the /24 means the first 24 bits (three octets) are the network, and the remaining 8 bits (one octet) are the host. This gives you room for 254 usable devices on that network (addresses 1 through 254, since 0 is the network address and 255 is the broadcast address).
Subnetting Step by Step
What is an IP Address?
An IP address is a unique number assigned to every device on a network, like a phone number. The most
common format is IPv4, which looks like four numbers separated by dots: 192.168.1.10. Each
of those four numbers is called an octet and ranges from 0 to 255. Under the hood, each
octet is 8 binary bits, so an IPv4 address is 32 bits total. Every single bit matters when it comes to
subnetting, because the subnet mask works at the bit level to draw the line between network and host.
The Subnet Mask: Drawing the Line
A subnet mask looks like an IP address -- for example, 255.255.255.0. But it serves a
completely different purpose. It tells your computer which bits of the IP address represent the network
and which represent the host. Everywhere the mask has a 1 bit, that position belongs to
the network. Everywhere it has a 0 bit, that position belongs to the host. The mask
255.255.255.0 in binary is twenty-four 1s followed by eight 0s -- which is why we write it
as /24 in shorthand.
Common Prefix Lengths: /24, /16, and /8
The three most common subnet sizes land on octet boundaries and are easy to understand.
/24 (mask 255.255.255.0) uses three octets for the network and one for hosts,
giving 254 usable addresses -- perfect for a home or small office. /16 (mask
255.255.0.0) uses two octets for the network and two for hosts, providing 65,534 usable
addresses -- suitable for a large campus. /8 (mask 255.0.0.0) uses one octet
for the network and three for hosts, allowing over 16 million addresses -- only used by the largest
organizations and internet service providers.
CIDR Notation: The Modern Shorthand
In the early days, subnets were described using full dotted-decimal masks like 255.255.255.0.
Today, we use CIDR notation (Classless Inter-Domain Routing), which appends a slash and
a number to the IP address: 192.168.1.0/24. The number after the slash tells you how many
bits are dedicated to the network portion. CIDR replaced the old "classful" system (Class A, B, C) because
it allows subnets of any size, not just the fixed sizes that classes imposed. You can have a /27 (30 hosts),
a /30 (2 hosts), or anything in between.
Subnetting in the Real World
Different situations call for different subnet sizes. Here are three common scenarios you will encounter:
Home Network (/24)
Your home WiFi router almost certainly uses a /24 subnet like 192.168.1.0/24.
This gives you 254 usable IP addresses -- more than enough for your phones, laptops, smart TVs, and
IoT devices. The router itself takes one address (usually .1), and DHCP assigns the rest
to your devices automatically.
Office Campus (/16)
A large corporate office might use a /16 network like 10.0.0.0/16, providing
65,534 addresses. This massive space is then further divided into smaller /24 subnets for each department
or floor -- accounting on 10.0.1.0/24, engineering on 10.0.2.0/24, and so on.
This is called subnetting a subnet.
Point-to-Point Link (/30)
When two routers are connected directly to each other, you only need two usable IP addresses -- one for
each end. A /30 subnet provides exactly that: four total addresses minus the network and
broadcast addresses leaves two usable IPs. This is standard practice for WAN links and saves valuable
address space in large networks.
Common Subnetting Mistakes
Subnetting errors can cause devices to lose connectivity or create security gaps. Watch out for these:
Wrong Subnet Mask
If two devices on the same network have different subnet masks, they may not be able to communicate.
For example, if your computer has 192.168.1.10/24 but your printer has
192.168.1.20/16, they disagree about the size of the network. The printer thinks the
entire 192.168.x.x range is local, while your computer only sees 192.168.1.x.
This mismatch causes unpredictable routing behavior.
Overlapping Subnets
If you assign 10.0.1.0/24 to the first floor and 10.0.1.128/25 to the second
floor, you have a problem -- the second range overlaps with the first. Routers will not know where to
send traffic for addresses in the overlapping region. Always plan your subnets on paper first and verify
that ranges do not collide before deploying them.
Forgetting the Default Gateway
A device with the correct IP address and subnet mask still cannot reach other networks without a
default gateway. The gateway is the router's address on the local subnet. If you set
a device's IP to 192.168.1.50/24 but leave the gateway blank, it can talk to other devices
on the 192.168.1.x subnet but nothing beyond -- no internet, no other subnets.
Private vs. Public IP Addresses
Not all IP addresses are created equal. The Internet Assigned Numbers Authority (IANA) reserved three
blocks of addresses for private use: 10.0.0.0/8, 172.16.0.0/12, and
192.168.0.0/16. These addresses are not routable on the public internet --
they can only be used inside your local network. That is why millions of home routers all use
192.168.1.x without conflicting with each other. NAT (Network Address Translation) handles
the conversion between your private addresses and the public internet.
How Routers Use Subnets
When a router receives a packet, it looks at the destination IP address and compares it against its
routing table. Each entry in the routing table includes a subnet (like
192.168.1.0/24) and a next-hop address. The router performs a longest prefix
match -- it finds the most specific subnet that contains the destination address and forwards the
packet accordingly. This is why subnetting matters for performance: well-designed subnets keep local
traffic local, reducing the load on routers and making the network faster for everyone.
The bottom line: subnetting is the foundation of every network, from your home WiFi to the global internet. Once you understand that every IP address is just a building address plus a room number, and that the subnet mask decides where the split happens, everything else in networking starts to make sense.
Frequently asked questions about subnetting
What is subnetting?
Subnetting is the practice of dividing a single IP network into smaller logical networks called subnets. You do it by extending the subnet mask so that some bits that used to identify hosts now identify the subnet, which improves routing, isolation, and address efficiency.
What does /24 mean in CIDR notation?
/24 means the first 24 bits of the address identify the network and the remaining 8 bits identify the host. That gives 2^8 - 2 = 254 usable host addresses per subnet, after subtracting the network address and the broadcast address.
How do I calculate the number of hosts in a subnet?
Take 32 minus the prefix length to get the number of host bits, raise 2 to that power, then subtract 2 for the network and broadcast addresses. For example, a /28 has 32-28=4 host bits, so 2^4 - 2 = 14 usable host addresses per subnet.
What is the difference between a subnet mask and CIDR?
They describe the same boundary. A subnet mask like 255.255.255.0 lists the bit pattern explicitly in dotted-decimal form, while CIDR notation like /24 just counts how many leading bits are set to 1. CIDR is more compact and is how routing tables express the split.
Why are the first and last addresses unusable in a subnet?
The first address (all host bits 0) is the network identifier and the last address (all host bits 1) is the broadcast address. Neither can be assigned to a host, which is why a /24 has 254 usable addresses rather than 256, and a /30 point-to-point link has 2.
Try the subnetting lab
You just learned how subnet masks split a network into host and network portions. Now give PCs addresses and masks, trace between them to see which destinations each host treats as local, and fix a PC that sits on the wrong subnet.
Launch the subnetting lab →