IP addresses and subnets with slash notation

253 views

So I was adding IP address ranges to AWS and ones I was adding had `/20` and `/16` on them. I realise this has an effect on the range, but I don’t understand what effect.

Part of the IP address stays the same and the other part(s) don’t.

Can someone explain what this means?

In: 9

4 Answers

Anonymous 0 Comments

The subnet mask tells the computer what part of the IP address denotes the network and what part of the IP address denotes the host. This allows it to easily distinguish (and appropriately label) messages intended for computers on the same network (which don’t need to be routed) and messages intended for computers on a different network (which do).

Since an IP address is simply a series of 32 bits, the easiest way to do this is to simply say the first X bits represent the network part and the remaining bits represent the host. When the subnet mask is written in slash notation, the number is X (the number of bits that represent the network).

So a /20 mask says the first 20 bits are the network and the remaining 12 bits represent the hosts. A /16 mask says the first 16 bits are the network and the remaining 16 bits represent the hosts. This effects the range because the more/fewer bits you have to represent hosts, the more/fewer hosts you can have on a network in that range.

With a /20 network and 12 bits for hosts, you can only have 2^(12) = 4,096^(*) hosts but with a /16 network and 16 bits for hosts you can have 2^(16) = 65,536^(*) hosts. Within each of those networks the first 20 and 16 bits of the IP address will stay the same, respectively.

^(* – the first and last IP addresses in the host range of a network are reserved and cannot be used for hosts, so it’s technically 4,094 and 65,534 hosts.)

Anonymous 0 Comments

The slash notation refers to the subnet mask. The number refers to the number of bits which will be ‘masked’. (An IPv4 has 32 bits). Basically, it’s used to indicate a range of IPs.

There are a number of free online IP calculators which can help you understand how this value affects results. I personally use https://jodies.de/ipcalc

Anonymous 0 Comments

Previous comments do a good job for the ELI5. For further googling it’s helpful to know that this is called CIDR notation.

Anonymous 0 Comments

There are different ways to write down a range of IP addresses that don’t require writing them all out in giant list.

Those different ways use the fact that you can only group together IP addresses in certain ways and can’t just divide them up arbitrarily. This allows you to write things down fairly compactly, the trick is to figure out how to read them.

It helps to understand what IPv4 addressee really are other than bunch of numbers divided by dots.

Fundamentally an IP address is just a 32- bit number. You could write that number down as single decimal between 0 and 4294967295. Nobody does that since it is not very helpful. You could also write it down as an 8 digit hexadecimal number. This would actually be more useful but isn’t really done either.

What is usually done is to write them down as 4 separate decimal numbers between 0 and 255 and separate these by dots. Basically taking the originally 32 bit number breaking it up into 4 bytes and and writing down the value of each byte as number separately.

This works well but somewhat obscures some of the underlying mechanics.

To really see what is going on you could write it down as a series of 1s and 0s 32 digits long. this is really unhelpful for memorizing or writing things as human but useful to see what is going on under the hood.

An example:

The IP-address `192.168.100.1` is one you may find commonly used in home networks as the address for the router.

That address written down in binary would loo like:

1100 0000 1010 1000 0110 0100 0000 0001

Usually this address is part of a network that includes all addresses that start with `192.168.100.x` where x is some number between 0 and 255 (technically between 1 and 254 as 0 and 255 have a special meaning in that network and are usable as addresses but lets ignore that for now)

Those other address would all look like this in binary:

1100 0000 1010 1000 0110 0100 XXXX XXXX

Where each x can be either a 1 or a 0.

This is a really easy to understand rule and we wouldn’t really need any special notation for this if they were all that easy. We could just give it a name that means: any address where the first three parts are the same is part of that network.

We actually have such a name. it is what we used to call a class C network. Class B if for the first a network where only the first two numbers are the same and Class A is for when only the number before the first dot is the same.

This system is easy to read an understand is really inflexible though. Either the range of addresses is far too big or far too small for what you want.

