The direct train from the outskirts of Cusco (Poroy station, service available from May to December) takes approximately 3 hours and a half to Machu Picchu Pueblo.
If you take the train at the Ollantaytambo station (two hours by road from Cusco), it will take you an hour and a half to get to Aguas Calientes.