Yes, airlines do have spare planes.
Many airlines have one or two spare planes parked somewhere to prepare for unexpected technical issues. The more flights you have, the more likely there will be one aircraft stuck on the ground. Airlines and aircraft manufacturers call this Dispatch Rate. It is the rate which measures how often a flight is delayed or cancelled due to technical problems of the aircraft.
But wait! A spare plane is incredibly expensive!
Yes, it is. But one also has to take into account the opposite: not having a spare plane.
It is not really a problem if the flight is only partly booked. It is really a problem if it's holiday season - every flight is nearly full, and annoyed passengers hate waiting for any minute longer. You either schedule the delayed passengers to a much later flight, which almost guarantees anger and negatively impacts the airline's image, or you move them to the next flight, then move those in the next flight to the second next flight, causing a cascade delay. Neither is satisfactory.
Not to mention, pilots and flight attendants need to be scheduled as well. There is only a limited time slot which a pilot is legally allowed to fly before the company must relieve the pilot from duty. If the crew is forced to stay, the accommodation cost is paid by the company. The company also has to find another crew to replace them as well. Needless to say, this gets costly very soon.
The larger the fleet size, the cheaper a spare plane
Obviously, if the company only has one aircraft, then the opportunity cost of the wasted spare plane is really high, since the fleet utilization is only 50%. Now, if the company has 100 aircraft, then the chance of at least one of those planes having a technical issue today is higher. If we assume a dispatch rate of 99%, we can expect one aircraft to be stuck on the ground, so we can keep a spare plane, making the total fleet size 101 planes: 100 scheduled planes plus 1 extra plane.
You don't keep one spare plane for every flight. You keep one for the entire fleet.
One advantage of booking with a large airline is that they have spare planes around. If there is a technical delay, the delay is usually shorter, since the airline can easily rotate its aircraft with only minor impact to its schedule. If it is a small airline, say with only 7 planes, and all 7 are dispatched on routes, the company has no choice but to wait until maintenance is completed. For example, SouthWest has ~700 planes; they're all even of the same model. This allows the airline to rotate a flight to a different plane without re-assigning the flight crew and without re-seating everyone in the cabin.
Spare planes usually only exists at the major hub
The major hub is where the airline is based. It is where most of its flight crews are based, and where major maintenance work is carried out. Maintenance tasks are not fixed in duration- some finish early, some late. Therefore, airlines do allow some flexibility in maintenance schedules. This flexibility can be utilized to resolve unexpected delays.
On the contrary, it does not make much sense to station an extra plane at a remote destination. Some destinations may not even be equipped to service that type of aircraft. If a plane breaks down far away, the only choices are to fix it asap, or fly in an empty plane to get the passengers out. These are referred to ferry flights by pilots, and they are not uncommon.