https://es.wikipedia.org/wiki/Español_de_América#/media/Arch...
I am from Galicia, that red corner in northwestern Spain, so "castellano" is the most common term here.
The division within Spain makes sense, by the way: regions that have strong official regional languages say "castellano", because of course Galician, Catalan, etc. are also Spanish languages. So when you speak two languages, both with their origin in Spain, it makes less sense to call one of them español (Spanish). Note however that this doesn't mean that choosing to say one or the other is a political statement at all (or at least, the overwhelming majority of people wouldn't consider it so), things just evolved that way.
As to why some Latin American countries ended up saying "español" and others "castellano", I have no idea, to be honest.
As for the use of castellano for Spanish-in-general see e.g. https://spanish.stackexchange.com/questions/913/is-there-a-d...