Being three sevens, twenty-one is considered an auspicious number. It shows up in card games, and in symbolism, but also as a sign of respect. Firing guns as a sign of respect began with the navy, firing your stores dry to demonstrate lack of hostile intent. It evolved into a show of respect, with more guns being fired the higher the rank of the visiting dignitary.
It is also often encountered at funerals, as a sign of respect to the departed, typically for police officers or military personnel. Traditionally, of course, it was cannons, but rifles are considered acceptable. At military funerals it may also be accompanied by Taps, or The Last Post for Commonwealth militaries.
The number of gunshots fired doesn't have to be twenty-one, but that's the highest number (traditionally reserved for heads of state) and tends to show up more often in fiction. The supertrope would be Due to the Dead.
Some relevant information from The Other Wiki on the 21-Gun Salute and the 3-Volley Salute. They're not the same thing. Technically, most "21-gun salutes" are actually 3-volley salutes. A 3-volley salute involves a group of guns being fired three times; a 21-gun salute is twenty-one guns being fired (or one gun twenty-one times).
Supertrope to Three-Volley Flinch, which is a character reaction to this trope.
- A seven-man honor guard at the funeral procession for Commissioner Loeb in The Dark Knight. Except they're not the honor guard: they're the Joker and his henchmen using the real honor guard's uniforms and rifles to assassinate the mayor.
- It is mentioned that rifles were fired at the funeral of Captain George Stacy in The Amazing Spider-Man
- You Only Live Twice. During the Burial at Sea of James Bond at the beginning of the movie, several sailors fire rifles as a salute.
- The movie version of Clear and Present Danger cuts between Admiral Greer's funeral and the ambush of the special forces team. It comes to a head as the three volleys are fired at the funeral, cut against the distress calls and machine gun fire of the battle.
- The First Men in the Moon. The (not quite) first landing on the Moon is celebrated by artillery pieces being fired off back on Earth. This creates the unintentional impression among the audience that war has broken out over the issue.
- This is shown at the start of The Rock.
- Billy Glenn in Mars Attacks! is laid to rest after the Martians' attack.
- Parodied in Hot Shots!. Dead Meat is given one at his funeral and Admiral Benson, thinking that he's under attack, pulls out a sidearm and returns fire.
- This shows up frequently in the Aubrey-Maturin series; fitting, as the tradition originated with the navy in the 17th century and this is a naval series set in the 19th. A captain gets a certain number of guns, an admiral a certain number more. After a particularly well fought battle in the first book, a number of ships fire off their guns as a salute to the HMS Sophie and her crew. One of the instalments is even named The Thirteen-Gun Salute, after the number which is due to the King's envoy, whom HMS Diane is carrying on board in this novel.
- In The Happy Return, Horatio Hornblower encounters a megalomaniacal Central American despot who demands a 23-gun salute. When he later turns against the British, Hornblower is only too glad to give him a full broadside.
- The centaurs of the dark forest near Harry Potter's Hogwarts fire off a volley of arrows in honor of Dumbledore, at his funeral.
- A version of this appears in Missee Lee from Arthur Ransome's Swallows and Amazons series, with gongs instead of guns. Taicoons Chang and Wu are saluted with ten strokes of the gong; Missee Lee herself, being the overall chief, is saluted with 21 strokes.
- Late in the 1982 miniseries The Blue and the Gray, the surviving members of the Geyser family are holding a funeral for two of the sons, one of whom died protecting the family farm alongside Confederate troops. A detachment of those troops arrives and their commanding officer offers to fire a volley in gratitude for the family's assistance at the battle. The father is reluctant to accept, but the mother interrupts him: "Fire your volley, Lieutenant. I'm sure the boys will hear it." The soldiers proceed with the volley.
- In an episode of Bones Booth takes part in a 21 gun salute at his own funeral, which was staged in order to catch a perp who said that Booth would never see him again except at his (Booth's) funeral. Since Booth had gotten shot by a Stalker with a Crush at the end of the previous episode the FBI decided to use it.
- One episode of The West Wing featured a military funeral complete with 3-volley salute for a homeless Korean War Veteran. The Pentagon granted the show rare permission to film at Arlington National Cemetery for the episode, with real military personnel performing the role of the honor guard and chaplain. Toby, the White House staffer who arranged the funeral, does a Three-Volley Flinch; it's possible it was not scripted.
- A fourth-season episode of White Collar featured a criminal who disappeared following conviction and the forfeiture of illegally gained assets and was presumed dead. His will required a 21-gun salute at his funeral.
- An episode of Magnum, P.I. showed this at his father's funeral.
- One episode of The A-Team has the A-Team step in to give a funeral for one of their old military buddies who had tangled with the Villains of the Week. With Hannibal calling the orders, the other three fire their rifles several times in salute.
- Stargate SG-1: The episode "2010" has a 21-gun salute as part of a ceremony commemorating SG-1 and their contact with the Aschen ten years before in an Alternate Timeline.
- In Home Improvement, Tim Taylor sets up a 21-nail-gun salute to the late Binford. As is to be expected from the show, the last row of nail guns doesn't exactly work correctly, and Hilarity Ensues.
- Referenced in the title and chorus of the song "21 Guns" by Green Day.
- Also referenced in the song "For Those About to Rock (We Salute You)" by AC/DC.
- Mentioned in Eric Bogle's song No Man's Land, the chorus of which asks a soldier dead in WWI "Did the rifles fire o'er you as they lowered you down [into the grave]?".
- Brantley Gilbert's "One Hell of an Amen" says a fallen soldier "went out twenty-one guns blazin'".
- A 7-gun (3-round burst) salute is performed during the funeral at the end of Halo 3.
- In some Wing Commander games, the death of your character or one of your wingmen will be followed by a cutscene of their funeral, with a 21 laser rifle salute.
- Team Fortress 2: The Soldier's taunt with the Shotgun or Reserve Shooter has him doing this.
- When Maude Flanders was killed by a gun that fires t-shirts on The Simpsons, there was a 21 t-shirt salute at her funeral.
- Daffy Duck uses 21 cannons to celebrate a victory over Speedy Gonzales. When he pulls the 21 cords to make the cannons shoots, he accidentally points them to make him their new target.
- In The Venture Bros., when henchman #21 (no relation) buries another henchman, there is a salute at the funeral. Unfortunately, the rifles used by the henchmen shoot tranquilizer darts, which #21 realizes just as they rain back down upon him. He passes out sprawled across the grave.
- The Queen of England had this as part of her Diamond Jubilee celebrations.
- Presidential funerals include a 21-gun salute.
- At the 2000 US Golf Open, there was a 21-drive salute in honor of defending champion Payne Stewart, who died in a plane crash the previous October.
- In the British Raj, the number of guns used in a salute varied depending on the status of the person being saluted. 21-gun salute was limited only to highest ranking Indian princes and high ranking British generals and officials. However, the British viceroy was entitled to a 31-gun salute while the British king, as the emperor of India, was entitled to a 101-gun salute.