Stove Pipes and Woodstoves
Stove pipes carry away the smoke and byproducts from burning wood in the stove. The pipe also provides oxygen for the stove so the wood inside can burn. Pipes should be as short as possible to reach the chimney, because long pipe lengths can decrease the amount of air getting to the fire in the stove and hamper ventilation of smoke.
Single-Wall Stove Pipes
Single-wall stove pipes have one layer of metal around the pipe. When using these, the code requires at least 18 inches between the pipe and the ceiling, according to "Code Check Complete: An Illustrated Guide to the Building, Plumbing, Mechanical and Electrical Codes" by Redwood Kardon, et al. Once the pipe reaches a wall or ceiling, a thicker, more insulated pipe needs to be used to prevent a fire in the wall from the heat of the stove pipe.
Why Angle Matters
You should never install a completely horizontal stove pipe. If your pipe is flat, creosote can build up inside. This flammable byproduct of incompletely burned wood can create a fire inside the pipe. Buildup of creosote can also block the stove pipe and cause smoke to back up into the room. A steep enough angle for the pipe will prevent creosote buildup inside the pipe and possibly prevent a house fire.
The angle of rise for the stove pipe should be at least 1/4 inch per foot of run between the stove and the chimney, according to Kardon, et al. "Shelter II," by Lloyd Kahn, et al., recommends an angle of no more than 30 degrees below a completely vertical slope.