The incident was an "insider attack" at Patrol Base Shawqat in the Nad-e Ali area of Helmand province, the MoD said.
The soldier was serving with The Royal Scots Borderers, 1st Battalion The Royal Regiment of Scotland.
Spokesman for Task Force Helmand, Major Laurence Roche, said: "I am very sorry to report the death of a soldier from The Royal Scots Borderers, 1st Battalion The Royal Regiment of Scotland who was shot by an individual wearing an Afghan National Army uniform at his base in the Nad-e Ali district of Helmand Province”.
"This is incredibly sad news for the Battalion and everyone serving in Task Force Helmand. As we mark Remembrance this weekend, our thoughts now turn to the soldier’s family and friends whose loss is so much greater than ours."
The soldier's family have been informed and they have asked for a period of grace before further details are released.