The clash on Feb. 7 will take place under the banner of the Roger Federer Foundation, which is involved in charitable work in Africa, and will be staged at the Cape Town Stadium.
It will be preceded by a doubles match in which Federer will partner Microsoft founder Bill Gates and Nadal will play alongside South African comedian Trevor Noah.
"This Match in Africa is a dream come true," Federer told the ATP website on Thursday. "I will play in my mother’s home country against my toughest rival and friend Rafa Nadal.
"We share not only the love for tennis but also for the good cause of giving children a better start in education and in life."
Nadal is also looking forward to the contest.
"Roger and I have shared so many magical moments on and off the court. Travelling with him to Cape Town and playing for the benefit of children is something I am very excited about," he said.
"It will be my first time in the region with Roger as a tour guide –- that will be fun."
The attendance record for a tennis match is 35,681, set at an exhibition game in Brussels between Belgian Kim Clijsters and Serena Williams in 2010.
The Cape Town Stadium, which hosted matches during the 2010 Soccer World Cup, has a capacity of 55,000.
(Reporting By Nick Said; editing by Clare Fallon)