The attack came two days after the United States said it had killed the chief of al Shabaab's intelligence and security wing, Tahliil Abdishakur, in a drone strike. Al Shabaab seeks to topple the Western-backed Mogadishu government and impose its own strict version of Islamic law.
"Al Shabaab attacked our base unexpectedly, early in the morning today. We lost seven soldiers," Captain Ahmed Idow, a Somali military officer, told Reuters by telephone from Baidoa.
Idow said Somali soldiers killed three al Shabaab insurgents during the attack.
A spokesman for al Qaeda-linked al Shabaab said the group had briefly seized the base and killed more than 10 soldiers. Al Shabaab often cites a higher death toll than the number given by officials.
"We fiercely attacked the military base near Baidoa," Sheikh Abdiasis Abu Musab, al Shabaab's military operation spokesman, told Reuters.
In a separate incident in central Somalia on Friday, al Shabaab ambushed a government convoy carrying food aid, killing one soldier, according to Somali officials.
A spokesman for al Shabaab confirmed the group was behind the attack.