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
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.