Mochabomb

Web Design and Technical notes

Mochabomb header image 2

Do subnet math in your head

April 12th, 2007 12:40 am · 8 Comments

Subnets are a necessary part of networking and while there are a lot of websites with charts out there. You can print out one of many such charts really small, then laminate it, or better, use our God-given noggen and memorize it! We learned multiplication tables as a kid - learning subnetting is about as easy you work with me on this… Take 20 minutes now and you’ll know this for life.

At first, subnets were hard for me to understand - until my brother Hans somegeek explained it in a really simple way.

Definition
A subnet is a portion of the full net - and every network we use is part of a subnet. As geeks we mostly deal with class C or smaller.

Lets work with an example. You just started working at RARPAnet and have lots of computers to set up. You were assigned the entire 10.0.0.0 network for address space. Since the 10 network is designated for use on private networks (its not routed on the public internet) you have lots of addresses.

Class - amount of address space you have:
Class A: The entire 10 network - any address where the first number is the same
Class B: The 10.1, or the 10.2 network - up to the 10.255 network - any address where the first 2 numbers are the same
Class C: 10.0.1, or 10.0.2, up to the 10.0.255 network - any address where the first 3 numbers are the same

Examples of subnets from the 10 network:
Class A: 10.0.0.0 to 10.255.255.255
Class B: 10.1.0.0 to 10.1.255.255
Class C: 10.1.0.0 to 10.1.0.255

Every Subnet has 4 parts to it:

  1. Network - this is the first address on the network - designates the starting address
  2. Hosts - addresses that can be used for hosts (routers, computers, etc)
  3. Broadcast - the last address of the network - for ‘yelling’ at everyone at the same time.
  4. Netmask - used to get the network - put as a mask over the address

Example 1: Break down the 192.168.1 network

For 192.168.1 is a class C with:
192.168.1.0 network
192.168.1.1 - 254 hosts
192.168.1.255 broadcast
255.255.255.0 netmask

Every IP address is made up of 32 bits in 4 chunks of 8 bits.

To count in binary is really simple - use the table below to make the number - a sum of its parts.

Basic table for counting up to 255 in binary: first row of 1’s, second row powers of 2 starting with 1:

1      1     1     1     1    1    1    1
128   64   32   16    8    4    2    1

Conversion of regular numbers to binary:

1 in binary:

1      1     1     1    1    1    1   1
128   64   32   16   8    4    2   1
                                          1

2 in binary: 2 + 0

1      1     1     1    1    1    1   1
128   64   32   16   8    4    2   1
                                     2 + 0
                                     1   0

5 binary: 4 + 1

1      1     1     1    1    1    1   1
128   64   32   16   8    4    2   1
                                4    0   1 = 5
                                1    0   1

18 binary: 16 + 2

1      1     1     1    1    1    1   1
128   64   32   16   8    4    2   1
                    16   0    0    2   0 = 18
                        1    0    0    1   0

187 in binary: 128 + 32 + 16 + 8 + 2 + 1

 1      1     1     1    1    1    1   1
128    64   32   16   8    4    2   1
128    0    32    16   8    0    2   1 = 187 
1        0       1       1     1      0    1     1 

Going backwards: convert 10110 to a regular decimal number:
1*16 + 0*8 + 1*4 + 1*2 + 0*1 = 22 - convert 22 back to binary above - it can be done in your head.

With the binary math out of the way, the binary for the full IP address is: 1111111.1111111.1111111.1111111

Detailed breakdown

Now, for a host with ip of 192.168.1.12, the IP and subnet are often denoted together in one of two ways:
192.168.1.12 255.255.255.0
or more often used and shorter to write:
192.168.1.12/24

The /24 means of the 32 bits for the address, use first 24 bit to denote the network, last 8 bits for address space:

For a /24: There 8 bits for address space:
Subtract the slash number from 32: in the case of /24:
32 - 24 = 8 bits;
Then the number of IP addresses used is 2^8bits = 256;

256 addresses: first address is network, last is broadcast; 254 in the middle are for hosts.
192.168.1.0 network
192.168.1.1 to 192.168.0.254 hosts
192.168.1.255 broadcast
255.255.255.0 subnet mask
1111111.1111111.1111111.00000000 Last 8 bits are zero's

How to easily remember this:
Mentally I think this: I see 192.168.1/24 - then
1. an IP address has 32 bits for address
2. 32 - 24 = 8; 2^8 = 256;
3. 256 addresses - first one is network; last one is broadcast, the rest in the middle are hosts.

Example: You are given an address of 192.168.1.16/29 for your network:
For a /29: There are 3 bits for address space:
1. 32 bits - 29 bits = 3 bits for address space;
2. 2^3 = 8 - the number of addresses in this network
3. Since my first address is 192.168.1.16, 192.168.1.23 is my last address

Summary:
8 addresses: First is network, 6 in the middle for hosts, last is the broadcast address:

192.168.1.16                         network
192.168.1.17 to 192.168.0.22   hosts
192.168.1.23                         broadcast
255.255.255.248                    subnet mask     

1111111.1111111.1111111.1111000  Last 3 bits are zero's

… and since this subnet is most like subdivided into groups of 8 ip’s, there is a new network every 8 IP addreses on this 192.168.1 subnet - a good way to segment a network for security, etc.

192.168.1.0-7
192.168.1.8-15
192.168.1.16-23     (your network)
192.168.1.24-31
192.168.1.32-39
...and so on up to
192.168.1.248-255

So there it is - binary math, subnets and now no chart to carry in your pocket. This website has a subnet calculator - good for refence and checking your work.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • MisterWong
  • Reddit

Tags: Linux · Networking · Unix · Windows

8 responses so far ↓

  • 1 Lee Sobremonte // Apr 24, 2007 at 12:00 pm

    Sup brother in law. I didnt know about this site until I talked to charisse today. I Iike the networking content(since it applies to me). Keep up the good work.

  • 2 Eric Roof // May 22, 2007 at 10:55 am

    I’m gonna need to spend a little more time on this when I have it before I could give feedback. Thanks,
    I look forward to it. I like the website so far.

  • 3 Ran // Sep 4, 2008 at 3:13 am

    I noticed a minor error in your calculation that may confuse some folks while perusing your web site…

    How to easily remember this:
    Mentally I think this: I see 192.168.1/24 - then
    1. an IP address has 32 bits for address
    2. 32 - 24 = 4; 2^8 = 256;
    3. 256 addresses - first one is network; last one is broadcast, the rest in the middle are hosts.

    #2. 32 - 24 = 8…not 4

  • 4 gregg // Sep 4, 2008 at 5:12 pm

    Fixed - thanks for stopping by and the comment!

  • 5 aq // Oct 6, 2008 at 4:35 pm

    I like this. This site is far easier than other sites, once you get past the binary numbers.

  • 6 jon // Oct 16, 2008 at 3:32 pm

    nice……
    this helped me to understand. just starting out.

    just like the mult.table, this is now in my back pocket!

  • 7 emmanuel // Nov 12, 2008 at 6:11 am

    could we also get some online objective questions after which an evaluation score is given. thanx.

  • 8 gregg // Nov 12, 2008 at 5:36 pm

    .. great idea - I’ll start working on it and that has a good question - please feel free to contribute suggestions.

Leave a Comment