In brief, a routing table contains network addresses and their next hop.
A router uses a packet's destination IP and uses the routing entry that most closely matches that IP.
For example, if a routing table had:
10.0.0.0 /8
10.1.0.0 /16
10.1.2.0 /24
for an IP of 10.1.2.3 it would use the 3rd entry.
for an IP of 10.1.9.3 it would use the 2nd entry.
for an IP of 10.9.2.3 it would use the 1st entry.