There are a bunch of standard highway types, and they have various routing scores (a fast road scores better than a slow road, for example). Junctions have a similar set of scores.
The software calculates routes to get the best score given its conditions (eg: yes to cycleways, no to footpaths); the highway types are manipulable in OSM because you can make any data tag mean anything in Garmin format.
It's witchcraft!