Casillas announced his retirement from football via his verified Twitter handle on Tuesday.
Announcing his retirement on Twitter, Casillas said: “The important thing is the path you travel and the people who accompany you, not the destination to which it takes you.
“I think I can say, without hesitation, that it has been the path and the dream destination.”
Reacting to Casillas’ retirement, Madrid described him as the best goalkeeper in the 118-year history of the club.
“Real Madrid wants to show its appreciation, admiration and love for one of the greatest legends of our club and world football,” read a statement on the club’s website.
“Iker Casillas belongs to the heart of Real Madrid and will be so forever.”
Casillas who joined Madrid at the age of nine, made 725 appearances for the Spanish giants during a 16-year career at the Bernabeu, winning three Champions League titles and five La Liga crowns.
He joined Porto in 2015 but has not played since suffering a heart attack during training in April 2019.
During his recovery he was given a role on the club’s coaching staff in July 2019.
He made 156 appearances for the Portuguese side, winning two Primeira Liga titles and one Portuguese Cup.
He won 167 international caps for Spain between 2000 and 2016. Only former Real team-mate Sergio Ramos has made more appearances for the national side.
During his time with the national team, he led them to win the 2010 World Cup and two successive European Championships in 2008 and 2012.
Also, he was a member of the Spanish team that won the 1999 FIFA U-20 World Cup in Nigeria.
In February, he announced his intention to run for the presidency of the Spanish Football Federation (RFEF), before later withdrawing because of the “exceptional social, economic and health situation” the country was suffering during the Covid-19 pandemic.