Longest prefix match vs administrative distance (Network+)
A router forwards each packet using the most specific matching route, the one with the longest prefix. Administrative distance only decides which source's route is installed when two sources offer the same prefix, and the metric breaks ties within one protocol. AD never overrides a longer prefix.
Step 1 at forwarding time: longest prefix wins
RFC 1812 describes the Longest Match rule. Of all routes that match the destination, the router keeps only those with the longest prefix. Its example: for 10.144.2.5, with 10.144.2.0/24, 10.144.0.0/16 and 10.0.0.0/8 in the table, only the /24 is kept.
The default route is by definition the route whose prefix length is zero. Any explicit route that covers the destination is therefore more specific and is used instead, whatever its metric.
Step 2 when installing: administrative distance
Cisco defines administrative distance as a value used to rank the trustworthiness of routing information sources. When two sources offer the same prefix, the lower AD is installed. Defaults: connected 0, static 1, EIGRP summary 5, external BGP 20, internal EIGRP 90, OSPF 110, IS-IS 115, RIP 120, external EIGRP 170, internal BGP 200, unknown 255.
A floating static route uses this. Cisco's example sets a static route to AD 250. Because 250 is higher than OSPF's 110, the static route stays out of the table while the OSPF route exists, and takes over if the OSPF route is removed.
Cisco also states that AD and routing metrics are not evaluated during forwarding, so AD does not override longest prefix match. If 192.168.0.0/16 comes from a low-AD source and 192.168.1.0/24 from a higher-AD source, both are installed because the prefixes differ, and a packet to 192.168.1.10 uses the /24.
Step 3 within one protocol: metric
When one protocol offers two routes to the same prefix and length, AD is equal, so the protocol's own metric decides; for OSPF that is the lowest total cost. When different protocols offer the same prefix, AD decides, because their metrics measure different things.
Where the exam catches people
Believing a lower administrative distance beats a longer prefix: AD only chooses between sources for the same prefix; forwarding uses longest match.
Believing a static route always wins over OSPF: a static route set to AD 250 loses to OSPF's 110 and floats as a backup.
Believing the default route can win because its metric is better: its prefix length is zero, so any covering explicit route is preferred.
Believing administrative distance is used while forwarding each packet: Cisco says AD and metrics are not evaluated during forwarding; they only decide what is installed.