The same carbon dioxide bubbles that make sodas fizzy.
In bread, those carbon dioxide bubbles are made by yeast, a tiny microbe that eats sugar and makes alcohol and carbon dioxide. In cookies, the bubbles are formed by a reaction between baking soda (sodium bicarbonate) and an acid.
The acid can be from something tart in the recipe, such as lemon juice or other fruit juices, vinegar, or buttermilk. Or it can be an acid produced when water is added to powdered tartaric acid (cream of tartar), or monocalcium phosphate. These are the powders that, along with baking soda, make baking powder.
Baking soda by itself will decompose to release carbon dioxide as the temperature of the cookie rises. Steam will also enter the bubbles and expand them. Air that was beaten into the cookie dough will also expand as the cookies get hot. All of these things combine to help make the cookies rise in the oven.
When the cookies cool, however, those hot gases will contract again. If the cookie has not been chemically changed by the heat, it will fall and get flat again. The chemical changes in the cookie that help it keep its fluffy texture and shape after it cools are mostly reactions of proteins.
As proteins are heated, their carefully formed three dimensional structures unwind (denature), and the untangled strings and sheets of protein can form bonds with other proteins. The proteins join up into big nets and sheets that hold the bubbles in place, and as the hot gases cool and try to contract, the proteins hold their shape, so air from the outside is sucked in.