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).