Spain was a province of Rome. After the fall of Rome it was a group of independent kingdoms/principalities. The Moors invaded Spain in 711 and eventually ruled most of it until the last Moors were defeated in 1492. At that point Spain was controlled under the power of Isabel and Ferdinand and took the form we know today.