
A submarine can submerge and avoid attack. They can also stay on the surface for a while to run their diesel engine and recharge their batteries.
Type 21 u-boat, or type xxi is a submarine that was used by the German navy during World War II. These were an improvement on the earlier German submarines.
They were able submerge for longer periods and had greater endurance than their predecessors. A new technology, the Schnorchel, enabled them to do this.

This was a significant breakthrough in the world submarine technology. It revolutionized the way submarines were built and worked. The Schnorchel was a compact, small engine that could be mounted in the hull of an existing Uboat. This allowed it to submerge more than before and also allowed it to reload the torpedoes from board while still underwater.
This technology was a breakthrough and allowed the Germans construct larger, more powerful submarines capable of enduring more attacks. This meant they would be able to keep their crews alive and fighting longer, which in turn helped them win the war.
But the most important thing about the Schnorchel was that it allowed them to reload their torpedoes while still under water, which was a game changer for the Germans. It allowed them not to have to worry as often about refilling their torpedoes. This allowed them more time to hunt for enemy ships in the sea.
Type XXI was the first U-boat to be built in Germany during World War II. It was meant to be the submarine that the Germans could use for victory. It was also a failure and may have contributed to the Third Reich's defeat.

A few years before the XXI was designed, the Germans had started work on a new submarine design that was supposed to be a game changer. It was a risky venture and they were not ready to take that chance. They weren't certain the boat would perform well, so they didn't want a lot to gamble on something that may not work.
They were able, however, to produce a prototype in Apri 1944. That gave them hope that production could begin sooner. The new design was based on the same Walter gas turbines that were used in the original designs, but doubled by the new Deutz SAA SM517 supercharged 8-cylinder diesel engines. This engine combined with streamlining the hull enabled seventeen knots in submergence.
Donitz had to choose between gambling on the new design or giving up submarine warfare. He knew that if he didn't have this new boat, the war would end with him losing his crews. The boat could also reload torpedoes. This was another plus.