The bubbles shape themselves so that their surface area is minimal. Where three surfaces meet along one edge, the angles between them are 120 degrees. In a corner where four bubbles meet, the edges extend with the tetrahedral angle. These rules are Plateau's laws.
My few bubbles already look like a foam. Apparently the optimal structure of a foam with bubbles of equal volume is still unknown. The Weaire-Phelan structure is the best one known.