Policía Nacional (CNP) cares for security within all the country.
Guardia Civil (GC) cares for security in certain rural areas, as well as for terrorism and traffic (only in roads and highways out of urban areas).
Policía Municipal (PM) is the local police of Madrid, cares for traffic within city limits and for petty crimes.
There is not a police at a province level, but some communities like the Basque Country, Navarre and Catalonia have it, usually with an equivalent role as Guardia Civil (though they never duplicate roles).
There is, though, a Policía Municipal (local police) called BESCAM which is financed at provincial/community level only in Madrid, that fullfills the same role as Policía Municipal in Madrid city, but just in other cities or villages out of Madrid capital.
Fernando