Carlos was born on 29 March 1788 at the Palacio Real de Aranjuez in Aranjuez, Community of Madrid. In 1808, Napoleon captured Madrid in the Battle of Somosierra, and he induced Carlos's father Charles IV and Carlos' older brother Ferdinand VII to renounce their rights to the throne of Spain. But Carlos, who was heir presumptive to his brother, refused to renounce his rights to the throne, which he considered to have been given to him by God. From 1808 until 1814, he and his brothers were prisoners of Napoleon at the palace of Valençay in France.