Application scalability is an enormous topic and not one that can really be addressed in a single post. However I'll have a crack at a basic explanation.
As you've implied most complex websites are scripts or programs which are executed on a server somewhere and HTML/Javascript (and others) are sent to a browser to interpret and render. Websites like amazon and facebook have millions of unique visitors each day.
To start off with yes, google's servers are no doubt considerably more powerful than your PC at home. However even they are not powerful enough to serve up so many http responses at once.
That's where server farms come in. If ten thousand users want to load the same website then a load balancer splits the traffic onto a number of different servers each of which can run the website.
To make things even more interesting these server farms do not have to all be located in one place, many huge organisations have their physical servers located around the globe allowing them to store and serve content from the one physically closest to the consuming computer (thanks for the suggestion amon).
There are a couple of challenges to overcome, if a user accesses server 462 on their first visit they may not necessarily hit the same server on their next request. Applications can either be designed to accommodate this (by avoiding things like session variables) or the load balancer can be configured to send returning users to the same server for the next page.
If all these servers access the same database under the covers then all the server farm may be doing is shifting the performance bottleneck from the web servers to the database. This is where microservice architecture (building a "website" from many tiny websites) can help as can distributed databases like MongoDB.
Many hosting providers nowadays (azure/AWS for example) prefer you deploy web applications to them rather than creating a website on a VM like you would if your company has it's own hosting. This is to allow them to scale up their infrastructure in demand to requirements - however these scale ups often come with cost implications.
TLDR
Many techniques are employed - load balancing, software architecture, and hosting considerations all play a part in building a robust system.