In the case where the other end is outside your local network, your PC doesn't need to know the subnetting arrangements at the other end it just needs to know enough to deliver the packets to the nearest router. For that it uses two pieces of info.
- local subnet mask
it uses this in conjunction with it's own IP address to see if the other
IP-address is local or not.
- default gateway (or explicit routes - see
anything non-local gets sent there
The router at the other end (i.e. with an interface in the other LAN) knows about subnet arrangements there. Nothing else needs to.
If you look at
netstat -nr you'll see your PC's routing table consists of destination-network, network-mask (the other side of subnet-mask) and gateway (router). Usually PCs have a single default gateway plus some kibble for things you don't use much (loopback, multicast etc).
You can think of the network masks in routing tables as equivalent to a high level summary or aggregation of millions of target subnets.