There are two ways of getting to Machu Picchu.
The first one is the traditional train trip which lasts between
3h 40min and 4 hours depending on the type of train, and the second
is the Inca Trail, ideal for those who love trekking. The latter
requires a major effort and takes 2, 4 or 5 days.
Inca Trail:

If you love adventure sports and enjoy long walks, contact with
nature and beautiful landscapes, an alternative for you to get to
the spectacular citadel of Machu Picchu will definitely
be walking along the old Inca trail which leads to Machu Picchu.
Although there are longer and shorter options, the average trip takes four days and three nights. Most of the trip is done 2,000 m above sea level, but you will have to cross three clearings at over 4,000 m above sea level. Therefore, it will be necessary for you to spend a whole day in a high place in order to become acclimatized.
The Inca trail to
Machu Picchu is known as the
most famous trekking route in South America due to the different
things it offers visitors. It begins at Km. 88 of the railway to
Valle de la Convencion (Convention Valley), in a place called Q'oriwayrachina,
39.6 Km from the sanctuary.