As I understand it, routers route packets to a specific network based on network id and of course the network id must be unique on the Internet, now the question is: maybe there are billions of networks in the world, or even more how to assign a unique network id to each of them?
A routing decision is based on the routing table which consists of entries with network prefix, interface, and next-hop gateway each.
Each router only forwards to a next-hop router and doesn't need to know more than that. Only routers with full peering require a complete routing table.
In the most basic case, there's a single, default gateway where anything that isn't local is routed.
In the most complex case, a router holds the Internet's entire, global routing table with many hundred thousand entries. Since each network requires just one entry, we've got much fewer entries than possible addresses.
User allocations with a single or just a few addresses are generally handled by the ISP and presented in summary only. Additionally, a large, private network may be hidden from public routing behind a single, public IP address.
For IPv4, only networks with a /24 prefix or larger can be globally advertised, so the theoretic maximum is 2^24 ~ 16 million prefixes (minus reserved ranges).
For IPv6, the number of prefixes is much larger (potentially 2^48), but (hopefully) the address allocation happens in a more organized fashion from lessons learned.