Thunderstorms occasionally produce upward discharges, called blue jets and gigantic jets, that propagate out of the storm top towards or up to the ionosphere. Whereas the various types of intracloud and cloud-to-ground lightning are reasonably well understood, the cause and nature of upward discharges remains a mystery. Here, we present a combination of observational and modelling results that indicate two principal ways in which upward discharges can be produced. The modelling indicates that blue jets occur as a result of electrical breakdown between the upper storm charge and the screening charge attracted to the cloud top; they are predicted to occur 5-10s or less after a cloud-to-ground or intracloud discharge produces a sudden charge imbalance in the storm. An observation is presented of an upward discharge that supports this basic mechanism. In contrast, we find that gigantic jets begin as a normal intracloud discharge between dominant mid-level charge and a screening-depleted upper-level charge, that continues to propagate out of the top of the storm. Observational support for this mechanism comes from similarity with `bolt-from-the-blue' discharges and from data on the polarity of gigantic jets. We conclude that upward discharges are analogous to cloud-to-ground lightning. Our explanation provides a unifying view of how lightning escapes from a thundercloud.