The Japan Railways Keihin-Tohoku line takes about 40 minutes from Tokyo to Sakuragi-cho Station in Yokohama; the faster shinkansen leaves you off at Shin-Yokohama, on the outskirts of the city.
The train takes 5 hours to go from Yokohama to Tokyo.