How this works:
Two IP addresses are on the same subnet if a binary OR of the subnet mask with each of the IP addresses gives the same result. This means that the lowest IP address on a subnet is the mask ORed with the IP address, the highest is the lowest address ORed with the inverse of the mask. That should now be as clear as mud.