Quantum electrodynamics (QED) corrections to the g factor of the bound electron and muon in the hydrogenlike atom are discussed. An approach that allows one to express the relativistic g factor of spin-1/2 particle in terms of the binding energy is applied to the calculation of the corrections to the g factor due to the finite nuclear size, including the vacuum polarization radiative correction. The contribution of the light-by-light diagram to the g factor of the bound electron and muon is calculated. For light one-electron ions, which are important for the experiment, this contribution has, so far, not been known.PACS Nos.: 31.15.Pf, 31.30.Jv, 32.10.Hq