According to Bulbapedia, Surf is obtained from Wally's parent's house in Petalburg. Before obtaining Surf, the player must have defeated the sixth gym master.
After defeating the sixth gym master at the Petalburg gym, the player must go to the house just left of the gym. Inside the house is Wally's father, who will give away the Hidden Machine (HM) 03 Surf.
Hidden Machines are items used to teach Pokemon specific moves. Hidden Machine 03 contains the move Surf in every generation of the Pokemon games. Surf is a damage-dealing, water-type attack and can be used outside of combat to traverse bodies of water.