"We are delighted to be able to welcome Roger to the tournament this year," event director Manolo Santana told Spanish media on Wednesday.
"It was a pity he missed last year with an ankle injury but the ATP have confirmed he will be with us this time."
World number one Federer has won eight titles this year, including three grand slams.
The Madrid Masters gets underway on Oct. 14.