The rifle volley is often mistaken by nonmilitary folks as a 21-gun salute, although it’s entirely different. In the military, a gun is a large-caliber weapon. The three volleys are fired from rifles, not guns. Therefore, the three volleys aren’t any kind of gun salute at all.
The firing team consisting of an odd number of service members, between 3 and 7 (size varies according to the rank of the deceased) fires three times (three volleys).
The three volleys come from an old battlefield custom. The warring sides would cease hostilities to clear their dead from the battlefield, and the firing of three volleys meant that the dead had been properly cared for and the side was ready to resume the battle.
The honor guard often slips three shell-casings into the folded flag before presenting the flag to the family. Each casing represents one volley.