The 21 gun salute is given, when a veteran passes away. In honor of their passing, they will let a 21 gun salute off. It is very eerie and gives you the goose bumps. When my Dad passed away, he had a military funeral and they did the gun salute for him.
Today the national salute of 21 guns is fired in honor of a national flag, the sovereign or chief of state of a foreign nation, a member of a reigning royal family, and the President, ex-President and President-elect of the United States. It is also fired at noon of the day of the funeral of a President, ex-President, or President-elect.
At military funerals, one often sees three volleys of shots fired in honor of the deceased veteran. This is often mistaken by the laymen as a 21-gun salute, although it is entirely different (in the military, a "gun" is a large-calibered weapon. The three volleys are fired from "rifles," not "guns." Therefore, the three volleys isn't any kind of "gun salute," at all).