Hartmann was born on 11 December 1902 in Silstedt near Wernigerode in the Province of Saxony, a province of the Kingdom of Prussia in the German Empire. He was the third child of Albert Hartmann, an evangelic pastor in Wernigerode, and Helene Hartmann, née Wernicke. Hartmann had one older brother, Rudolf, and an older sister, Edith. From 1909 to 1914, he attended the Volksschule, a primary school, in Silstedt and later the Gymnasium, a secondary school, in the district of Magdeburg.
On 1 April 1914, Hartmann joined the Königlich Preußischen Kadettenkorps (Royal Prussian Cadet Corps) in Oranienstein near Diez. He initially served in the Vorkorps (pre corps) before he transferred to the Hauptkadettenanstalt (Main Military Academy) in Berlin-Lichterfelde on 1 April 1917. There he graduated with his Abitur (diploma) in 1921. Following his graduation he began his naval career with the Reichsmarine of the Weimar Republic on 1 April 1921 as a member of "Crew 21" (the incoming class of 1921).
Until 30 September 1925, he underwent a number of military and naval training courses. It began with basic military training (1 April – 30 September 1921) in Stralsund at the Baltic Sea and weapons courses at the Naval Academy at Mürwik. Hartmann was then transferred to the Hannover (1 October 1921 – April 1922) for onboard training and then to the training ship Niobe (April – 30 June 1922). During this timeframe, he advanced in rank to Fähnrich zur See (officer cadet) on 1 April 1923 and to Oberfähnrich zur See (Senior Ensign) on 4 April 1925.
He went on to serve as commander of the torpedo boats Seeadler and Albatros, before transferring to the U-boat arm in 1935. During the Spanish civil war, he commanded U-26 that patrolled Spanish waters during the Civil War in 1937–38 with Günther Prien as his first watch officer.
From January–May 1940 Hartmann was commander of both U-37 and 2nd U-boat Flotilla, but directing U-boats while at sea proved inefficient, and the Befehlshaber der U-Boote ("U-boat High Command") decided henceforth to direct the U-boats from land. After three patrols, and sinking 19 ships totalling 78,559 GRT, Hartmann received the Knight's Cross of the Iron Cross. His senior officers on his four patrols on U-37 were future Knight's Cross winners, first watch officer Oberleutnant zur See Ernst Bauer (two patrols) and later Oberleutnant zur See Nicolai Clausen (two patrols), second watch officer Leutnant zur See Gustav Poel and chief engineer Oberleutnant (Ing.) Gerd Suhren.
Hartmann's first patrol (19 August 1939 – 15 September 1939) on U-37 left Wilhelmshaven almost two weeks before the outbreak of World War II on Friday 1 September 1939 when German forces invaded Poland. Commander of U-37 on this patrol was Kapitänleutnant Heinrich Schuch.
Hartmann then moved to the BdU as a staff officer, and in November 1940 became commander of the 2nd ULD (U-boat Training Division). A year later he took command of the 27th U-boat Flotilla in Gotenhafen. In November 1942 he took command of the large Type IXD U-198 for a patrol to the Indian Ocean lasting 200 days, the third longest patrol ever undertaken, and sank 7 ships totalling 36,778 GRT. Chief engineer was Johann-Friedrich Wessels who received the Knight's Cross for his services on this patrol. In 1944 Hartmann became Führer der Unterseeboote Mittelmeer ("Commander of U-boats in the Mediterranean") and in this post received the Knight's Cross with Oak Leaves.
After the war he joined the Bundesmarine on 1 July 1956, commanding the 1. Schiffsstammregiment (1st Naval training regiment) in Glückstadt, retiring on 1 April 1962. He died on 26 April 1963 in Usseln/Waldeck of pulmonary embolism. He was buried in a family grave in Glückstadt.
As commander of U-37 and U-198 Werner Hartmann is credited with the sinking of 26 ships for a total of 115,337 gross register tons (GRT).Wehrmacht Long Service Award 4th and 3rd Class (2 October 1936)
Wehrmacht Long Service Award 2nd Class (1 April 1939)
Spanish Naval Merit Cross in White 2nd Class (Cruz blanca del merito naval) (21 August 1939)
Iron Cross (1939) 2nd Class (8 November 1939) & 1st Class (8 November 1939)
U-boat War Badge (1939) (7 December 1939); with Diamonds (5 November 1944)
Knight's Cross of the Iron Cross with Oak Leaves
Knight's Cross on 9 May 1940 as Korvettenkapitän and commander of U-37
645th Oak Leaves on 5 November 1944 as Kapitän zur See and leader of the U-Boote in the Mediterranean Sea
Mentioned twice in the Wehrmachtbericht on 1 March 1940 and 19 April 1940, the latter announcing the purported sinking of HMS Glasgow by Hartmann. He had launched an attack on Glasgow or HMS Sheffield on 13 April 1940 failing to sink either.