Chiang Mai has three bus terminals. Terminal 1 is only for local routes, so you probably won’t need to use that one. Bus Terminal 2 is also known as the Arcade Bus Station, and right next to it is Bus Terminal 3, also called Wat Ket Bus Station. If you’re arriving from or departing to Bangkok, that will be at Bus Terminal 3. Buses and vans to and from Pai arrive and depart at Bus Terminal 2, the Arcade Bus Station.
Chiang Mai’s train station is located a few kilometers south of the bus terminals.
A taxi or songthaew to Arcade, Wat Ket, or the train station usually costs around 150 THB. Try booking a Bolt or Grab ride to get there cheaper. The reverse trip — from Arcade, Wat Ket, or the train station back to the city — is often a bit cheaper: you can hop on the back of a songthaew or book a Grab/Bolt taxi.
If you book a night train or night bus, you might arrive very early in the morning. There are generally always taxis and songthaews available at those hours, even in the middle of the night. However, when booking your accommodation, keep in mind whether you can check in that early.