It depends almost entirely on whether you stay airside. Many countries let passengers remain in the international transit area without a visa, provided you hold an onward ticket and never pass through immigration. But the moment you must collect bags, re-check them, cross a public area between terminals, or switch airports, you are technically entering the country and normal visa rules apply.
Some countries are stricter and require a transit visa even for airside connections from certain nationalities; others waive requirements entirely for short connections. A few airports have no sterile transit area at all, so every passenger clears immigration regardless of intent.
Before booking, check three things: whether your nationality needs a transit visa for that specific country, whether your connection forces you landside, and whether your bags are checked through. The airline can confirm baggage handling, while the transit country's embassy or immigration site confirms the visa side. A short layover is not protection in itself; the requirement is about status, not duration.