Petroleum is retained in shales either in a sorbed state or in a free form within pores and fractures. In shales with oil resource potential, organic matter properties (i.e., richness, quality, and thermal maturity) control oil retention in general. In gas shales, organic pores govern gas occurrence. Although some pores may originate via secondary cracking reactions, it is still largely unclear as to how these pores originate. Here we present case histories mainly for two classic shales, the Mississippian Barnett Shale (Texas) and the Toarcian Posidonia Shale (Lower Saxony, Germany). In both cases, shale intervals enriched in free oil or bitumen are not necessarily associated with the layers richest in organic matter but are instead associated with porous biogenic matrices. However, for the vast bulk of the shale, hydrocarbon retention and porosity evolution are strongly related to changes in kerogen density brought about by swelling and shrinkage as a function of thermal maturation. Secondary organic pores can form only after the maximum kerogen retention (swelling) ability is exceeded at Tmax (the temperature at maximum rate of petroleum generation by Rock-Eval pyrolysis) around 445°C (833°F), approximately 0.8% vitrinite reflectance. Shrinkage of kerogen itself leads to the formation of organic nanopores, and associated porosity increase, in the gas window.