IP Address

Whether on your home Wi-Fi or across the internet, your device needs an address to send and receive data. Just like your home has a street address, your computer or phone has an IP address. It’s a unique identifier that helps data know where to go.

There are two types of IP addresses: IPv4 and IPv6.

In this post, we’ll focus on IPv4.

IPv4

You’ve probably seen something like this before: 192.168.0.1.

That’s an example of IPv4 address.

It’s made of four numbers, called octets, separated by dots. Each octet can go from 0 to 255.

Under the hood, each octet is just 8 bits. So the whole IP address is 32 bits total.

IP address consists of two parts:

To know where to split it, we have to use the subnet mask.

Subnet Mask

A subnet mask looks like an IP address (e.g. 255.255.255.0).

The difference is that instead of identifying a device, it tells us which part of the IP address is the network, and which part is the host.

It also must start with a group of consecutive 1s and end with consecutive 0s.

This works by using bits:

For example:

  255    .    255   .   255    .    0
11111111 . 11111111 . 11111111 . 00000000

In this case, the first 24 bits (the 1s) are for the network, and the last 8 bits (the 0s) are for hosts on that network.

Without subnet masks, computers wouldn’t know if an IP address is on their own network (send directly) or somewhere else (send to the router).

CIDR Notation

You’ll often see subnet masks written in a shorter form called CIDR (Classless Inter-Domain) notation.

Instead of writing 255.255.255.0, we write it as /24, which means: “The first 24 bits are 1s.”

This number can go from /0 (no network bits, entire IPv4 space) to /32 (all bits fixed, a single address).

Here are the most common subnet masks:

CIDRBinarySubnet Mask
/2611111111.11111111.11111111.11000000255.255.255.192
/2511111111.11111111.11111111.10000000255.255.255.128
/2411111111.11111111.11111111.00000000255.255.255.0
/1611111111.11111111.00000000.00000000255.255.0.0
/811111111.00000000.00000000.00000000255.0.0.0

Splitting IP Address into Network and Host

To get network and host parts from IP, we use a bit operation called AND.

It goes bit by bit, comparing the IP address and the subnet mask.

Let’s look at an example:

IP:    192.168.0.1
Mask:  255.255.255.0 (/24 in CIDR)

Convert both to binary:

IP:    11000000.10101000.00000000.00000001
Mask:  11111111.11111111.11111111.00000000

Now we apply the AND operation:

Result: 11000000.10101000.00000000.00000000 (192.168.0.0)

This result is the network address. All devices in this network will share this part.

The rest of the bits (the last 8 in this case) are for hosts, they tell us which device it is on that network.

To find the device (host) number, we do a bitwise NOT on the subnet mask (which flips 1s to 0s and 0s to 1s), and then AND it with the IP:

NOT Mask:      00000000.00000000.00000000.11111111
AND with IP:   11000000.10101000.00000000.00000001
Result:        00000000.00000000.00000000.00000001

So the device number is 1, it’s the first device in this network.

Subnet Calculator

You can use the calculator below to experiment with IP addresses, subnet masks, and see how network and host addresses are determined.

Number of Network Bits
Number of Host Bits
Subnet Mask
Network Address
Broadcast Address
First IP Address
Last IP Address
Usable Addresses

Summary

IP addresses are like digital street addresses, and subnet masks are the rules that tell your device which part is the “neighborhood” (network) and which part is the “house number” (host).

With subnet masks, we can slice big networks into smaller, easier-to-manage chunks. This organizes devices and keeps traffic efficient, your computer knows when to talk directly to a neighbor and when to go through the router.

So the next time you see something like 192.168.1.42/24, you’ll know that:


Find this post helpful? Subscribe and get notified when I post something new!