What's in a routing table entry
Every entry describes: a destination network (as an address and prefix, like 10.0.2.0/24), the next-hop address to forward toward, the outgoing interface, and a metric/administrative distance (covered in the next topic) used to break ties between competing sources of routes.
When more than one entry matches
Routing tables are built with prefixes of different lengths, and a single destination IP (Internet Protocol) address can legitimately match several entries at once: a broad 10.0.0.0/16 entry and a more specific 10.0.2.0/24 entry could both technically cover the same address. The router always picks the entry with the longest matching prefix, meaning the most specific one, regardless of which entry appears first in the table or which one has a "better" metric.
This is exactly how postal sorting works: a rule for "Springfield, Illinois" is more specific than a rule for "the state of Illinois," and a sorter routes mail using whichever rule matches most precisely, not whichever rule was written first.
The default route
A 0.0.0.0/0 entry, the default route (sometimes called the "route of last resort"), matches literally every address with the least specificity possible: a prefix length of zero. It only gets used when nothing more specific matches anything at all, which is exactly what makes it the right entry for "everywhere else on the internet I don't have an explicit route for."
Longest prefix match is evaluated first, before administrative distance or metric ever come into play. Those only break ties between multiple routes to the exact same prefix. They never override a more specific match. That distinction is the whole subject of the next topic.