The midfielder, who signed for Los Blancos from Tottenham Hotspur in 2012, is now tied down to the club until June 2020.
Modric has become a key member of the team having made 180 appearances and scored 11 goals over the past four years.
The Croatia international is hopeful that the final few years of his career will be spent at the Bernabeu.
"I hope it is not my last contract renewal," Modric told reporters in a press conference. "My desire is to retire at Real Madrid and with this renewal I am closer to that challenge, but it depends on many things. How I feel, what I contribute to the team, but my idea is to retire here.
"I feel very happy and excited to renew with Real Madrid, the best club in the world. I want to thank the club and the president for their confidence in me. I can promise that I will continue giving everything and work hard to meet the demands of the club.
"There came a time at Tottenham where I had to change to improve and grow as a player. I did not doubt my quality and I knew that sooner or later I would succeed here, working every day in training and in the games. I've always had confidence in myself. I did not start well, but I never stopped believing in myself."
Modric has won seven trophies, including two Champions League titles, during his time at Madrid.