They keep their regional and local warehouses stocked with the items. Using algorithms (math type stuff) they can fairly accurately guesstimate the stock needed at each of their regional/local distribution centers to meet those orders.
They also give a discount/perk to Prime members who elect to NOT get their items one/two day or recently they have gone to a “Prime Day” where they deliver any orders in the same day. This allows them to be able to more accurately predict shipping and stocking/inventory needs and plan for them.
Amazon has a lot of warehouses across the country, and many popular items are stocked at many of those warehouses. Because of this, many orders can be fufilled by a location somewhat close to your address, and thus don’t have to stay in ground transportation for days.
For prime members, Amazon will sometimes use air cargo services to get a item close to your location.
While there is a lot of logistics that go into actually physically moving the item to you the short explanation is they have ton of different facilities spread around major metropolitan areas with a huge amount of stock ready to go in addition to a massive number of trucks, and delivery personal ferrying packages every conceivable direction. This means when you want to buy an item from Amazon.com there are hundreds of possible places that specific item could potentially come from. When you are signed in and tell it where you want to ship an item to their computer system looks at where the nearest warehouse that has that item is and gets it on the way to your door pretty much immediately.
You will note things like same day and 1-2 day shipping are only available on certain items and if you tried to ship that same item to another address (particularly one in a more rural area) it may not be available for same/next day delivery.
Think about it this way. If you were to look for that item on a major brick and mortar store website (Walmart, Target, etc) and they said they had one on a shelf at a store an hour away, or even a few hours away, if you really wanted that item you could drive there and get it today. Essentially the same thing applies to getting an item from Amazon, although it will require a few more steps inside their fulfillment center. As long as there is one available reasonably nearby all that has to be done is find the item and get it on a truck headed your way. To do this they just need to have the order placed before a certain time (which is why before placing the order you will often see a timer that says “get it tommorow if you order in the next X minutes”)
Source: Amazon employee