Carbon nanotube growth in the presence of nitrogen has been the subject of much experimental scrutiny, sparking intense debate about the role of nitrogen in the formation of diverse structural features, including shortened length, reduced diameters, and bamboo-like multilayered nanotubules. In this paper, the origin of these features is elucidated using a combination of experimental and theoretical techniques, showing that N acts as a surfactant during growth. N doping enhances the formation of smaller diameter tubes. It can also promote tube closure which includes a relatively large amount of N atoms into the tube lattice, leading to bamboo-like structures. Our findings demonstrate that the mechanism is independent of the tube chirality and suggest a simple procedure for controlling the growth of bamboo-like nanotube morphologies.