When your machine sends data, IP wraps it in a packet with a header. The header carries the source address, the destination address, a TTL (time to live) counter, and a few other fields. The data is the payload. If the payload is too big for a link, IP can fragment it into smaller packets, though modern stacks try to avoid that by discovering the largest size a path allows.
The packet hops from router to router. Each router looks only at the destination address, consults its routing table, picks the best next hop, and forwards the packet. It does not know or care about the full path. Every hop decrements the TTL by one; when TTL hits zero the packet is dropped and an ICMP error is sent back. That is exactly the mechanism traceroute exploits to map a route, and it stops packets from looping forever.
Routing tables get filled in by protocols. Inside one company or data center, OSPF or IS-IS spread route information. Between the large networks that make up the internet, BGP (Border Gateway Protocol) advertises which address ranges each network can reach. A BGP misconfiguration is how, in 2008, Pakistan Telecom accidentally took YouTube offline worldwide for a couple of hours by announcing it owned YouTube's address block.