Machu Picchu doesn't sell tickets the way most landmarks do. Entry is capped, timed, and split into circuits, and the allocation for peak season (June through August) can be gone eight to ten weeks out. Showing up in Aguas Calientes and assuming you'll sort it out locally is the single most common way people miss it entirely.
Tickets are sold through Peru's official Ministry of Culture portal, and this is the part that trips people up: the site is not always in English, it does not always accept foreign cards smoothly, and inventory is released and adjusted in ways that aren't clearly communicated. None of that means it's impossible — it means you shouldn't leave it until the week before.
Why tickets disappear months out
Daily entries are capped by circuit, and certain circuits (particularly ones that include Huayna Picchu or Machu Picchu Mountain) have far smaller quotas than the base entry ticket. Tour operators and larger agencies also reserve blocks of tickets well in advance, which shrinks the public allocation faster than the raw visitor numbers would suggest.
What actually worked
Booking the base circuit (not one of the mountain hikes) roughly two to three months ahead consistently found availability, even in high season. The mountain-hike circuits needed to be locked in closer to four months out. And the earliest entry slot of the day — while it means a very early start from Aguas Calientes — had noticeably more availability than midday slots, likely because most travelers default to booking mid-morning.