As described in this post, on 22 July 1812 Wellington‘s Anglo-Portuguese army defeated the French at the battle of Salamanca. On 6 August Wellington moved towards Madrid with about 60,000 men.The French and their Spanish allies had 210,000 troops in Spain, but many of these were spread around the country in garrisons. Others were in Andalusia in the south under the command of Marshal Nicolas Soult
King Joseph Bonaparte and Marshal Jean Jourdan had only 22,000 men with which to oppose Wellington. On 10 August Joseph and his royal household left Madrid for Valencia, accompanied by 15,000 civilians in a convoy of 2,000 wagons. Only a small garrison was left behind.
The poor communications between Andalusia and Madrid meant Soult did not learn of the French defeat at Salamanca until 12 August. He was forced to withdraw. He ended his siege of Cadiz on 25 August and evacuated Seville two days later, apart from a small rearguard that was quickly defeated by an Anglo-Spanish force. Soult joined with other French forces from Extremadura at Cordoba and withdrew to Granada. On 16 September he retreated to Valencia.
Wellington’s army entered Madrid on 12 August 1812 to the cheers of the population. The French had lost half the territory that they had gained in Spain since 1808 in eight months.
The Spanish could theoretically put 100,000 troops in the field, and more could be raised from the liberated territories. The British hoped for a general Spanish mobilisation against the French, but this did not happen. Charles Esdaile says that the British attributed this to ‘Spanish laziness and incompetence’ but argues that this view ignored the true situation in Spain and the ineffectiveness of the government.
The 1811 harvest was disastrous, and the countryside had been pillaged by a series of armies. The crowds that cheered Wellington’s armies wanted bread rather than a chance to fight the French.
Police controls imposed by the French were little relaxed. Feudalism was theoretically abolished, but landowners simply replaced feudal levies with rents. Some guerillas preferred banditry to pursuing the French or joining the regular army. There was consequently anarchy in much of the country.
The country was also in a dire financial state. The French invasion and troubles in the Spanish American colonies reduced revenue from 407.7 million reales in 1810 to 210.6 million in 1811 and 138 million in 1812. Esdaile argues that Spain was bankrupt unless it could stabilise the situation in its American colonies. Only British subsidies allowed it to continue the war.
Despite the liberation of the capital of Spain and half the country, the Peninsular War was a long way from being over.
 C. J. Esdaile, The Peninsular War: A New History (London: Allen Lane, 2002), p. 403.
 Ibid., pp. 406-7.