There are two main options of where to stay on your way to visit the Lost City of the Incas: Aguas Calientes and Cusco.
The easiest and quickest way to get from Cusco to Machu Picchu is to buy a roundtrip train ticket with PeruRail or IncaRail to Aguas Calientes, the town located a few miles from Machu Picchu itself. The ride to Aguas Calientes is a scenic 3.5-hour trip, and the entire trip to and from Machu Picchu can be done in one day. If you are very short on time with your Peru trip, then staying in Cusco and taking this route is your best option.
If you have time to spare, are ready for a physical challenge, and want to see beautiful landscapes of Peru – a multi-day trek is your best option. If you choose to do the Inca Trail hike, Salkantay Trek or any of the other multi-day tours to Machu Picchu, you’ll definitely want to spend the night in Aguascalientes, and it will most likely be included in your trek package anyway. The majority of the guided trek packages spend most nights camping along the trails and one night at a hotel in Aguascalientes. If you choose this option during your visit to Machu Picchu then you’ll also spend at least a couple nights in Cusco, before heading out on the trek and once you get back.
So if you trek your way to Machu Picchu then you will end up staying in Aguas Calientes at least one night, and whether you take the train or the trek, you’ll definitely stay in Cusco at least one night. Consider extending that stay as Cusco has its own nightspots, bars and restaurants to explore, and staying in this special town just as a pitstop to Machu Picchu would be a mistake.