The calculated distance (air line) between Saint Andrews and Edinburgh is approximately 31 miles respectively 50 kilometers.
By car or train, the actual journey to Edinburgh is certainly longer, as only the direct route (as the crow flies) between Saint Andrews and Edinburgh has been calculated here.
Air line (approximately)
50 kilometers
27 nautical miles