Was everyone on board lost when a submarine sank?
In WW2, that was often the case but not always. When we lost USS S-36 (SS-141), USS S-27 (SS-132), USS S-39 (SS-141) and USS Darter (SS-227) because they had each run aground, all of the crews survived. The crew of the Darter was transferred, en masse, to the USS Menhaden (SS-377), then still under construction.
Nine other boats were lost with some, but not all, of the crew surviving:
The USS Sealion (SS-195) was lost at the very beginning of the war in the Philippines. Four men were killed when she was hit by two bombs from an aircraft attack. The boat was in maintenance. (One man from the USS Seadragon (SS-194) died from the shrapnel from Sealion.) The rest of the crew survived and were evacuated from the Philippines.
All 62 men of the crew of the USS Perch (SS-313) survived the damage to their boat. They also survived the scuttling of the boat but nine died in captivity.
The USS Grenadier (SS-210) was damaged and then scuttled. All 76 men survived the loss of the boat, but four died in captivity.
The USS R-12 (SS-89) was recommissioned at the beginning of the war for use as a training boat. She was still being used as a training boat when she was lost in 1943. 42 men died when the boat went down, including two Brazilian Naval Officers. Five men were rescued and, fortunately, 18 others were on liberty that day and were not on board.
The USS S-44 (SS-155) was lost in 1943 along with 55 of her crew. Two crewmen survived.
In a very unusual case, 43 men initially survived the loss of the USS Sculpin (SS-191). They were picked up by the Japanese and split into two groups and put aboard Japanese carriers for the trip to Japan. One of those carriers was sunk by the submarine USS Sailfish (SS-192) and only one of that group of Sculpin sailors survived. A total of just 21 men from the Sculpin survived the war. Captain John Cromwell, who was aboard Sculpin as wolfpack commander, had opted to go down with the boat rather than taking a chance that he might give away the Ultra secrets under interrogation. He was awarded the Medal of Honor posthumously.
The USS Tullibee (SS-284) was sunk by her own torpedo when it made a circular run.79 men were lost and just one survived. Approximately 23 circular torpedo runs were reported in WW2, although there could have been more.
78 men were lost when the USS Flier (SS-250) was sunk by a mine. Eight others made it to Mantangula Island where they made contact with friendly natives. They radioed Australia, and the survivors were extracted by the USS Redfin (SS-272).
The USS Tang (SS-306) was hit and sunk by a circular run of her own torpedo. It was her last torpedo at the end of the patrol. Nine men survived the sinking and were taken prisoner. All nine survived the war including her captain, Richard O’Kane, who was later awarded the Medal of Honor.
In the other 39 cases, the entire crew went down with the boat.