So there is a way to make better smaller or bigger networks out of the existing ones.

One is to take two neighboring networks and merge them together for one that is double the size. You can for example take all IP addresses from `192.168.100.X` and `192.168.101.x` and put them together.

If you write both these things out in binary you will find they look like this:

1100 0000 1010 1000 0110 0100 XXXX XXXX
1100 0000 1010 1000 0110 0101 XXXX XXXX

Very similar with only the last digit before the 8 Xs being different.

In fact if you think about since that digit can be now either 1 or 0 in your new merged network you could write it down as

1100 0000 1010 1000 0110 010X XXXX XXXX

Everything else stays the same and the last 9 digits can be 1s or 0s in this new merged network.

In fact if you wanted to double it again and would want to include all IPs that start with a `192.168.100` or `192.168.101` or `192.168.102` or `192.168.103`. You would end up with 4 ranges that you could write like this:

1100 0000 1010 1000 0110 0100 XXXX XXXX
1100 0000 1010 1000 0110 0101 XXXX XXXX
1100 0000 1010 1000 0110 0110 XXXX XXXX
1100 0000 1010 1000 0110 0111 XXXX XXXX

or just like this:

1100 0000 1010 1000 0110 01XX XXXX XXXX

Neat, right?

All we really need to do is give a single address from anywhere in the range and tell people how many of the 32 binary digits describe the network itself and which are X that describe the adresses in the network.

One way of doing that is write down the number likie `192.168.100.0/24` with the `/24` being the number of binary digits that describe the network. Since there is 32 in total and each group of 8 bits works out as one decimal number in the normal notation `192.168.100.0/24` just means everything that starts with `192.168.100`. this is the Class C network we started with.

Merging two of these `/24` networks together gets you a `/23` network- `192.168.100.0/23` means any address that starts with `192.168.100` or `192.168.101` as we described above.

And the four networks merged together gives you a `/22` network. the example above is `192.168.100.0/22` and means anything that starts with `192.168.100` or `192.168.101` or `192.168.102` or `192.168.103`.

What happens if you don’t need a whole `/24` network? You can split it up into two `/25` networks.

From the example above we can take the `192.168.100.0/24` which looks like this:

1100 0000 1010 1000 0110 0100 XXXX XXXX

And split it up into two networks that look like this:

1100 0000 1010 1000 0110 0100 0XXX XXXX
1100 0000 1010 1000 0110 0100 1XXX XXXX

The first would be `192.168.100.0/25` (because the first 25 bits describe the network) and go from `192.168.100.0`to `192.168.100.127`the second would be `192.168.100.128/25`and go from `192.168.100.128` to `192.168.100.255`.

Simple enough.

another common way to write down the same information is to wite it all down as decimal in a subnet mask.

What would 24 1s followed by 8 0s look like when written down as a decimal IP address?

1111 1111 1111 1111 1111 1111 0000 0000

looks like this

255.255.255.0

`255.255.255.0` conveys the same information as `/24`, it says 24 1s followed by 8 0s it just takes up more space.

A `/23`network that is twice that size would be written as `255.255.254.0` and so on.

In normal networking you will rarely i fever need any of that.

Almost all what you have to deal with on your network is a `/24` Network where all you need to know is that every address where the parts before the last dot are the same is in the network.

Occasionally you will encounter `/23` (255.255.254.0) ones that are twice that size.

The only thing that may make some time getting use to is realizing where the networks get split apart and lumped together. for example you may find yourself asking why `192.168.100.0/24` must be lumped together with `192.168.101.0/24` and not `192.168.99.0/24`. You can either tell that by looking at how the numbers are written in binary or by remembering that if you merge two networks together you draw the lines at the beginning 0+1, 2+3, 4+5, 6+7, …. 98+99, 100+101, 102+103, … ,254+255

You always start with a number divisible by two. is you merge fou4 networks you start by 0, 4, 8, 12 … always by one divisible by 4 and so on.