Subnet Masks: Tutorial


Remembering back to when I took my first networking class, subnet masks were the hardest concept for me to grasp. I threw together a quick tutorial that I hope is easy to understand and can help you through this concept. The first thing you need to understand before even looking at subnet-masking is how to read and manipulate binary. Here is a quick youtube tutorial Binary Conversion Tutorial Once, You have a grasp on converting Decimal into Binary, we can move forward.

Anatomy of a Subnet Mask

A subnet mask goes hand in hand with an IP address. It is responsible for telling the computer which portion of an IP address is the network address, and which portion (bits) are reserved for the hosts. It has the same "dotted-decimal" notation, a very common example of an IP address and subnet mask in this format would be: (IP) (mask) The basic structure of this format is a 4-byte address (32-bits), which means there are 32 binary digits (1's and 0's) that make up the address. Translating the mask ( into binary would look like this: 11111111.11111111.11111111.00000000 Note: The mask's leftmost bits must be 1's and the rightmost bits must be 0's( Another way of writing the subnet mask is in CIDR notation, which is basically counting the number of active bits (1's) from the left. So a mask of in CIDR notation would be /24. Applying this to the IP address (, we see that the mask ( has the first 3 octet's (8 bit sets) are all set to 1's, meaning that the first 3 bytes of the IP address are the network address, and the last byte of the IP address is reserved for host addresses. Thus we can conclude that: Network address: Host Address Range: - Note: Host the first and last addresses are reserved for gateway and loopback addresses i.e.( and Here is a handy chart that allows you to quickly translate an octet into its binary equivalent: quickReference


Subnetting is the act of breaking down the host portion of an IP address to separate the distribution of host addresses into separate zones or subnets, within the network. When looking at the right-most octet of a subnet mask we can tell how many subnets are present, and how many hosts per subnet.
 Content Is not completed yet, 3/19/13 

C++ – Relative Alignment of String Output

I was doing a project for my C++ class and was trying to find
an easy solution to print a string to the console and after that
string, I was to print "Record Number: " and the corresponding
number. The problem was that I needed the string to be at an 
absolute position from the left side of the screen. I read various 
blogs trying to find a simple way to do what I desired but was 
unsuccessful (doesn't mean it's not out there). The reasoning I 
was given why setw(25) wasn't working is because it was a string
object. So I developed this work-around, I am no professional
and I'm sure that someone will tell me there is a far simpler way,
but this is how I solved that problem.
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

int main()
	int location;
	int indent;
	bool done = false;
	// create an array of 4 names
	string names[4] = {"Chad", "Mitch", "Abbie", "Courtney"};

		// prompt the user for an index location
		cout << "\nEnter Record number(1-4) or 0 to quit: ";
		cin >> location;

		// input validation
		if (location == 0)
			done = true;
		else if (location < 0 || location > 4)
			cout << "\nYou must enter a number between 1 and 4\n";
			// Prompt for absolute positioning
			cout << "How far from the left would you like to indent: ";
			cin >> indent;

			// Store an isolated instance of the array at index "location"
			string result = names[location - 1];
			// Add spaces after result until desired absolute spacing achieved
			for (int i = result.length(); i < indent; i++)
			   result += " ";

			result += "Record Number: ";

		   // Print formatted text
			cout << endl << result << location + 1 << endl;

	return 0;