Take the 2-minute tour ×
Network Engineering Stack Exchange is a question and answer site for network engineers. It's 100% free, no registration required.

First some background information on what I already know:

An IPv4 address is a 32 bit address that identifies a node in a network. An IP address will have an IP prefix which determines the "Network" part of the IP address and the rest will determine the "Host".

An example:

128.208.0.0/24 will tell me that the first 24 bits is the "Network" part of the IP address, and the remaining 8 bits will be for the host in the given Network. Also, 128.208.0.0. will be the lowest IP address that is available in the given network..

Now Tannenbaum states in his book:

Since the prefix length cannot be inferred from the IP address alone, routing protocols must carry the prefixes to routers. Sometimes prefixes are simply de- scribed by their length, as in a ‘‘/16’’ which is pronounced ‘‘slash 16.’’ The length of the prefix corresponds to a binary mask of 1s in the network portion. When written out this way, it is called a subnet mask. It can be ANDed with the IP ad- dress to extract only the network portion. For our example, the subnet mask is 255.255.255.0.

So my questions are:

1) How do routing protocols carry the prefixes? Where is the "slash" part stored?

2) What does this mean at all:

It can be ANDed with the IP address to extract only the network portion. For our example, the subnet mask is 255.255.255.0.

Thanks.

share|improve this question
    
Can the downvoter please clarify why this question is downvoted? –  Koray Tugay Feb 19 at 14:28
    
I suspect the community is expressing some down voting because your question is introductory-level, and this site is aimed at professionals. On the upside though, people are not close-voting you. –  Craig Constantine Feb 19 at 16:27
    
Sorry, English is not my native language. What does this mean: "On the upside though, people are close-voting you." –  Koray Tugay Feb 19 at 17:50
    
I meant to say: people are not voting to close your question. So some people don't like it (down voters), but it's not so bad that people are voting to close it. –  Craig Constantine Feb 19 at 18:15
    
@CraigConstantine Got it thanks.. Yes you are right.. –  Koray Tugay Feb 19 at 19:54
add comment

2 Answers

up vote 5 down vote accepted
  1. How do routing protocols carry the prefixes? Where is the "slash" part stored?

I'll answer this as direct as possible with OSPF. Below is a Type 1 Hello packet sent out all interfaces to form an adjacency.

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   Version #   |       1       |         Packet length         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                          Router ID                            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                           Area ID                             |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |           Checksum            |             AuType            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                       Authentication                          |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                       Authentication                          |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                        Network Mask                           |    <------
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |         HelloInterval         |    Options    |    Rtr Pri    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                     RouterDeadInterval                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                      Designated Router                        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                   Backup Designated Router                    |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                          Neighbor                             |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                              ...                              |

RFC 2328, A.3.2 The Hello packet

The Network Mask field is populated with the subnet mask you're using with that interface.

CIDR Notation is nothing more than a shorter version of your subnet mask for the sake of brevity. And for that matter, subnet masks are just a condensed version of bit positions. Imagine having to write in decimal every time you wanted to configure a port.

11111111.11111111.11111111.00000000    <---- This would be painstaking
255.255.255.0                          <---- Better, but not optimal
0xffffff00                             <---- Shorter still, but still not optimal
/24                                    <---- Best-case scenario

Everything comes out to the same thing in the end. So having these shorthand ways of representing the same data just makes sense.

share|improve this answer
    
The whole network mask is sent? Wouldn't it be more efficient to use 5 bits(only 1 to 31 is needed) indicating how many bits are network? Is there really any advantage to being able to define a 255.0.255.0 mask? –  Cruncher Feb 19 at 16:54
    
@Cruncher 255.0.255.0 isn't a possibility. Only wildcard masks can work with discontiguous bits like this. The RFC doesn't outline why it sends the entire network mask with the OSPF packets. –  Fizzle Feb 19 at 18:01
    
Is this a DHCP packet? –  Koray Tugay Feb 19 at 19:54
    
No, the example above is an OSPF Type 1 Hello packet. –  Fizzle Feb 19 at 20:05
    
@Cruncher wild card mask are only used for access-list and NATing, it is practically an inverted subnet mask. –  chris Feb 20 at 12:15
show 2 more comments

It depends on the routing protocol. Old protocols like RIP v1 assume a classful mask and do not advertise a mask, but newer ones like RIP v2, OSPF, ISIS, BGP, etc do.

The answer to the second part of your question: To determine the network part of the address, or to test if a given address is part of a particular network, you perform a bitwise logical AND with the subnet mask.

For example, to get the network address of 172.16.24.5/24, you AND each bit of the 32 bit address and the Mask, like this:

10101100 00010000 00011000 00000101 <- 172.16.24.5

11111111 11111111 11111111 00000000 <- 255.255.255.0


10101100 00010000 00011000 00000000 <- Result: 172.16.24.0

The result is the network portion of the IP address (also called the network number). This is exactly what your router and PC do to determine which network to use to transmit the packet.

share|improve this answer
    
Thanks for the answer but what is so special about 255.255.255.0 ? –  Koray Tugay Feb 19 at 14:29
1  
Nothing really, other than because the division between the network and host mask fall on the "dot" boundary, it is easy to use (the last decimal digit is always 0). So it is very commonly used. –  Ron Feb 19 at 14:34
    
Does it assume the IP has a 24 bit prefix? –  Koray Tugay Feb 19 at 14:42
    
What I do not understand is, you have given an example: 172.16.24.5/24 and you already know the prefix length. But how does the Router know the prefix? If it does not know the prefix, how will it know it should use 255.255.255.0 ? –  Koray Tugay Feb 19 at 14:48
    
The router advertisements for each route carry the prefix (for modern protocols). –  Ron Feb 19 at 15:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.