Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 03-27-2007, 04:00 PM   #1
Registered: Mar 2007
Distribution: FD4,6
Posts: 52

Rep: Reputation: 15
question about IP address and subnet mask

I have a question about IP address and subnet mask.

My understanding is each IP address has netid part and hostid part. The netid part is used for routing efficiently.

For example: an IP address with a netmask, (ie /24 ) has a subnet number of, and there can be 2^8-2 = 254 hosts in this system.

But, for the same IP address, if I want to divide the 254 hosts into 8 subnets, what should I do? Change the subnet mask? How do I know they are in different subnets?

Furthermore, I read in a book said:
“When you divide a class C address into eight subnets, you get a subnet mask of (27 1s). The eight resultant network are,,,,,,, and”

I understand 224 is 27 1s. But I don’t know where 224 comes from. Also, I thought hosts in a subnet has a range of IP address. For exmaple, are in the first subnet. But how can the routers between the subnets know?

I’m really confused with these concepts. Please advise.
Old 03-27-2007, 04:17 PM   #2
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 653

Rep: Reputation: 32
8 subnets, so sections of 32 each 2*2*2*2*2 or 2^5 -> 32-5 = 27

OR alternatively 256(total addresses)-32(desired addresses) = 224
That said if you want 15 addresses you can't go 256-15 = 241 ->

Or if you have a CIDR table handy

CIDR Dec Netmask Hex Netmask No of IP addresses
/27 0xFFFFFFE0 32

so your networks are: which is the exact same as *

* well not exactly the same - hosts.allow understands the long form, but not the short form. On that note, don't specify individual IPs in your hosts.allow (or deny) as cause that will be ignored/not matched.

Each of those CIDR notations are a range, not a single address. Or they are a network address block, which is a range. The routers between the subnet can know by a number of means: Vlans are one popular mean though i'm not sure what deeper explanation you might need there.

in a Vlan setup your system tags each packet so the router knows that the source is part of a vlan, and based on this can route it. Unless you have a complex setup though, vlans might not be the way to go. If you use a firewall you can restrict access of your network blocks to each other in the router and not bring vlan's into it. Vlans offer enhanced security (as potential targets are not part of the Vlan so they won't respond to the packets as said target knows to ignore them), but this can be subverted by the router due to making a port tagged or untagged. but again, this gets complex and unless you need to know there is little point in telling you, and i'm sure wikipedia will do a better job.

Last edited by chakkerz; 03-27-2007 at 04:19 PM.
Old 03-27-2007, 05:03 PM   #3
Registered: Mar 2007
Distribution: FD4,6
Posts: 52

Original Poster
Rep: Reputation: 15
so for 254 hosts divided into 8 subnets, it is 32 hosts on each subnet, that is 5 bits for hostid. Is this how you get the first 32?
Old 03-28-2007, 07:36 AM   #4
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 653

Rep: Reputation: 32
well CIDR is based on 2 to the power of 32 = 4294967296
this is the same as 256*256*256*256 ... each section of the netmask can be 0 - 255 (or 0x00 to 0xFF) in other words 256 values, so total potential number of IP addresses is that long number with 4 at the start.

CIDR does not care about the number of hosts, in fact it completely ignores that aspect of it. It can be used to denote a range of IPs which are all hosts (say in a firewall) or a subsection of a network. In the case of the network subset, it may or may not include all sorts of non host usable IPs such as Base IP, Gateway, Broadcast, HSRP interfaces, Router Management IP etc.

so really you have not 254 hosts but 256 IPs. 256 / 32 = 8. Or 8 equal sized network segments out of 256 potential IP addresses gives 32.

CIDR uses a starting point of /32 meaning one IP address only, each step towards 0 means double the IPs, so /31 is 2; /30 is 4; /29 is 8; /28 is 16; and /27 is 32.

An easier way to derive this, rather than counting backwards, is to take the 32 (number of IPs) and work out 2 to the power of what = 32. (2^x=32) so the value in question (x) is 5. To then work out what you CIDR mask for this would be is 32 (base CIDR value of one IP) and reduce that by x -> 27 so /27 (CIDR) gives 32 IP addresses.

So in other words, if you are doing your network split instead of 254 host usable IP address; you end up with 240 host usable IP addresses only.

oh, and one other things, say we have - that would mean; but depending on the place you use it, it may mean something else; for instance most routers will interpret that as meaning you want the /27 block of the address range, which will contain .16 and interpret that as instead;

If you used this in a firewall on the other hand, it might be legal and mean 16-48 instead (i'm really not sure, i've not come across that, but firewalls generally interpret it as a range, and don't give the bounds special meaning as a router would). To be safe that this is interpreted as the range, you'd probably have a group of and which would not confuse a firewall, but would mean something completely different to a router.

I realize that this is all a bit confusing and probably more info than you wanted, but just know it's based on Y = 2 to the power of X; and then 32 - X is the notation that gives you Y addresses. As long as you know X or Y you'll be fine.

Last edited by chakkerz; 03-28-2007 at 07:39 AM.
Old 03-28-2007, 11:00 AM   #5
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
.. This stuff always ends up making my head hurt!

2007fld: There's a good tutorial here:



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Subnet Mask with 1 IP. Ionized Linux - Networking 25 06-10-2007 12:20 AM
Subnet Mask jomyjose Linux - Networking 2 08-01-2006 09:19 AM
subnet mask kizersouzay Linux - Networking 1 08-31-2005 03:07 PM
Setting IP Address and Subnet Mask and whatnot... Sloanr333 Linux - Networking 6 11-06-2003 11:39 PM
Subnet mask mikeshn Linux - Networking 1 08-26-2002 01:19 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration