0

A subnet mask defines how an IPv4 address is broken up. IPv4 addresses nnn.nnn.nnn.nnn aren't like MAC addresses in that they are just random numbers. That defeats the purpose of Routing. They have two parts: Network ID and Host ID. Network ID shows which subnet the device is on. The Host ID shows which specific device on the subnet it is.

However, with 4 different octets, there are different ways of breaking the address up into two fields. This gave us Class A, B, C. These only had full octets dedicated to the Node ID or Network ID, so classless masks came into play. This is the 192.24.50.1/24 notation. I understand this part (unless I made a mistake above without knowing.)


How do routers use this to make decisions?

The process that takes place is deciding between two options for a device:

Is the destination that I want to get to on the same subnet as me?

  • If so, then send direct transmission in the form of a frame, with the destination address in the Ethernet/802.11/etc. frame being the MAC address of that host. If its not known, then ARP will be performed in order to obtain it. "Hey, who's IP address is 192.59.1.2, and whats your MAC address?

  • If not, that means we have to route it to another subnet. Its in a different "neighborhood." This is the job of routers, thus, we send the transmission to the default gateway to make the routing decision. Then we ask the question again afterwards, and so on.


How do routers specifically use subnets and IP addresses?

As stated before, in order to see if the destination is on the same subnet as its own, it has to compare the IP addresses. However, it only compares the Network ID part. That's all that matters for the comparison. "Is the destination in my neighborhood?" So it compares the Network IDs of both to make that decision.

The way the Network ID is obtained is basic binary logic by "applying" the subnet mask to both IP addresses.

For example, 120.50.2.1 with a 255.255.255.0 subnet mask gives us 120.50.2.0. It essentially, takes away the Host ID because that part is useless for the comparison.


HERE IS WHERE I AM CONFUSED

How do devices transmit to other devices that use different subnet masks?

When making the routing decision, only three pieces of information are needed. The current device IP, the destination IP, and the current device's subnet mask. (the destination subnet mask isn't used)

But what if you have a device with class A subnet mask sending to a device with class C subnet mask?

Source IP 122.10.21.5 Using Class A Mask

  • 122 is the Network Number
  • 10.21.5 is the Network Node

Destination IP: 122.10.2.4 Using Class C Mask

  • 122.10.2 is the Network Number
  • 4 is the Network Node

So the source device applies the subnet mask to its own and to the destination device to see if they are on same subnet.

Source: 122.10.21.5 + 255.0.0.0 = 122.0.0.0

Destination: 122.10.2.4 + 255.0.0.0 = 122.0.0.0

This tells us they are on the same subnet. But they aren't! The source is on the subnet identified as 122, while the destination is on subnet that identifies as 122.10.2!

If the subnet mask of the destination was applied to the desination rather than using the source, then this is fixed.

Source: 122.10.21.5 + 255.0.0.0 = 122.0.0.0

Destination: 122.10.2.4 + 255.255.255.0 = 122.10.2.0

  • 1
    IPv4 addresses nnn.nnn.nnn.nnn aren't like MAC addresses in that they are just random numbers - MAC addresses aren't just random numbers. – joeqwerty Nov 15 '17 at 0:12
  • 1
    You’ve done a good job explaining yourself, and everything is correct. Even the last part you mentioned. So I ask you this, what makes you think that the Router on the class A subnet will deliver packets to the Class C network? It won’t. The Class A Router sees the IP address on it’s directly connected network and at best would send it back out on the same wire it came in on. That Class A network is “owned” by that router. It’s not possible for another network to have that address too. – Appleoddity Nov 15 '17 at 0:17
  • @appleoddity So in this Source: 122.10.21.5 + 255.0.0.0 = 122.0.0.0 Destination: 122.10.2.4 + 255.0.0.0 = 122.0.0.0 are you saying that the destination IP can't exist even with a class C subnet mask? or are you saying that the sourse just can't reach it? if so, then how? – Jordan Farris Nov 15 '17 at 5:43
  • 1
    Yes in your example the source cannot reach the destination. The source computer has been told it's part of the 122.0.0.0/8 network and so it thinks every host with an IP in that range is locally accessible. This would be a error by the person who designed the network if that's not what is desired. – USD Matt Nov 15 '17 at 12:39
0

First: IP classes have been removed 20+ years ago, so forget about them. I'm going to use CIDR notation.

Overlapping subnets are not allowed. You can't have a /24 subnet in the same space that is also used for a /8 subnet. In other words: each IP address can only be part of one network with one subnet mask.

  • So doesn't this reduce the number of available IP addresses drastically? – Jordan Farris Nov 15 '17 at 20:06
  • Every IP address identifies an endpoint, and can only be used once. – Sander Steffann Nov 15 '17 at 23:09
0

In routing, the source IP address isn't used for anything, it's just transmitted along.

The destination IP address is matched to the routing table entries using the respective entry's mask: if (dest.IP && entry[n].mask) == entry[n].address then forward to entry[n].gateway is iterated over all routes from longest to shortest mask, first hit is the gateway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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