Home » Networking » Calculating Ip Addresses And Subnets

Calculating IP Addresses and Subnets – A Reference

This article aims to familiarise you with IP addresses and subnets and the calculations involved when setting them up. It’s a big topic, so this article will try to stay focused on its practical side to help get you on the right track and subnetting your home network with ease.

Networking and Subnets

Let’s skip the analogies and break it straight down:

An IP address contains two components the network address describing the network and the host address describing the host on the network.

  • Networks can be split into subnets – sub-networks
  • The subnet mask (AKA netmask) defines the range of IP addresses available within a (sub) network.
  • Hosts in the same subnet can communicate directly.
  • Hosts on different subnets must communicate via a router.
  • The subnet mask determines, in an IP address, which part identifies the network and which part identifies the host (or device) on the network.
    • It’s called a ‘mask’ because it ‘masks’ the network part of the IP address, leaving the host address.

Each subnet contains at least two addresses:

  • Network address
    • Usually, the first address in the range.
    • Identifies the network itself – devices use it to recognize different networks.
  • Broadcast address
    • Usually, the last address in the range.
    • Traffic to this address goes to all hosts on the network.


IPv4 (Internet Protocol version 4) is the standard used for computers to communicate on a network (and the Internet).

An IPv4 address looks like this:

It consists of 4 sets of up to 3 numbers referred to as OCTETS from 0-255 (inclusive) separated by a period (.).

They’re called octets as each set consists of 8 bits when expressed in binary – see the table later in the article for a visual representation.

This gives a total of 4,294,967,296 possible addresses – a supply that has rapidly dwindled as more and more people get online, requiring Internet IP addresses for their devices. Many tricks are being used to keep the supply available, like having devices share addresses behind routers, but it’s only a matter of time before the addresses run out.

Due to this, IPv4 is slowly being replaced out on the Internet. Though it is still the standard, when IPv4 addresses run out, they’ll run out, and IPv6 will reign.

However, IPv4 remains popular and will remain popular on local networks in homes and offices, as:

  • It is easy to read and calculate network addresses/subnets without a special calculator.
  • Legacy device support (many only support IPv4) – things like office printers, Point of Sales hardware, etc
  • It’s way easier to remember an IPv4 address for a few minutes while you run from one side of the office to another than to remember an IPv6 address!

Subnet Masks

Here’s an IPv4 subnet mask, commonly used on home networks:

It has the same format as a standard IPv4 address. This subnet mask is for a class C subnet, as shown in the below table.

For the netmask, the first three octets have a value of 255, which determines that the IP addresses for hosts within the subnet will share the first 3 octets. This means that the first 3 sets of numbers are the network IP address, and the last set/octet is the host IP address – allowing for 256 unique hosts (254 subtracting the network and broadcast addresses).

Why is this? Check out the table below, which is hopefully the only binary we’ll need to explain things:

255 255 255 0
11111111 11111111 11111111 00000000

Remember this for later when we look at CIDR Notation! 8 + 8 + 8 = 24

This table shows the binary representation of each octet. You can see that 255 results in all of the binary values in the octets being set to 1, which denotes that they are part of the network address. The leftover bits (0s) are thus the available host IP addresses.

Here’s a second octet table to further illustrate:

255 255 128 0
11111111 11111111 10000000 00000000

Remember this for later when we look at CIDR Notation! 8 + 8 + 1 = 17

Again, this table shows the binary representation of each octet. The third octet is set to 128 rather than 255, meaning that part of that octet is available for host addresses as well as the final octet.

CIDR Notation

CIDR (Classless Inter-domain Routing) notation is a shorthand way of describing an IP address and its subnet information. It looks like this:
  • Everything before the forward slash is the IP address.
  • The number after the slash is a decimal number suffix describing the network mask.

Remember 8 + 8 + 8 = 24 from above? That’s how we calculated this decimal suffix – it’s the sum of the binary representation of the netmask

Thus, the decimal suffixes in CIDR notation range from 0 to 32.

This means you can represent IP ranges with as few as 2 addresses to as many as 232 addresses.

Public and Private Addresses, Subnet Classes

IPv4 is split into several classes – the classes are big subnets described in this table:

