The Brazil international's new deal will run until June 30, 2022.
The 29-year-old has won 17 major trophies since joining Los Blancos from Fluminense a decade ago, including three UEFA Champions League crowns and four La Liga titles.
Marcelo, however, will miss his club's next two league games against Real Sociedad and Real Betis following his red card against Levante last Saturday. He was dismissed for kicking out at Jefferson Lerma, with his two-match ban upheld by the Royal Spanish Football Federation earlier on Wednesday.
Real will first begin their bid for a third straight Champions League triumph tonight against Cypriot side APOEL in Group H.