Mr Mandela was treated for a long-standing abdominal complaint and is expected to be released from hospital by Monday, a government statement said.
The anti-apartheid icon, 93, is comfortable and "fully conscious", the statement said.
His health has declined in recent years and he rarely appears in public.
As the country's first black president after a history of white minority rule, the BBC's Andrew Harding in Johannesburg says Mr Mandela occupies a special place in the hearts of South Africans.
The statement from President Jacob Zuma's office said: "The doctors are satisfied with his [Mr Mandela's] condition, which they say is consistent with his age.
"He was in good health before admission in hospital but doctors felt the complaint needed a thorough investigation."
The presidency asked for his family to be given privacy.
The statement did not say which hospital he had been admitted to but there are suggestions it was a military hospital in the capital, Pretoria.
Journalists waiting outside one hospital were earlier told to move away or face arrest.'Epitome of health'
Mr Mandela had returned to Johannesburg last month from his rural home in the Eastern Cape and in January last year, he received treatment in the city's Milpark hospital for a serious chest infection.
"I can assure you that the former president is in good spirits and well," said Mac Maharaj, a spokesman for Mr Zuma.
"This was a long-standing complaint - nothing that cropped up suddenly and needed emergency attention," said Mr Maharaj, who was in prison in Robben Island with Mr Mandela.
"But it is an issue that the doctors treating him felt needed specialist attention, and so arrangements were made accordingly."
He would not confirm reports that Mr Mandela had undergone overnight surgery for a hernia, and appealed for "co-operation from the public and the media so we manage this thing properly".
The statesman's eldest granddaughter said she was not immediately concerned about his health.
"I don't see it as a big thing. When I saw him on Wednesday, he was in good spirits, in perfect health, and the epitome of health really for a man of his age," Ndileka Mandela told the AFP news agency.
"Grandad rebounded from his illness last year. I don't see any reason why this should be any different."
Andrew Harding says the government is clearly keen to control the flow of information, after previous alerts about the former leader's health became the subject of much speculation.
Mr Mandela retired from public life eight years ago - his last public appearance was at the World Cup in South Africa in 2010.
The Nobel Peace Prize winner is affectionately known in South Africa by his clan name, Madiba.
He spent 27 years in prison for his fight against white minority rule before being released in 1990.
In 1994, he became South Africa's first black president, stepping down in 1999 after one term.