The attack in the Jurm district of Badakhshan province on Friday also left around a dozen soldiers missing, fuelling speculation they had been captured by insurgents.
Taliban insurgents have stepped up attacks on government and foreign targets since Washington backpedalled on plans to shrink the US force in Afghanistan this year by nearly half.
"Eighteen Afghan soldiers were martyred and eight of them were beheaded" on Friday, provincial spokesman Naweed Frotan told AFP, saying 200 fighters stormed the post.
The defence ministry confirmed the incident in a statement and said the fighting left a total of 33 Afghan soldiers dead, wounded or missing.
Also Read
Twenty Taliban, including foreign fighters, were killed in the battle, deputy provincial police chief Sakhidad Haidar told AFP.
The Taliban claimed responsibility for the attack, which highlights Afghanistan's precarious security situation as US-led foreign troops pull back from the frontlines after a 13-year war against the insurgents.
Afghanistan is bracing for what is expected to be a bloody summer push by the Taliban, set to be the first fighting season in which Afghan security forces will battle insurgents without full NATO support.
President Barack Obama last month announced a delay in US troop withdrawals from Afghanistan, an overture to the country's new reform-minded leader, President Ashraf Ghani.
Hosting Ghani at the White House for their first presidential face-to-face meeting, Obama agreed to keep the current level of 9,800 US troops until the end of 2015.
The Taliban, who have waged a deadly insurgency since they were ousted from power in late 2001, warned that the announcement would damage any prospects of peace talks as they vowed to continue fighting.
Afghan security forces are suffering heavy casualties on the battlefield and large numbers of troops are resigning or deserting their units, a report by a US body said last month.