Names given to the Spanish language
Formally speaking, the national language of Spain, the official Spanish language, is the Castilian language (as opposed to regional Spanish languages like Galician, Catalan, Asturleonese and Basque). As such both names, "español" and "castellano", have distinct and independent meanings that may be required for clarity in some specific contexts.
Generally speaking, though, both terms can be used to refer to the (national) Spanish language as a whole, with a preference for one over the other that depends on the context or the speaker's origin. "Castellano" (as well as "Castilian" in English) has another, more restricted, meaning, relating either to the old Romance language spoken in the Kingdom of Castile in the Middle Ages, predecessor of the modern Spanish language, or to the variety of Spanish nowadays spoken in the historical region of Castile, in central Spain.
Names given to the Spanish language
In the regions where regional languages are spoken, there is obviously a daily need to make the contrast between the national language and the regional language and so the national language is most often referred to as Castilian, particularly in the regional languages themselves (for example, "espanyol" is virtually never used to refer to the language in Catalan: "castellà" is used instead; in Basque, the name of the language is "gaztelania" or "gaztelera", never "espainiera"; and in Galician, the most commonly used term is "castelán" rather than "español"). That is often mirrored by educated English-speakers to refer to the linguistic situation in Spain.