The attack has been claimed by a faction of the Pakistani Taliban
The bomb went off outside the National Database and Registration Authority (Nadra) office in the town of Mardan.
A faction of the Pakistani Taliban said it carried out the attack, which left more than 45 others wounded.
The attack is one of the deadliest since last December’s massacre of 150 pupils and teachers in Peshawar.
The bomber in Mardan reportedly arrived on a motorbike and blew himself up when stopped by a security guard outside the Nadra building.
The office is usually crowded with people queuing up to get ID cards.
Officials put the death toll at 26 so far. Most of the dead and wounded are civilians, BBC correspondents say.
The Bacha Khan Medical complex has received at least 16 dead bodies and dozens of injured people, Reuters news agency reports.
If the attacker had not been stopped by a security guard at the office’s gate, the death toll would be significantly higher, Mardan police Deputy Inspector General Saeed Wazir told BBC Urdu’s Adil Shahzeb.
He said up to 12kg (26.5lb) of explosive material may have been used in the blast.
Jamaat-e-Ahrar, which split from the Pakistani Taliban in 2014, said it carried out the attack on what it called the “heathen Pakistan state”.
The group, along with others, also claimed responsibility for an explosion that killed more than 50 people at the Wagah border crossing with India in 2014.
Mohammad Khurasani, spokesman for Tehrik-e Taliban Pakistan (TTP), the main faction in the country, said the group did not support attacks on public places.
It has, however, previously claimed responsibility for many attacks on civilians, including the Peshawar school massacre in December 2014.
Tuesday’s bombing is one of the deadliest since a security crackdown following that attack, which saw 150 people killed by the Pakistani Taliban.
Offensives against insurgents have reduced major militant attacks from dozens every month in 2014 to no more than one or two a month this year.