The bomb went off late on Friday close to a guesthouse where the students were reportedly staying in Pul-e-Alam, the capital of eastern Logar province.
Dozens of people were hurt. Witnesses described roofs collapsing and victims being trapped under the debris.
No group has said it was behind the blast as people broke their fast in the Islamic holy month of Ramadan.
Afghanistan has seen a surge in violence since US President Joe Biden announced US troops would withdraw by 11 September.
A number of buildings were damaged in the explosion at about 19:00 local time (15:30 GMT) including the civilian guesthouse.
Some of those killed were high school students preparing to sit university entrance exams, said Hasibullah Stanekzai, head of Logar's provincial council.
As many as 90 people were injured, interior ministry spokesman Tariq Arian said.
He said the explosion caused widespread damage in the area, including to a hospital and residential houses.
More about: Afghanistan