The abdomen of adult Drosophila, like that of other insects, is formed by a continuous epithelium spanning several segments. Each segment is subdivided into an anterior (A) and posterior (P) compartment, distinguished by activity of the selector gene engrailed (en) in P but not A compartment cells. Here we provide evidence that Hedgehog (Hh), a protein secreted by P compartment cells, spreads into each A compartment across the anterior and the posterior boundaries to form opposing concentration gradients that organize cell pattern and polarity. We find that anteriorly and posteriorly situated cells within the A compartment respond in distinct ways to Hhthey express different combinations of genes and form different cell types. They also form polarised structures that, in the anterior part, point down the Hh gradient and, in the posterior part, point up the gradient - therefore all structures point posteriorly. Finally, we show that ectopic Hh can induce cells in the middle of each A compartment to activate en. Where this happens, A compartment cells are transformed into an ectopic P compartment and reorganise pattern and polarity both within and around the transformed tissue. Many of these results are unexpected and lead us to reassess the role of gradients and compartments in patterning insect segments.