From this wikipedia article:
In quantum chromodynamics, the modern theory of the nuclear force, most of the mass of the proton and the neutron is explained by special relativity. The mass of the proton is about 80–100 times greater than the sum of the rest masses of the quarks that make it up, while the gluons have zero rest mass. The extra energy of the quarks and gluons in a region within a proton, as compared to the rest energy of the quarks alone in the QCD vacuum, accounts for almost 99% of the mass. The rest mass of the proton is, thus, the invariant mass of the system of moving quarks and gluons that make up the particle, and, in such systems, even the energy of massless particles is still measured as part of the rest mass of the system.
Also, at about 5:00 of this youtube video by Veritasium is your same question answered.
This other physics.se questionThis other physics.se question is also related.