The convicts, Col. Shah Mahmood and Commander Nazirullah, from the 201st Selab Military Corps, were arrested two years back over spying for the Pakistani intelligence agency, Pajhwok News gas reported.
The two were tried at the appellant court of the Selab Military Corps during an open hearing.
Prosecutor Maj. Noor Mohammad presented his arguments in which he accused the two commanders of spying for the intelligence agency of the neighbouring country.
Afterwards, defense lawyer for the accused, Toryali Muqnan, defended his clients and said the security officials had been forced to make the confession.
At the end, the jury headed by Maj. Najibullah Nadeem indicted the two in the treason case and sentenced them to 20 years in jail each.
Earlier, another commander of the Selab Corps was sentenced to 10 years in jail over steeling weapons.