Calculating IP Address Using
the Binary Method
An IP address is a 32-bit number that is usually represented in
decimal format for human readability. Each bit in the 32-bit number can either
be 0 or 1, which means that there are a total of 2^32 (or 4,294,967,296)
possible IP addresses.
To represent an IP address in binary format, we can convert each
decimal number in the IP address to its binary equivalent. For example:
192 = 11000000 168 = 10101000 42 = 00101010 0 = 00000000
So the binary representation of the IP address 192.168.42.0
would be:
11000000.10101000.00101010.00000000
In binary format, each group of 8 bits is called an octet. So we
can also represent the IP address in binary format as a series of 4 octets:
11000000 . 10101000 . 00101010 . 00000000
Each bit in the binary representation of an IP address
represents a power of 2, starting from 2^0 (or 1) for the rightmost bit and
doubling with each bit to the left. For example:
128 64 32 16 8 4 2 1 1 1 0 0 0 0 0 0 = 192 128 64 32 16 8 4 2 1
1 0 1 0 1 0 0 0 = 168 128 64 32 16 8 4 2 1 0 0 1 0 1 0 1 0 = 42 128 64 32 16 8
4 2 1 0 0 0 0 0 0 0 0 = 0
So the IP address 192.168.42.0 can also be represented in binary
format using the power of 2 notation:
11000000.10101000.00101010.00000000 128+64 168 42 0
Culculating a Subnet Mask
To calculate a subnet
mask, you need to determine the network portion and the host portion of the IP
address. The subnet mask is a 32-bit number that has a series of 1's on the
network portion and a series of 0's on the host portion.
The length of the network portion of the
subnet mask is determined by the number of subnets you want to create. The
length of the host portion is determined by the number of hosts you want to
assign to each subnet.
Here are the steps to calculate a subnet mask:
- 1. Determine the number of subnets you want to create.
- 2. Determine the number of hosts you want to
assign to each subnet.
- 3. Convert the number of subnets and hosts to
binary.
- 4. Calculate the number of bits needed for the
network portion and the host portion.
- 5. Write the subnet mask in binary using the
appropriate number of 1's for the network portion and 0's for the host portion.
- 6. Convert the binary subnet mask to decimal
format for human readability.
Here is an example:
Suppose you want to create 4 subnets, each
with up to 16 hosts.
- 1. The number of subnets is 4, which is 100 in
binary.
- 2. The number of hosts is 16, which is 10000 in
binary.
- 3. 100 (subnets) and 10000 (hosts) are both 4-bit
numbers in binary.
- 4. You need 2 bits for the network portion (2^2 =
4 subnets) and 4 bits for the host portion (2^4 = 16 hosts).
- 5. The subnet mask in binary is
11111111.11111111.11111100.00000000.
- 6. The subnet mask in decimal format is
255.255.252.0.
So the subnet mask for
creating 4 subnets, each with up to 16 hosts, is 255.255.252.0.
Converting
Binaries to Decimals
To convert a binary number to decimal, you can use the following method
1. Write down the binary number.
2. Assign each digit of the binary number a power
of 2, starting from 0 and increasing by 1 for each subsequent digit. For
example, if the binary number is 1011, you would assign powers of 2 as follows:
· 1 (the rightmost
digit) is 2^0 = 1
·
1 (the
second-rightmost digit) is 2^1 = 2
·
0 (the third-rightmost
digit) is 2^2 = 4
·
1 (the leftmost digit)
is 2^3 = 8
3. Multiply each digit of the binary number by
its corresponding power of 2.
4. Add up the products from step 3 to get the
decimal equivalent of the binary number.
For example, to convert the binary number 1011 to decimal
1. Write down 1011.
2. Assign powers of 2: 8, 4, 2, 1.
3. Multiply each digit by its corresponding power
of 2: 1x1 + 1x2 + 0x4 + 1x8 = 1 + 2 + 0 + 8 = 11.
4. The decimal equivalent of 1011 in binary is 11
in decimal.
Therefore, the decimal
equivalent of the binary number 1011 is 11.
To convert a binary number to a
decimal a numerical value to each bit, starting from the right with 1b and
proceeding to the left, doubling the value each time. The values for an 8-bit
number are therefore as follows.
128 64 32 16 8 4 2 1
You then up
the values of your 8-bit binary number with the eight conversion value
1 1 1 0 0 0 0 0
128 64 32 16 8 4 2 1
Final you add together the conversion
valu for the1-bit only
1 1 1 0 0 0 0 0
128 +64 +32 +0 +0 +0 +0 +0 =224
The decimal equivalent to the binary
value 11100000 is 224
Calculating IP addresses Using the
Subtraction Method
The subtraction method is a way of calculating the IP address range given an IP address and a subnet mask. The steps to calculate the IP address range using the subtraction method are as follows:
1- Convert the IP address and subnet mask to binary.
2- Subtract the binary value of the subnet mask from the binary value of the IP address using the bitwise AND operation.
3- Add 1 to the result obtained from step 2 to get the first IP address in the range.
4- Subtract the binary value of the subnet mask from the binary value of all 1's using the bitwise AND operation.
5- Subtract the result obtained from step 4 from the binary value of the IP address and add 1 to get the last IP address in the range.
Let's illustrate the above steps with an example. Suppose we have the IP address 192.168.1.100 and the subnet mask 255.255.255.0. we can convert the IP address and subnet mask to binary as Follows
IP address: 1100000000.10101000.00000001.0100100
Subnet Mask: 11111111.11111111.11111111.00000000
Step 2: Perform a bitwise AND operation between the IP address and the subnet mask.
11000000.10101000.00000001.01100100(IP address) 11111111.11111111.11111111.00000000(Subnet mask)
11000000.10101000.00000001.00000000
Step 3: Add 1 to the result from 2 to get the first IP address in the range.
11000000.10101000.00000001.00000000 +1 = 11000000.10101000.00000001.00000001 =192.168.1.1
Step 4: Perform a bitwise AND operation between the subnet mask and all 1's.
11111111.11111111.11111111.00000000 (subnet mask) 11111111.11111111.11111111.11111111 (All 1's)
11111111.11111111.11111111.00000000
Step 5: Subtract the result from step 4 from the IP address, and add 1 to get the last IP address in the range.
11000000.10101000.00000001.01100100 (IP address) 11111111.11111111.11111111.00000000 (Result from step4)
00000000.00000000.00000000.01100100 + 1=00000000.00000000.00000000.01100101 =192.168.1.254
Therefore, the IP address range for the subnet with IP address 192.168.1.100 and sunet mask 255.255.255.0 is 192.168.1.254.




1 Comments
Very helpful
ReplyDelete