Free lesson · IP Addresses and Subnet Masking

Binary, just enough of it

You cannot understand subnet masks without seeing addresses in binary. The good news is that you need very little binary, and it is all in this lesson.

Eight bits, eight values

Each octet is 8 bits. Each bit position has a value, doubling from right to left:

128   64   32   16    8    4    2    1

An octet's value is the sum of the positions set to 1.

192  =  1 1 0 0 0 0 0 0   =  128 + 64
255  =  1 1 1 1 1 1 1 1   =  128+64+32+16+8+4+2+1
  0  =  0 0 0 0 0 0 0 0
 20  =  0 0 0 1 0 1 0 0   =  16 + 4

Those eight numbers — 128, 64, 32, 16, 8, 4, 2, 1 — are worth memorising. They are the only arithmetic in this course.

Converting decimal to binary

Work left to right. For each position, ask "does this fit in what remains?" If yes, write 1 and subtract; if no, write 0.

Take 200:

128 fits in 200?   yes → 1, remainder 72
 64 fits in 72?    yes → 1, remainder 8
 32 fits in 8?     no  → 0
 16 fits in 8?     no  → 0
  8 fits in 8?     yes → 1, remainder 0
  4, 2, 1                 0 0 0

200 = 1 1 0 0 1 0 0 0

Check: 128 + 64 + 8 = 200. Correct.

The values you will actually meet

Subnet masks only ever use eight values in their interesting octet, because the ones are always contiguous from the left:

DecimalBinaryOnes
0000000000
128100000001
192110000002
224111000003
240111100004
248111110005
252111111006
254111111107
255111111118

That is the whole table. If a mask octet is not in this list, it is not a valid mask — 255.255.255.100 is meaningless, because 100 is 01100100 and the ones are not contiguous.

You will find yourself recognising these on sight within a day of using them. Print the table; it is the most useful page of the handout.

This is one lesson of 92

AWS Cloud Networking: From IP Addresses to Production VPCs continues from here — 6 lessons are free to read like this one, and the rest come with the course. Enrolled readers also get an AI tutor that has read the lesson they are on.

See the full course