Petrified wood formed when ancient trees and plants became buried under mud, sand or volcanic ash.
When buried deep enough, the organic material was starved of oxygen, which prevented it from decay.
Dissolved minerals being carried in groundwater gradually filled pores and voids, and as the water evaporated, the minerals crystallised.
Over thousands to millions of years, the crystallised minerals replaced the original cell structure.
Although it's often believed the wood turned into stone, that's incorrect. The organic material is always replaced with minerals.
The colours in petrified wood are determined by the minerals present.
Some petrified wood can look almost identical to the original organic structure.