The issue is not that easy and not fully understood.
What's very well understood is the theory of quite weakly bound systems like the binding of atomic nuclei out of nucleons (protons and neutrons) via the residual strong force (a kind of van der Waals force of the strong interaction acting between color neutral hadrons) or atoms out of atomic nuclei and electrons. The mass of such objects (i.e., the rest energy of these objects in the center-of-momentum frame of the constituents) is given by the sum of the mass of the constituents minus the binding energy, i.e., there is a "mass defect" ##\delta M=E_{\text{B}}/c^2##.
The case of the hadron masses as bound states of either three quarks (baryons) or a quark-antiquark pair (mesons) is way more complicated. The light quarks (up and down) have a "current quark mass" of a few 10 MeV. The determination of these masses is already complicated enough since we cannot define it in the usual sense of the mass of asymptotic free particles, because there are no free quarks (nor free gluons) due to confinement. This "current quark mass" is the mass due to the Higgs mechanism of the electroweak sector of the standard model. A proton, however has a mass of about 938 MeV. The precise mechanism, how this mass can be explained as dynamically generated via the strong interaction, is pretty much unkown. That this picture is, however, quantitatively correct, is inferred from ever more accurate evaluations of QCD with help of computer simulations, called lattice QCD. Basically it's the Monte-Carlo evaluation of path integrals of Euclidean ("imaginary time") QCD with ever better algorithms and increasing CPU/GPU power. The observed hadron spectrum is pretty well described in this way, and that's why we can be pretty confident that QCD is the right fundamental theory of the strong interaction (at least as far as the Standard Model works, and to the dismay of the particle physicists there's no clear hint for "physics beyond the Standard Model" yet!).
Qualitatively one can make sense of the fact that the mass of the hadrons is so much larger than that of the valence quarks in the naive quark model in terms of the socalled MIT bag model, which however is not too successful quantitatively. Nevertheless it provides a picture: The three valence quarks of, e.g., a proton are confined to a "bag" about the size of 1 fm due to confinement (however this may work in detail), and thus there's a lot of kinetic energy of the motion of these constituents within the bag, and this motion makes the huge part of the mass of the proton not provided by the mass of the constituents. The formation of the bag is hand-wavingly depicted as a bubble of perturbative QCD vacuum in the fully interacting QCD vacuum, although as I said it's not very clear, how to make sense of this mathematically.
Confinement, chiral-symmetry breaking through the formation of a quark condensate, ##\langle \bar{q} q \rangle \neq 0##, is among the most puzzling an fascinating questions of contemporary physics. It's investigated with heavy-ion collisions at various accelerators (e.g., RHIC at the Brookhaven National Lab and the LHC at CERN). There the collision of heavy nuclei like Au and Pb at very high energies (200 GeV, up to about 5 TeV per nucleon respectively) creates tiny "fireballs" (some fm in extension) of very hot strong-interaction matter for a very short time (some fm/c) were the relevant degrees of freedom become quarks and gluons, the socalled quark-gluon plasma. This fireball rapidly cools down and undergoes transitions from a QGP to a hot hadron-resonance gas and is finally freezing out in terms of the known hadrons.
During it's lifetime the fireball also spits out lepton-antilepton pairs and photons, for which the medium is pretty transparent, and thus these "electromagnetic probes" provide some information about the spectral properties of their sources, which is the strongly interacting matter and thus one can learn about the deconfinement-confinement as well as the chiral-symmetry-restoration mechanism. For transparencies of some lectures, I've given to graduate students at some lecture weeks, see
November 25-26, 2015: Two Lectures on "Electromagnetic Probes in Heavy-Ion Collisions" at the "Graduate Days" at the University of Graz, Austria
Lecture 1: Electromagnetic Probes in Heavy-Ion Collisions I: Foundations [
pdf]
Lecture 2: Electromagnetic Probes in Heavy-Ion Collisions II: Phenomenology from SIS to LHC Energies [
pdf]
http://th.physik.uni-frankfurt.de/~hees/hqm-lectweek14/index.html