# mwohlauer.d-n-s.name / www.mobile-infanterie.de

### Site Tools

It is recommended to have a look at the article subnet, to understand this article a bit better.

## General Contept

The subnet mask is a way of noting which part of an IP address is the host number and which is the network address.

When you have a look at an IPv4 address, it is usually depicted as four numbers separated by a dot, e.g. 192.168.0.1. The subnet mask is also noted in this fashion, e.g. 255.255.0.0. Only in combination you can really say, what part of 192.168.0.1 is the host number and what part is the network number. A subnet is assigned a network number. A host is assigned a host number. In combination, a host inside its subnet has a network address.

In order to understand, what a subnet mask means, you have to look at address and subnet mask in binary depiction. Let's take the above example:

192.168.0.1 = 11000000.10101000.00000000.00000001

255.255.0.0 = 11111111.11111111.00000000.00000000

As you probably noticed, the subnet mask 255.255.0.0 seems to be a series of ones followed by a series of zeros. That's exactly what defines, which part of the address is holding the network number and which part is holding the host number. In our case, applying the mask to the address gives the following result:

192.168.0.0 = 11000000.10101000.00000000.00000000

It's an AND combination of both, mask and address, that gives the network number. For the host part, the opposite is taken. So the subnet mask is negated to:

00000000.00000000.11111111.11111111

and then applied to the address;

192.168.0.1 = 11000000.10101000.00000000.00000001

0.0.255.255 = 00000000.00000000.11111111.11111111

which obviously results in 0.0.0.1 for the host number. So after applying the subnet mask, we can conclude, the network number is 192.168.0.0, while the host number is 0.0.0.1. This means, all numbers of that subnet are between 192.168.0.0 and 192.168.255.255. This is the IP range of the subnet 192.168.0.0.

Important for you to understand is also, that the network number itself may never be used as host's address. So 192.168.0.0 is not available for assignment as an IP address to a host. Same goes for the last host inside a subnet. This is the so-called broadcast address, which all computers on the same network can respond to. So 192.168.255.255 is also not available for a host assignment. This leaves the effectively usable network address space as 192.168.0.1 - 192.168.255.254. The example subnet mask allows for 65534 computers in one network.

You can also have different subnet mask, than 255.255.0.0. Important: The series of ones may never be interrupted by an intermediate zero! So 11111111.11111100.00000000.00000000 or 255.192.0.0 is OK, while 11111111.11111010.00000000.00000000 or 255.250.0.0 is not.

So when applying 255.255.254.0 as a subnet mask on our example IP 192.168.0.1, it places that IP in the network 192.168.0.0, which this time only uses the last 9 bits of the address as host number. So the network already ends at 192.168.1.255. Host range would then be 192.168.0.1 - 192.168.1.254, a total of only 510 computers.

Network: 192.168.0.0 = 11000000.10101000.00000000.00000000

Host 1: 192.168.0.1 = 11000000.10101000.00000000.00000001

Host 511: 192.168.1.255 = 11000000.10101000.00000001.11111111

## CIDR Notation

Aside from the depiction of a group of four numbers separated by dots for subnet mask and address each, there is also the more compact CIDR notation, that appends the number of bits used for the network mask after the address. So the above shown networks could also be written as 192.168.0.0/16 and 192.168.0.0/23.

## IPv6

The above mentioned aspects can in principle also be applied to IPv6. The difference between the two are, that IPv6 subnet masks are usually only entered as number of bits of the network, the so-called prefix. And IPv6 networks know hierarchical structures. While in IPv4 all subnets are equal in their position or importance, IPv6 can partition a subnet in further subnets. So when your ISP assigns you an IPv6 address, you are usually assigned an entire prefix, within which your hosts can select their IPs freely. As most users let their router's DHCP assign IPv6 addresses automatically to the hosts, that leaves you with little to do. But in principle you could use the delegated prefix and partition it into two or more further subnets. E.g. you are assigned a 64 bit prefix. That leaves you with a 64 bit address space, that you can freely use. You could then take another 2 bits from that, as part of the new prefixes of four subnets. That would still leave 62 bits for the hosts in each network and 66 bits for their prexif/network number. However, that's something your router would have to support. This is when you ought to really know what you are doing and what to use for the task.