A tree is mostly built out of thin air. Through photosynthesis, leaves grab carbon dioxide gas from the atmosphere, split it apart using sunlight, and turn the carbon into sugar. That sugar becomes wood, bark, leaves and roots. Roughly half the dry weight of a tree is carbon that used to be floating around in the sky.
This makes trees a sort of natural air-cleaning machine. Forests across the planet store about 80% of the carbon held in land ecosystems - way more than soil, grass or crops combined. Tropical rainforests like the Amazon are especially powerful carbon sponges.
The catch is that the carbon only stays locked up while the tree (or its wood) is intact. Burn it or let it rot, and that carbon floats straight back up as CO2 again. Which is one big reason scientists worry so much about forest fires and logging.