The Royal Scots Borderers, 1st Battalion the Royal Regiment of Scotland or 1 Scots, were sent to Helmand province in September this year.
The soldier was killed by a man wearing Afghan National Army uniform at Patrol Base Shawqat in the Nad-e-Ali district.
The death of the 12th this year from “green-on-blue” attacks, where soldiers fall victim to their supposed allies.
News of the death came just after the Queen led the country in remembering fallen soldiers on Remembrance Sunday.
The Ministry of Defence confirmed next of kin had been informed.
Major Laurence Roche, spokesman for Task Force Helmand, 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”.