The main part of Spain borders 4 other countries:
Spain also has some territory in Africa that borders Morocco.
All countries share borders, although these may not always be land borders. Australia, for example, shares no land borders with any other country, but it does have maritime borders with other countries.
The USA shares land borders with Canada to the north and Mexico to the south.
They have no land borders, but Australia shares maritime borders with Indonesia, Papua New Guinea and New Zealand.
Canada and Mexico share land border with the US.
Did Spain control land that borders the Pacific Ocean?
Canada to the north and Mexico to the south share land borders with the United States.
Singapore does not have any land borders but it is linked to Malaysia by the Causeway and the Second Link.
Hawaii, being made out of islands, has no land borders.
The Philippines does not share any land borders with other countries. It is surrounded by the sea and shares maritime borders with countries such as Taiwan to the north, Indonesia to the south, and Malaysia to the southwest.
Some island countries have no land borders with other countries, such as Australia, Iceland, and Cuba. They may still have sea borders, areas of coastal waters that they claim.
Spain shares borders with France, Portugal, Andorra, Morocco, and the UK. Pick any other country and it will not share a border with Spain.
Just south, across the Mediterranean Sea, is Morocco, and to the southeast is Algeria and Tunisia. (The UK territory of Gibraltar is at the southern tip of Spain.)