PDA

View Full Version : How does subnet mask works?


drag034043
Dec 31, 2010, 08:05 AM
(I'm talking about IPv4. And this is not a school exercise... I take this example because I need to understand the point)
Hello.
(
Sorry for my poor english. If something in the following example is not clear what I want to understand is: HOW TO TRANSLATE AN ADDRESS WITH AN EQUIVALENT ONE (and related broadcast and network address) AFTER APPLYING SUBNET MASK
)
What I already know is: subnet mask is build of how many 1s as the network address is (example: 16 bit for class B) + as many 1s as many the bits of subnet identifier are
In particular (this is a example): 150.1.0.0 with subnet mask = 255.255.240.0 (240 = 1111000) then 14 subnets (16 subnets but 0000 and 1111 are reserved for network address and broadcast address) and 4094 host (2^12 bit of remainder = 4096 - 2 bits for network and broadcast address).
And up there... all fine..
The example follow con this information... but I can't understand it.. (already tried IP address AND subnet mask (logical operation) but I can't get to the point... ):
Subnets: from 150.1.16.0 to 150.1.32.0 [Tthird byte: from 00010000 to 00100000.. it is clear to me that 10000 = 16 and 100000 = 32 but not the link with subnet mask and network address witout applying the subnet mask)
Broadcast address: from 150.1.31.255 to 150.1.47.255 [Third byte: from 00011111 to 00101111.. is clear to me that 11111 = 31 and 101111 = 47 and 255 = 11111111 for broadcast address but not the link with subnet mask and network address witout applying the subnet mask]
Addresses pool: from 150.1.16.1 to 150.1.31.254 and from 150.1.32.1 to 150.1.47.254 [and this a logical consequence of the previous calculus]

Thanks

cajalat
Dec 31, 2010, 07:52 PM
Sounds like you're getting a couple of things mixed up which might explain why this is confusing. Let's look at your first example where your assumptions were not correct:

Network: 150.1.0.0/255.255.240.0. The Network and Broadcasts are at the beginning and end of the subnet and do not fall on octet boundaries. So in this case the network we're talking about is this:

First IP is the Subnet ID: 150.1.0.0
Last IP is the Broadcast Address: 150.1.15.255

Everything in the middle is a usable/assignable IP address to hosts:

150.1.0.1 - 150.1.15.254

As long as the hosts have a 255.255.240 subnet mask then the following IP's are all valid for hosts: 150.1.0.255, 150.1.2.0, 150.1.2.255, 150.1.3.0, and so on. Those aren't reserved for Subnet ID's or Broadcasts because the Mask of 255.255.240 tells you that they are in the middle of the Subnet identified above.

In terms of the various boundaries you can get with a 255.255.240 mask for the 150.1.x.x example you get 16 (not 14). The subnets themselves are not unusable. Only the first/last IP's within the subnet are what can't be used for host assignments. So you get the following:


150.1.0.0/255.255.240.0:
150.1.16.0/255.255.240.0
150.1.32.0/255.255.240.0
150.1.48.0/255.255.240.0
150.1.64.0/255.255.240.0
150.1.80.0/255.255.240.0
150.1.96.0/255.255.240.0
150.1.112.0/255.255.240.0
150.1.128.0/255.255.240.0
150.1.144.0/255.255.240.0
150.1.160.0/255.255.240.0
150.1.176.0/255.255.240.0
150.1.192.0/255.255.240.0
150.1.208.0/255.255.240.0
150.1.224.0/255.255.240.0
150.1.240.0/255.255.240.0


Again, the first/last IP's within each subnet above is the Network ID and Broadcast Address. What is in between is all usable for hosts (each has 4094 assignable IP).

To break this down in terms of bits for an IPv4 (32 bits) you get this:

150.1.0.0/255.255.240.0:


_____150 . _______1 . _______0 . _______0 Subnet
10010110 . 00000001 . 00000000 . 00000000

_____255 . _____255 . _____240 . _______0 Mask
11111111 . 11111111 . 11110000 . 00000000
nnnnnnnn . nnnnnnnn . nnnnhhhh . hhhhhhhh



So looking at the 3rd octet only you have the following


nnnnhhhh


Your n's are these:


0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111


When you add the h's you get 4 zero's in front of the above as follows:


0000 0000 = 0
0001 0000 = 16
0010 0000 = 32
0011 0000 = 48
0100 0000 = 64
0101 0000 = 80
0110 0000 = 96
0111 0000 = 112
1000 0000 = 128
1001 0000 = 144
1010 0000 = 160
1011 0000 = 176
1100 0000 = 192
1101 0000 = 208
1110 0000 = 224
1111 0000 = 240


So anything in the h's will be assigned to hosts within that subnet and anything in the n's will be a different subnet.

Does that help?