Casillas, who finished his playing days at Porto, won the World Cup and two European Championships during an illustrious international career.
He lifted five LaLiga titles and the Champions League three times with Real, making 725 appearances for the Spanish giants over 16 seasons between 1999 and 2015.
“The important thing is the path you travel and the people who accompany you, not the destination that it takes you,” Casillas posted on Instagram alongside a lengthy retirement letter.
“Because that with work and effort comes alone and I think I can say, without hesitation, that it has been the path and the dream destination.”
Casillas won 167 caps for Spain, bettered only by Sergio Ramos, and was captain when they became world champions in 2010 and triumphed at Euro 2008 and Euro 2012.
He sits second on the list of all-time appearances for Real, with only former team-mate Raul having made more.
The keeper also won two Portuguese titles at Porto after leaving the Bernabeu in 2015 but did not play again for the club after suffering a heart attack in training last year.
Real hailed Casillas as the club’s greatest goalkeeper and one of their finest players.
“Real Madrid wants to show its appreciation, admiration and affection for one of the greatest legends of our club and world soccer,” read a statement on the Spanish champions’ website.
“The best goalkeeper in the history of Real Madrid and Spanish football came to our house when he was nine years old.
“Today, one of the most important footballers in our 118-year history, a player whom we love and admire, a goalkeeper who has enlarged the legend of Real Madrid with his work and with exemplary behaviour both inside and outside, says goodbye as a professional player.
“Iker Casillas belongs to the heart of Real Madrid and will be so forever. Real Madrid wants to convey to him and his family the affection of our club, which is the club of his life.”