why can't ip address contain 256 in it ?

This is a discussion on why can't ip address contain 256 in it ? within the Tech Board forums, part of the Community Boards category; i have the basic knowledge as ip adress means it is a made of 4 octets. But i have some ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    112

    why can't ip address contain 256 in it ?

    i have the basic knowledge as ip adress means it is a made of 4 octets.

    But i have some basic doubts like below

    1) why does it cannot have like 192.168.17.256 in it ..?


    2) I have an example here

    If i have a small organization and i want to get some public ips for all my systems from my nearest ISP

    does he give a specific subnet ..? from here i need to calculate and give ips OR

    or he gives a list of ips to use ..?

    what is the general procedure ?

    iam trying to understand the ip addressing and subnet concepts thorougly , if any body can
    give some good tutorial urls it would be great help for me.

    thanks in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Because each of the elements (a.b.c.d where a, b, c and d are elements) is 8 bits, and 256 takes 9 bits to store this value (in 8 bits, 256 is the same as zero, it's like in old cars, when the car has done 100000 miles/kilometers, it says "00000" on the odometer).

    And it's your subnet mask that says how many of the bits in your address are "fixed by the service provider". For example, if you have 255.255.255.192 in the subnet mask, you've got 6 bits that are "private" to your network.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    112

    255.255.255.192 number of networks / hosts in it ?

    In this case i left with 6 bits

    lets think that they gave public ip as 152.167.70.24 and subnet mask as

    255.255.255.192

    so 000000 and 111111 cannot use as it would be used for broadcast address .


    from here how can i go further like number of networks and the number of hosts calculation?

    if iam not wrong the number of host would be like


    000001

    000010

    000011

    .
    .
    .
    .
    .
    111110

    please correct me if iam going wrong ..


    thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, you'd have 2^6 = 64 - 2 addresses in that subnet.

    Of course, you can put a router in at any time and make your own private network, e.g. using 192.168.0.1 with 255.255.255.0 for subnet, which gives you another 254 usable addresses.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    112

    Ip range with the above subnet and IP?

    If we consider our ip as 152.167.70.24 as our ip

    and subnet mask as 255.255.255.192

    then i feel the range of ip we can use is from 152.167.70.1 to 152.167.70.30

    and 152.167.70.0 would be network address and 152.167.70.31 would be broadcast address

    am i right ..?

    total 30 host adress ?

    do we have any formula so that i can just cross check that the number of host addresses i got is correct or not ?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    256-192 = 64, so you have 64 (-2) addresses that are available for your use with the .192 on the end of the subnetmask.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    2,584
    To expand on what matsp said, a .192 netmask would make the valid addresses for that range 152.167.70.0 (network) through 152.167.70.63 (broadcast), leaving 1 through 62 available for your use, but one of them must be a router, unless your service provider handles the routing.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Totally not a Linux thread. Moving to Tech.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,578
    Quote Originally Posted by vlrk View Post
    and 152.167.70.0 would be network address and 152.167.70.31 would be broadcast address
    The base and broadcast addresses are usually the first and last address of a subnetwork. If you need to calculate them for some reason, given some IP and its subnet mask:

    - The broadcast address is found by getting the complement of the mask and ORing with the IP: (~mask) | ip

    - The network address, or network portion- is calculated by simply ANDing the mask with the IP: mask && ip

    EDIT: mind you that there are no broadcast and network addresses for 1 bit network masks, or point-to-point networks. This is the only exception I'm aware to the above rule. Which means it's still possible to connect two computers in network with a 255.255.255.254 mask.
    Last edited by Mario F.; 04-23-2008 at 09:48 AM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    112

    calculating the subnet mask ?

    Of course, you can put a router in at any time and make your own private network, e.g. using 192.168.0.1 with 255.255.255.0 for subnet, which gives you another 254 usable addresses.
    if we take the above case then

    first broadcast address

    ~mask would be 0.0.0.255

    now ~mask | ip will be 192.168.0.255

    now for network address mask && ip is 192.168.0.1

    total from 2 to 254 which are 254 usable addresses


    Now my dobut is if i have ip like 192.168.68.0 and i need calculate the subnetmask in such a way that i can only give ony 10 usable ips any shortcuts
    like above ..?

    thanks
    Last edited by CornedBee; 04-24-2008 at 05:15 AM.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can only partition networks in powers of 2, so 1, 2, 4, 8, 16 etc. If you want to give someone 10 addresses, you actually need to use a netmask of 255.255.255.240, which gives it 16 addresses. You can thus, split 192.168.0.0 network into 16 sections of 16 addresses, giving each group:
    192.168.0.0 .. 192.168.0.15
    192.168.0.16 .. 192.168.0.31
    192.168.0.32 .. 192.168.0.47
    ...
    192.168.0.224 .. 192.168.0.239
    192.168.0.240 .. 192.168.0.255

    Or sevaral different sizes, one section of 16, another of 32, another 64, andother 32, another 16, etc, until you have used up the 256 values available. I won't even try to enumerate the addresses for that combination at 20 to midnight.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    112

    The trick to find out network mask?

    It would depend on the requirement in terms of 2,4, ....

    if you need to give four in a class c ips then 255.255.255.252 would be the subnet mask

    am i right ..?

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes. 252 on the end would give you 4 addresses.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux raw socket programming
    By cnb in forum Networking/Device Communication
    Replies: 17
    Last Post: 11-08-2010, 08:56 AM
  2. What does this do (Windows API)?
    By EVOEx in forum Windows Programming
    Replies: 4
    Last Post: 12-19-2008, 10:48 AM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  4. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 02:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21