A short version of the Spanish hierachy is that in the 1500's New Spain [now Mexico] was actually listed as the Viceroyalty of New Spain in most official correspondence with the Kingdom of Spain and the various Kings/Queens.
New Spain was established in 1521 and exploration in this region was first funded by Spain's Queen Isabella. The Viceroyalty was established in 1535, and for all practicle purposes served as a proxy or substitue for the King/Queen. This was a special power that few were given in this era.
In order to maintain order in New Spain with the large amount of land, the Viceroyalty ceded this power (with oversight) to what were called Audiencias, who had broad Judicial, Legislative, and executive powers. In New Spain the two audiences set up were in Mexico City and then Guadalajara.
Audiencias then ceded control to Corregidor's who controlled Governorate's, more commonly called provincia's.