Subnetting sucks. Let's not be coy about it. It's a pain in the ass, takes forever and I hate doing it. But life is suffering, and subnetting is something you at least need to understand in concept since, well, modern networking - and, in turn, modern communication - is built on it. It's also a requirement in case you're chasing certification in IT or networking.
So my here goal is to give you a runthrough that will help you create a coherent internal concept for subnetting. This will help you read and understand network topology, and allow you to progress to understanding of deeper networking concepts.
Every computer that can communicate over a network uses the Internet Protocol (IP). Just like every person needs a mouth (or hands) to talk to others, computers need a common protocol to do their talking through. IP allows computers to locate each other either on local networks or on the internet (the internet itself is just a large network of other, smaller, networks). Knowing the IP adress of another networked device (host), allows a computer to send and recieve packets between those hosts.
An IPv4 (internet protocol version 4, the most widespread protocol in use) address will look something like 192.168.20.25. If you notice, it's a group of four numbers separated by dots. Those numbers are actually representative of their binary counterparts. Remember, computers fundamentally don't understand anything other than binary, and our communication protocols are based on this fact. So a computer will see 192.168.20.25 as 11000000.10101000.00001010.00011001. Every IP address looks similar to this set of four octets (group of 8) made up of 32 total bits. To understand how this works, check out my other article on binary [COMING SOON].
Every networked computer will have a host IP address, which identifies the host on a network. Networks also have an IP address, conveniently called network IP address. This identifies a collection of hosts. Usually these hosts will be in the same physical location, like at your home or office, but not necessarily. That's why network and host IP addresses are sometimes referred to as "logical" addresses.
A network IP address would be like a postal, or ZIP, code for your device, while a host IP would be like a street and appartment number. So if you see some IP address out there; let's use 192.168.20.25 for example - is that an address for a host or for a network? For that, we need to look at a concept called the
Every IP address identifies a host and the network it's on. So the previous question was sort of a trick. The subnet mask designates a section of an IP address for the network. For our address 192.168.20.25 (11000000.10101000.00001010.00011001) the subnet mask will look like this: 255.255.255.0 or 11111111.11111111.11111111.00000000 in binary.
So what does that mean? When an octet of a subnet mask is filled in (255 or 11111111), you can read it as "every bit in this set is designated for the network address." The subnet mask in our example is called a 24-bit mask, because the first 24 bit of the total 32 are filled in. With the first 24 bits making up the network address, in our example 192.168.20.xx is the network address while .25 is the host.
It used to be that IP addresses were assigned to classes, depending on the range designated in the first octet. Since these are pretty much ignored at this point, we won't go into it. I should mention, however, the commonly used network addresses. Generally, on the vast majority of networks, you will see addresses along the lines of 192.168.0.xx, 10.0.0.xx. As a carryover from IP address classes, these ranges are usually reserved for private local networks.