Swimming is super simple, and super complicated all at the same time.
The reason being is that swimming is simply moving through the water, but how you move is really important. Not to mention the holding the breathe aspect .The panic you feel when you think you need to breath is such a visceral feeling. It is a physiological response to essentially being covered in water.
Our body can’t tell that we are doing it on purpose, and that we will breath in a moment. It just wants to do it, but you can tell it to wait with your brain.
Why + Philosophy:
This all comes down to delayed gratification, and is honestly that simple. Some people were raised in a way where they got what they wanted/needed quickly, and others had to wait until their reward. This isn't a nature versus nurture thing, but simply a nurture.
Meaning that some people pick up on this skill sooner than others, and it is sort of fascinating to think about. Our physiological response would indicate something that of the natural state of our body. However it generally originates from the mind instead.
Meaning that our whole process is trying to change the body, when in actuality we should trying to change how we think about the water.
How + Physics:
This whole time while under water your brain is like "I NEED TO BREATHE. I NEED TO BREATHE", but you really don't.
You'd be very surprised just how long you can hold your breathe if you really tried, let alone after practicing for a while. That notion of needing to breathe is just your body acting on autopilot, but we can turn that off.
We can choose to hold our breathe, or even better do the opposite... BREATHING OUT.
Just like I hinted with the title it isn't about air going in, but rather air going out. Once your body builds up too much carbon dioxide, then it is probably too late. You'll need to reset, but if you can stop it before it reaches that point. Then you have the golden ticket!
What + Psychology:
It is all in the mind, and making sure you're keeping track of how long you're under water. By holding your breathe for a few seconds, then choosing to breathe out under the water.
You'll extend your time under water significantly, and that leads to more practice actually moving. Some instructors out there tell you to breathe out the whole time under the water, but that isn't helpful for most people.
It is helpful to them because they are usually going to be swim team or competition, where your breathes are going to be highly controlled.
On your own your mindset is different, and thus your actions should be too.
Take 3-5 seconds, holding your breathe, and then slowly let it out over time. The longer you breathe out, then the more time you get. However you can still panic if you wait too long.
Note: Your breathing out should be through your NOSE, not mouth.
Disclaimer:
This is advice for people to level up their swimming, or perhaps get started in the first place. While you swim you should make sure you are doing so in a public facility with a lifeguard on duty for safety.