In early times, submarines were often powered by hand. This is because boat engines had not been invented yet. They were almost always designed to be used for war. Submarines would try to sink enemy ships by crude methods. These included drilling screws into their wooden hulls. Some tried to blow up a ship. This often destroyed the submarine, too.
Later, during the First and Second World Wars, better submarines were made. Many of these better submarines were created by Germany, called U-boats. The submarines were powered by a diesel-electric system. A diesel motor would be used to turn a generator. The generator would charge a large battery while the submarine was above the water. This power was then used to power the submarine when it went underwater. These submarines were dangerous to enemies. They are hard to see while underwater but it was easy to attack them when they were above the water and recharging. Many navies use larger, more modern diesel submarines.
The First Battle of the Atlantic was the first major battle that was mainly fought between submarines and their enemies. As in later wars, the main jobs of submarines were to enforce blockade and to sink enemy warships. They usually attacked freighters at night, shooting with their guns and then hiding under the water. Sometimes they used their torpedoes, especially against large ships and warships. During World War II The US Navy lost about 52 submarines due to combat and non combat causes.
After World War II better sonar helped the enemies of submarines to find and destroy them. New subs were more streamlined and had no artillery because water dragging against the guns made noise underwater and slowed the subs.