Centre back Rudiger will be at Real for the next four seasons, the LaLiga champions said, adding that a presentation ceremony will be held for him on June 20.
The 29-year-old was a key player for Chelsea since joining the club from the Italian side AS Roma in 2017.
Rudiger moved to Chelsea for an initial fee of 29 million pounds from Roma in 2017.
He made 203 appearances and scored 12 goals for the Blues, winning the FA Cup, Champions League, Europa League, Uefa Super Cup and Club World Cup.
Chelsea described Rudiger as “as one of the most passionate characters to represent the club in recent memory”.
“I’m super excited for all the challenges ahead and can’t wait to play my first games for this huge club,” Rudiger said on his Twitter account.
Rudiger, who also spoke to Bayern Munich, was offered a contract worth more than 200,000 pounds to stay at Chelsea.
“We gave everything, and now we enter a situation where we can’t fight any more because of the sanctions and now Toni will leave,” Chelsea manager Thomas Tuchel said in April.
Rudiger played more than 200 times in all competitions for Chelsea and won the Champions League, Europa League, FA Cup, UEFA Super Cup and Club World Cup with the London club.
Rudiger initially arrived at Roma on loan from VfB Stuttgart, where he started his career, in 2015, before making the switch permanent at the end of that season.
He has had 50 international caps for Germany since making his debut in 2014.
In a statement on their official website, Madrid said Rudiger would be unveiled at a press conference at the club’s training ground on June 20. He is currently with the Germany squad for a series of UEFA Nations League matches, with Hansi Flick’s team playing Italy away on Saturday and then taking on England and Hungary before facing Italy again on June 14.
Rudiger joins a Real side who are fresh from winning the Champions League by beating Liverpool 1-0 in last weekend’s final in Paris.
Rudiger’s signing is the second time in successive seasons that Madrid have taken advantage of the availability of a top-level defender on a free transfer after signing David Alaba from Bayern Munich last year. He will compete with Eder Militao, David Alaba and Nacho Fernandez for a slot in the heart of the Real defence.