The earlier the better. There are baby swim lessons. Babies love the water! If you wait a long time, you end up dealing with fear of water, which is not usually a problem when they're young. I can't imagine waiting until they're 5!!! That's inviting disaster, IMO.
The problem will be finding a program or teacher. My husband was a lifeguard/swim instructor for years, and he says the mom/tot lessons aren't worth a darn, because parents won't make their kids put their heads underwater. They're too timid about it, and are afraid that their kid will get water up their nose, etc., and the kids pick up on it, and it just makes a big mess. I happen to disagree somewhat. I think that mom/tot lessons should just be called "play in the water with mom time." I think it would be fun. Just don't expect your child to learn how to swim until they can be in the water on their own.
When I called around the Boise area to get some swim lessons for my then three-year-old, I was told that nowhere in Boise started lessons that young, at least without a parent in the water. My husband was shocked! He never liked teaching the 3 year olds, but in in Phoenix (where he taught) they started at 2 years. With a 1-yr -old, I couldn't do lessons with him! And I couldn't afford a babysitter on top of the lesson fees, even if I'd been able to find a babysitter.
We discovered that the next town over started "alone" lessons at age 3, so I drove him there. Now we live in that town, so my almost-3-yr-old will start this summer.
But my husband has met a lady who teaches lessons in her back yard who will start them at 1. Now, these are private lessons, so they're much more expensive than a community pool would be. But there are people out there.
By the way, my son, who just turned 5, graduated to level 3 last summer. He could swim to the edge by himself if he fell in the pool. He jumps into water that's deeper than his head and swims back to the top. And he wasn't even 4 1/2 then. He's not exactly the most coordinated kid in the world, either. We need some serious work on catching a ball :) So people who say that they can't really learn anything 'til they're 7 must have very timid children. My friend's 7 year old just got into level 3 because he's a scaredy cat (about everything!)