The event takes place less than two weeks after her 15-month doping ban expires.
The five-time Grand Slam winner has been given a wildcard for the event, which begins on May 5.
It is scheduled to be her second comeback tournament after her suspension for doping, with the Russian set to return to action at the Stuttgart Grand Prix in April.
“Sharapova requested an invitation to play… (She) is one of the best players of the last 15 years and also a past winner of our tournament,” said event director Manolo Santana.
“In Madrid she always plays well and I’m sure she will come back to the courts highly motivated and hoping to do well.’’
Following a positive test for the drug meldonium at the 2016 Australian Open, the Russian was suspended for two years by the International Tennis Federation (ITF).
The Court of Arbitration for Sport (CAS) cut the ban by nine months last October, allowing her to return from April 26.
NAN recalls that her case divided opinion in the sport.
The Florida-based Sharapova, who turns 30 on April 19, had called the ITF’s original ruling “unfairly harsh’’ because she had not intentionally violated anti-doping rules.
Meldonium was only added to the World Anti-Doping Agency list of banned substances at the start of 2016 after mounting evidence it boosted blood flow and enhanced performance.
CAS cut Sharapova’s suspension but said she “bore some degree of fault’’ by relying on agent Max Eisenbud to check the banned list for changes.