Spanish is a member of the Romance branch of Indo-European, descended largely from Latin and having much in common with its European geographical neighbors.
Spanish is related to several languages in terms of phonology, grammar and orthography. Of these, Portuguese is perhaps one of the most similar in terms of major languages. However, Spanish is also closely related to Catalan, Asturian, Galician and several other Romance languages. Spanish has fewer similarities with French and Italian but shares strong ties due to Latin roots.
Portuguese is orthographically similar in many ways to Spanish but it has a very distinctive phonology. A speaker of one of these languages may require some practice to effectively understand a speaker of the other (although generally it is easier for a Portuguese native speaker to understand Spanish than the other way around). Compare, for example:
Ela fecha sempre a janela antes de jantar. (Portuguese)
Ella cierra siempre la ventana antes de cenar. (Spanish)
Some less common phrasings and word choices have closer cognates in Spanish because Portuguese has managed to retain a much larger vocabulary, with stronger Latin heritage:
Ela cerra sempre a janela antes de cear. (less common Portuguese)
(Which translates as "She always closes the window before having dinner.")
In some places, Spanish and Portuguese are spoken almost interchangeably. Portuguese speakers are generally able to read Spanish, and Spanish speakers are generally able to read Portuguese, even if they cannot understand the spoken language. In fact, the number of bilingual speakers in Brazil (where Portuguese is the official language) has greatly risen because nearly every nation bordering Brazil is Spanish speaking.