Bus is the most practical and efficient transport to go from Belgrade to Sarajevo. Trains between both cities haven't been working since 2013, if I'm not wrong. By bus, it takes about 8 hours of trip. You can take a bus from the Bus Station in Belgrade, that arrives in Ist Sarajevo, the Serbian side of the city.
From Ist Sarajevo, you can take a trolleybus to the city center. Other option you have is to take transportations leaving Belgrade directly to the city center of Sarajevo. The hostels know about the timetables and have contacts of drivers who make these trips.
