The two cities, where left-wing councils run by citizen protest movements took power from conservatives this year, criticised the Spanish government's response to the migrant crisis.
Barcelona city hall said on Tuesday it had met with local NGOs to discuss how to register migrants coming to the city and place them with the "many Barcelona families" which have "offered to receive refugees".
"Barcelona's intention is to work to set up a network of cities of refuge in order to face up to this crisis in a unified way," it said in a statement.
Madrid city hall said in its own statement that it was joining this initiative, first announced by Barcelona on August 29th.
"The city hall is joining the network of host cities proposed by Barcelona and in the coming days will propose resources and measures to tackle the refugee tragedy," it said.
Spain's conservative Prime Minister Mariano Rajoy said on Tuesday that his country, which is home to nearly 47 million people, was willing to receive just over 2,700 migrants in 2015.
He spoke in Berlin alongside German Chancellor Angela Merkel, who said her country -- population about 80 million -- planned to receive 800,000 asylum seekers this year.
Madrid city hall, run by the left-wing Ahora Madrid group, said "Spain's contribution to this humanitarian crisis has been very poor."
Rajoy said in Berlin that he was willing to discuss with European Union authorities the number of migrants Spain will receive on certain conditions and that his position could change.
The International Migration Organisation says 2,166 people tried to reach Spain by sea this year up to August 24th.
Among some of Spain's Mediterranean neighbours the figure was much higher: 107,000 for Italy and 157,000 for Greece.