The Spanish empire was largely dissolved in the 19th century. From Mexico to Argentina, most of the old colonies declared their independence from Spain.
Cuba remained a colony. In fact, my paternal grandparents were born in the island during the colonial period or 1892. It was really interesting a few years ago when my mother showed my “abuela’s” birth certificate.
It all ended for Spain when Puerto Rico and Guam were ceded to the US. Also, the Philippines were bought for $20 million, and Cuba became a US protectorate until independence in 1902.