In the summer of 2005, Ramos was purchased by Real Madrid for €27 million, a record for a Spanish defender.
He was the only Spanish player brought in during Florentino Pérez's first stint as Real's president.

At the club, Ramos was assigned the number 4 shirt, previously worn by Fernando Hierro.
On 6 December 2005 he netted his first goal for the Merengues, in a 1–2 UEFA Champions League group stage loss at Olympiacos.

During his first seasons, Ramos played as centre back, being also used as an emergency defensive midfielder on occasion.
However, with the arrival of Christoph Metzelder and Pepe in the 2007–08 season, he was again relocated to right back.
In his first four seasons at Real Madrid, Ramos displayed a goalscoring instinct unusual to many defenders, netting more than 20 goals overall.
He also received the first nine of his 24 red cards for the club, including four in his debut season.
His first red card came after two bookable offences in a 1–0 away loss to RCD Espanyol on 18 September 2005.

During the 2006–07 season, Ramos scored five goals, including one in a 3–3 draw with FC Barcelona, as Real Madrid won a record 30th Spanish league championship.

On 4 May 2008, he assisted Gonzalo Higuaín in the 89th minute against CA Osasuna in an eventual 2–1 away win, the match that sealed the club's 31st league championship.
On the final day of the season, he scored twice in a 5–2 home win against already relegated Levante UD: one through a header, and another an individual effort; these goals taking his league tally for the 2007–08 season to five.

On 24 August 2008, Ramos scored in the 2008 Supercopa de España second leg against Valencia, making the score 2–1 in an eventual 4–2 and 6–5 aggregate win.
The victory came despite Real Madrid playing with only nine men for a long period of time after Rafael van der Vaart and Ruud van Nistelrooy were sent off.
Although Ramos experienced a slight dip in form during the early part of the 2008–09 season, he returned to his best and on 11 January 2009, scoring an acrobatic volley in a 3–0 triumph at RCD Mallorca.
He continued his scoring run the following week in a 3–1 home win against Osasuna.

Ramos was named in both FIFA and UEFA's 2008 Team of the Year, adding the FIFPro Team of the Year 2007–08 accolade.
He also finished 21st in the European Player of the Year nomination for 2008.
In the summer of 2005, Ramos was purchased by Real Madrid for €27 million, a record for a Spanish defender. He was the only Spanish player brought in during Florentino Pérez's first stint as Real's president.
At the club, Ramos was assigned the number 4 shirt, previously worn by Fernando Hierro. On 6 December 2005 he netted his first goal for the Merengues, in a 1–2 UEFA Champions League group stage loss at Olympiacos.
During his first seasons, Ramos played as centre back, being also used as an emergency defensive midfielder on occasion. However, with the arrival of Christoph Metzelder and Pepe in the 2007–08 season, he was again relocated to right back. In his first four seasons at Real Madrid, Ramos displayed a goalscoring instinct unusual to many defenders, netting more than 20 goals overall. He also received the first nine of his 24 red cards for the club, including four in his debut season. His first red card came after two bookable offences in a 1–0 away loss to RCD Espanyol on 18 September 2005.
During the 2006–07 season, Ramos scored five goals, including one in a 3–3 draw with FC Barcelona, as Real Madrid won a record 30th Spanish league championship.
On 4 May 2008, he assisted Gonzalo Higuaín in the 89th minute against CA Osasuna in an eventual 2–1 away win, the match that sealed the club's 31st league championship. On the final day of the season, he scored twice in a 5–2 home win against already relegated Levante UD: one through a header, and another an individual effort; these goals taking his league tally for the 2007–08 season to five.
On 24 August 2008, Ramos scored in the 2008 Supercopa de España second leg against Valencia, making the score 2–1 in an eventual 4–2 and 6–5 aggregate win. The victory came despite Real Madrid playing with only nine men for a long period of time after Rafael van der Vaart and Ruud van Nistelrooy were sent off. Although Ramos experienced a slight dip in form during the early part of the 2008–09 season, he returned to his best and on 11 January 2009, scoring an acrobatic volley in a 3–0 triumph at RCD Mallorca. He continued his scoring run the following week in a 3–1 home win against Osasuna.
Ramos was named in both FIFA and UEFA's 2008 Team of the Year, adding the FIFPro Team of the Year 2007–08 accolade. He also finished 21st in the European Player of the Year nomination for 2008.
Sergio Ramos