The main deck gun was a dual-purpose weapon used to sink merchant shipping or shell shore targets, or defend the submarine on the surface from enemy aircraft and warships. Typically a crew of three operated the gun, while others were tasked with supplying ammunition. A small locker box held a few 'ready-use' rounds. With a well-drilled, experienced crew, the rate of fire of a deck gun could be 15 to 18 aimed shots per minute.
Some submarines also had additional deck guns like auto-cannons and machine guns for anti-aircraft defense.
Similar unenclosed guns are often found on surface warships as secondary or defensive armament (such as the US Navy's 5-inch (127 mm)/25 caliber gun which was removed from battleships to mount on submarines), although the term "deck gun" normally refers only to submarine-mounted guns.
The deck gun was first used by the Germans in World War I, and proved its worth when the U-boat needed to conserve torpedoes or attack enemy vessels straggling behind a convoy. Submarine captains often considered the deck gun as their main weapon, using torpedoes only when necessary (i.e. situations like an enemy warship where it was dangerous to use a deck gun), since many World War I submarines carried ten or fewer torpedoes and typically fired several torpedoes simultaneously to increase the probability of hitting the target. Lothar von Arnauld de la Perière used a deck gun or a dynamiting team on 171 of his 194 sinkings.
The deck gun was introduced in all submarine forces prior to World War I. The three British M-class submarines mounted a single 12 inch (305 mm)/40 caliber naval gun intended to be fired while the submarine was at periscope depth with the muzzle of the gun above water, principally in a shore bombardment role. This World War I design was found unworkable in trials because the submarine was required to surface to reload the gun, and problems arose when variable amounts of water entered the barrel prior to firing.
The French submarine Surcouf was launched in 1929 with two 203mm/50 Modèle 1924 guns in a turret forward of the conning tower. These were the second largest guns carried by any submarine after the British HMS M1 during the Second World War. The London Naval Treaty of 1930 restricted submarine guns to a maximum of 155 mm (6.1 inches).
In the early part of World War II, German submarine commanders favored the deck gun for similar reasons as their World War I counterparts; the limited number of torpedoes that could be carried, the unreliability of torpedoes, and because their boats could only travel submerged at slow speed for short distances. The deck gun became less effective as convoys became larger and better equipped, and merchant ships were armed. Surfacing also became dangerous in the vicinity of a convoy because of improvements in radar and direction finding. (See Defensively equipped merchant ships (DEMS) and United States Navy Armed Guard). German U-boat deck guns were eventually removed on the order of the supreme commander of the U-boat Arm (BdU) during World War II, and those deck guns that remained were no longer manned. For a few months in 1943, some U-Boats operating in the Bay of Biscay were equipped with enhanced anti-aircraft guns (at the trade-off of reduced torpedo loadouts), being known as "U-Flak" boats to be deployed as service escorts for regular U-Boats. After the Royal Air Force modified their anti-submarine tactics which made it too dangerous for a submarine to stay on the surface to fight, the U-Flaks were converted back to standard U-boat armament configuration.
Two notable deck guns from German U-boats used in World War II were the 8.8 cm (3.5 in) SK C/35 (not to be confused with 8.8 cm Flak ) and the 10.5 cm (4.1 in) SK C/32. The 88 mm had ammunition that weighed about 30 lb (14 kg) and was of the projectile and cartridge type. It had the same controls on both sides of the gun so that the two crewmen that were in charge of firing it could control the gun from either side. The 105 mm evolved from the 88 mm in the sense that it was more accurate and had more power due to the 51 lb (23 kg) ammunition it fired.
In the US Navy, deck guns were used through the end of World War II, with a few still equipped in the early 1950s. Many targets in the Pacific War were sampans or other small vessels that were not worth a torpedo. The unreliability of the Mark 14 torpedo through mid-1943 also promoted the use of the deck gun. Most US submarines started the war with a single 3-inch (76 mm)/50 caliber deck gun, adopted in the 1930s to discourage commanders from engaging heavily armed escorts. However, the aging S-boats were equipped with a 4-inch (102 mm)/50 caliber gun, which was often used to re-equip 3-inch-gunned submarines as the S-boats were transferred to training duties beginning in mid-1942. By 1944 most front-line submarines had been refitted with a 5-inch (127 mm)/25 caliber gun, and some were equipped with two 5-inch guns. The cruiser submarines USS Argonaut, Narwhal and Nautilus were each fitted with two 6"/53 caliber guns Mark 18 (152 mm) as built in the 1920s, the largest deck gun to be fitted on any United States submarine.
In the Royal Navy, the Amphion-class submarine HMS Andrew was the last British submarine to be fitted with a deck gun (a QF 4 inch Mk XXIII). HMS Andrew was decommissioned in 1974 and the deck gun is now in the Royal Navy Submarine Museum.