It knows this because it knows where it isn't. By subnetting where it is from where it isn't, or where it isn't from where it is (whichever is larger) it obtains a prefix, or mask. The routing subsystem uses these prefixes to generate corrective headers to route the packet from a network where it is, to a network where it isn't, and arriving at a network where it wasn't, it now is. Consequently, the network where it is, is now the network that it wasn't at, and it follows that the network that it was at, is now the network that it isn't.
In the event that the network that it is on is not the network that it wasn't, the router has acquired a metric, the metric being the difference between where the packet is, and where it wasn't. If the metric is considered to be a significant factor, it too may be corrected by the BGP. However, the packet must also know where it was.
The internet packet routing scenario works as follows: Because a router has modified some of the information the packet has obtained, it is not sure just where it is. However, it is sure where it isn't, within reason, and it knows where it was. It now subnets the mask of where it should be, from where it wasn't - or vice versa; and by differentiating this from the shortest path of where it shouldn't be, and where it was, it is able to obtain the destination interface, prefix and its metric, which is called a route.

