So far, we've learned about network IDs,

which are used to identify networks,

and host IDs, which are used to identify individual hosts.

If we want to split things up even further,

and we do, we'll need to introduce a third concept, the subnet ID.

You might remember that an IP address is just a 32-bit number.

In a world without subnets,

a certain number of these bits are used for the network ID,

and a certain number of the bits are used for the host ID.

In a world with subnetting,

some bits that would normally comprise the host ID are actually used for the subnet ID.

With all three of these IDs representable by a single IP address,

we now have a single 32-bit number that can be

accurately delivered across many different networks.

At the internet level, core routers only care about the network ID

and use this to send the datagram

along to the appropriate gateway router to that network.

That gateway router then has some additional information that it can use to send

that datagram along to

the destination machine or the next router in the path to get there.

Finally, the host ID is used by

that last router to deliver the datagram to the intended recipient machine.

Subnet IDs are calculated via what's known as a subnet mask.

Just like an IP address,

subnet masks are 32-bit numbers that are normally written now as four octets in decimal.

The easiest way to understand how subnet masks work is to compare one to an IP address.

Warning: dense material ahead.

We're about to get into some tough material,

but it's super important to properly understand

how subnet masks work because they're so frequently misunderstood.

Subnet masks are often glossed over as magic numbers.

People just memorize some of the common ones

without fully understanding what's going on behind the scenes.

In this course, we're really trying to ensure

that you lead with a well-rounded networking education.

So, even though subnet masks can seem tricky at first,

stick with it, and you'll get the hang of it in no time.

Just know that in the next video,

we'll be covering some additional basics of binary math.

Feel free to watch this video a second or third time after reviewing the material.

Go at your own pace,

and you'll get there in the perfect amount of time.

Let's work with the IP address 9.100.100.100 again.

You might remember that each part of an IP address is an octet,

which means that it consists of eight bits.

The number 9 in binary is just 1001.

But since each octet needs eight bits,

we need to pad it with some zeros in front.

As far as an IP address is concerned,

having a number 9 as the first octet is actually represented as 0000 1001.

Similarly, the numeral 100 as an eight-bit number is 0110 0100.

So, the entire binary representation of the IP address

9.100.100.100 is a lot of ones and zeros.

A subnet mask is a binary number that has two sections.

The beginning part, which is the mask itself is

a string of ones just zeros come after this,

the subnet mask, which is the part of the number with all the ones,

tells us what we can ignore when computing a host ID.

The part with all the zeros tells us what to keep.

Let's use the common subnet mask of 255.255.255.0.

This would translate to 24 ones followed by eight zeros.

The purpose of the mask or the part that's all ones is

to tell a router what part of an IP address is the subnet ID.

You might remember that we already know how to get the network ID for an IP address.

For 9.100.100.100, a Class A network,

we know that this is just the first octet.

This leaves us with the last three octets.

Let's take those remaining octets and imagine

them next to the subnet mask in binary form.

The numbers in the remaining octets that have a

corresponding one in the subnet mask are the subnet ID.

The numbers in the remaining octets that have a corresponding zero are the host ID.

The size of a subnet is entirely defined by its subnet mask.

So for example, with the subnet mask of 255.255.255.0,

we know that only the last octet is available for host IDs,

regardless of what size the network and subnet IDs are.

A single eight-bit number can represent 256 different numbers,

or more specifically, the numbers 0-255.

This is a good time to point out that, in general,

a subnet can usually only contain two less than the total number of host IDs available.

Again, using a subnet mask of 255.255.255.0,

we know that the octet available for host IDs can contain the numbers 0-255,

but zero is generally not used and

255 is normally reserved as a broadcast address for the subnet.

This means that, really,

only the numbers 1-254 are available for assignment to a host.

While this total number less than two approach is almost always true,

generally speaking, you'll refer to the number of

host available in a subnet as the entire number.

So, even if it's understood that two addresses aren't available for assignment,

you'd still say that eight bits of host IDs space have 256 addresses available, not 254.

This is because those other IPs are still IP addresses,

even if they aren't assigned directly to a node on that subnet.

Now, let's look at a subnet mask that doesn't draw

its boundaries at an entire octet or eight bits of address.

The subnet mask 255.255.255.224 would translate to 27 ones followed by five zeros.

This means that we have five bits of host ID space or a total of 32 addresses.

This brings up a shorthand way of writing subnet masks.

Let's say we're dealing with our old friend

9.100.100.100 with a subnet mask of 255.255.255.224.

Since that subnet mask represents 27 ones followed by five zeros,

a quicker way of referencing this is with the notation /27.

The entire IP and subnet mask can be written now as 9.100.100.100/27.

Neither notation is necessarily more common than the other,

so it's important to understand both. That was a lot.

Make sure to go back and watch this video again if you need a refresher,

or if you're a total wiz,

you can move on to the next video on basic binary math.

I'll see you there or maybe here.