WiFi is almost universally available at hotels, as well as in some cafes, restaurants and airports; usually (but not always) it’s free. Connection speed often varies from room to room in hotels (and coverage is sometimes restricted to the hotel lobby), so always ask when you check in or make your reservation if you need a good connection. Some tourist offices may have a list of WiFi hot spots in their area.
Another option for accessing the internet is MiFi, is a popular new invention for Spain travelers. You’d have to purchase it after you’ve arrived, and the SIM inserted connects you to a local cellular operator. Included in your purchase is a battery and cord for charging the small device that you carry around with you, and the battery should be turned off if you are out all day and turned on only for charging purposes. The WiFi provided with this service has many reviews of being helpful, and many poor reviews of being a hassle. Keep in mind that it's only usable in Spain.
If you choose not to use any of the fancy gadgets, you can stick to letting your mobile provider know that you are traveling abroad, and they can set up a plan accordingly. Some roaming charges are only twenty cents for one minute of phone calls, while others may cost a few dollars. From there, you can connect to your hotel’s WiFi or any other public WiFi.
Fortunately, in Spain, there are many mobile providers willing to set you up with a SIM-card and data plan. The popular companies include Movistar, Vodafone, Orange, and Yoigo. It is the law that all SIM-cards have to be registered, and can only be purchased with a valid passport. Many plans are available that offer you different amounts of data use. If you know someone that speaks Spanish, it’s best to bring them along with you. If not, you will have trouble communicating with the person trying to help you and you may get set up with a plan you didn’t want. This is another option that can only be done once you’ve arrived to Spain and have located your nearest phone store.