The La Liga club have released a statement on their official website, thanking the Spanish international goalkeeper for his 25 years of service to the club, beginning at their youth academy.
Casillas moves to Porto comes after the 34-year-old fell out of favour under former boss Jose Mourinho, ending months of speculation on his future at the Bernabeu.
The one-time World Cup winner with Spain, in 2010, made 725 appearances since his debut for Madrid in 1999.
During his 15 years with the first team, Casillas five La Liga titles, two Spanish Cups, two European Super Cups, four Spanish Super Cups and lifted the UEFA Champions League trophy on three occasions.