If all hosts were directly reachable through the local network we could, using ARP, locate other hosts on the network and send data to them.
The problem is: how do you reach hosts that are not on the same physical network (link) as you, and what do you do to reach them ?
Another question: how do you know that the host isn't on the local network ?
The answer is: compare the address/netmask of the source address with the address of the destination.
The rule is that for other hosts to be considered directly reachable is:
The IP address of the destination must be within the range defined by the local network number and netmask.
Example 1
Source: 192.168.1.10, netmask is /24 (or 255.255.255.0) Dest : 192.168.1.50
The netmask, /24, indicates that the network part of the source address is 24 bits, or 3 bytes wide. Therefore, the network number here is:
192.168.1.0
And the range of the network is:
192.168.1.0 - 192.168.1.255
The destination host's address, .50, is withing the range and can therefore be reached directly via a local link.
Example 2
Now consider the following:
Source: 192.168.1.35, netmask is /28 (or 255.255.255.240) Dest : 192.168.1.75
The netmask, /28, indicates that the network number of the source address is:
192.168.1.32
With a range of:
192.168.1.32 - 192.168.1.47 (14 hosts)
As we can see, the address 192.168.1.75 is NOT included in the range, therefore it is not directly reachable.
Example 3
Yet another case:
Source: 192.168.1.10, netmask is /16 (or 255.255.255.240) Dest : 192.168.2.30
The network associated with the source address/netmask is:
192.168.0.0
With a range of:
192.168.0.0 - 192.168.255.255 (65534 hosts)
Address 192.168.2.30 is contained within the range, and directly reachable.
Example 4
Source: 10.2.15.4, netmask is /8 (or 255.0.0.0) Dest : 192.168.2.30
Range:
10.0.0.0 - 10.255.255.255 (16777214 hosts)
Address is 192.168.2.30 is not contained, and not directly reachable.