The custom of gun salutes began in the 14th century on the high seas with the salute by cannon. During that time, warships fired a seven-gun salute, probably selected for either its astrological or Biblical significance. Warships would also show their peaceful intentions when nearing a friendly port by disarming themselves (emptying their guns) and friendly shore batteries did the same. This then evolved from a meaningful gesture to a ritual salute, the shore batteries took to answering each gun of a warship with three shore salutes. Early British warships had seven guns to empty, when each was answered by three shore salutes that came to twenty-one.
By 1875, the twenty-one-gun salute was established as the international salute, with the United States adopting the practice on August 18, 1875.
The twenty-one gun salute is fired in honor of a national flag, the head of state of a foreign nation, a member of a royal family, and the president, ex-president, and/or president elect of the United States. It is also fired at noon on the day of the funeral of the president, ex-president, or president-elect of the United States.