Class Subnet mask Number of addresses First octet Example address
Class A Subnet 16,777,216 Between 1 and 126, inclusive
Class B Subnet 1,048,576 Between 128 and 191, inclusive
Class C Subnet 65,536 Between 192 and 223, inclusive

These ranges are considered private address space (for use on home or office networks, with no public access), and everything outside of them is considered public address space (the Internet!).

Your home WiFi network devices will all have an address in a range defined in one of these classes. When a device requests data from the Internet, your router will have an external address in the public range, and your router will translate traffic from the public internet to the device on your private network, which made the request.

Subnetting in IPv4 – Practical Examples

We will focus on subnetting with private addresses. If you’re working in the public address space, you should probably pick up some heavier reading on the topic.

Why would you want to subnet your home network?

  • Split up your network – keep your home entertainment devices separate from your mission-critical work devices.
  • Keep the kids on their own network so they can’t access your stuff.
  • Or do the opposite – fit more devices on your network by setting up a larger than default subnet.

The Quick Method For Calculating Subnets and IP Addresses

Just use this table – it summarizes the IP address counts, netmasks, and CIDR notations! You can manually count binary bits and do these calculations yourself, but who actually wants to do that?

CIDR notation Available IP Addresses IP Addresses Available to Hosts Netmask
/30 4 2
/29 8 6
/28 16 14
/27 32 30
/26 64 62
/25 128 126
/24 256 254
/23 512 510
/22 1,024 1,022
/21 2,048 2,046
/20 4,096 4,094
/19 8,192 8,190
/18 16,384 16,382
/17 32,768 32,766
/16 65,536 65,534
/15 131,072 131,070
/14 262,144 262,142
/13 524,288 524,286
/12 1,048,576 1,048,574
/11 2,097,152 2,097,150
/10 4,194,304 4,194,302
/9 8,388,608 8,388,606
/8 16,777,216 16,777,214
/7 33,554,432 33,554,430
/6 67,108,864 67,108,862
/5 134,217,728 134,217,726
/4 268,435,456 268,435,454
/3 536,870,912 536,870,910
/2 1,073,741,824 1,073,741,822
/1 2,147,483,648 2,147,483,646
/0 4,294,967,296 4,294,967,294

You’ll notice that subnets all have a number of IP addresses that are a power of 2 – You can’t, for example, have a subnet with 7 IP addresses

Here’s how to use the table with some real-world examples.

Example 1

  • A network in the Class C range
  • 16 IP addresses
  • Including network and broadcast addresses

So let’s build a network with:

  • IP range of to (16 total addresses as we start with 0)

By referring to the above table and finding the row with 16 available addresses, and taking the CIDR and netmask, we find that we will need:

  • Subnet mask of
  • CIDR of

This network will have:

  • The network address of
  • The broadcast address of
  • 14 IP addresses left for hosts to use

Example 2

  • A network in the Class A range
  • 512 IP addresses
  • Including network and broadcast addresses

So let’s build a network with:

  • IP range of to (512 total addresses – as the last octet can hold 256 unique values, and the second to last octet will need to have two unique values, so that multiplied they create 512 possible unique IP addresses)

By referring to the above table and finding the row with 512 available addresses, and taking the CIDR and netmask, we find that we will need:

  • Subnet mask of
  • CIDR of

This network will have:

  • The network address of
  • The broadcast address of
  • 510 IP addresses left for hosts to use


IPv6 is the solution to the dwindling number of addresses used for IPv4. An IPv6 address looks like this:


It consists of 8 sets of 4 hexadecimal digits separated by a colon (:). It allows for an unfathomable number of addresses. We will not look at subnetting for IPv6 here – it’s just easier to use a special IPv6 subnet calculator, and IPv6 is yet to supersede IPv4 on local networks.


There are whole books dedicated to IP addressing and networking if you want to fully grok what’s going on – if you’re working on mission-critical networks, a full understanding of the underpinnings of network and even IPv6 is probably a good thing to have.

The goal of this article was to distill the basics without getting too bogged down, a quick read to get you jump-started on IP networking – hopefully, no meaning was lost in brevity.

Check out our other networking articles!

Photo of author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment