What's with the very slightly larger mass of the neutron compared to the proton? Neutron mass: 1.008664 u
Proton mass: 1.007276 u
Why the discrepancy?
On a related note, how does one go about measuring the mass of a neutron or proton, anyway?
 A: A recent paper [1] has computed the mass difference ab initio from the theory, using a technique know as lattice, where one writes the equations on a discretised spacetime (this is conceptually similar to what engineers do with finite elements method to study how a beam of metal flexes for example). They took into account 


*

*the contributions of electromagnetism and of the strong interaction,

*the difference of mass between up and down quarks,

*up, down, strange, and charm in the quark sea [*],


Their result is
$$m_n-m_p = 1.51(16)(23) \text{MeV},$$
to be compared with the experimental value,
$$m_n - m_p = 1.29,$$
with an error orders of magnitude smaller. This is pretty impressive: an accuracy of 390 keV, and according to the paper a proof that $m_n > m_p$ at the level of 5 standard deviations. Again, ab initio, just from the Standard Model.
The authors of that paper also give the respective contributions of electromagnetism and of the strong interaction. This is very interesting as the electrostatic energy, just based on the quark charges, would naively be thought to be negative for the neutron but zero for the proton, on average [**]. Their result is that


*

*$(m_n-m_p)_\text{QCD}=2.52(17)(24)$ MeV,

*$(m_n-m_p)_\text{QED}=-1.00(07)(14)$ MeV,


where QCD stands for Quantum ChromoDynamics, our best theory of the strong interaction, and QED for Quantum ElectroDynamics, our best theory of electromagnetism. So indeed, the different of electrostatic energy is in the intuitive direction I have just highlighted above. This is compensated by the contribution of the strong interaction which goes in the other direction. I don't have an intuitive reason for that to share.
[*] Protons and neutrons are made of 3 so-called valence quarks, but also of a "soup" of other quarks-antiquark pairs which is called the sea.
[**] The sum of the product of the charges are $\frac{2}{3}\frac{2}{3} + \frac{2}{3}\frac{-1}{3}+ \frac{2}{3}\frac{-1}{3}=0$ for the proton but $\frac{2}{3}\frac{-1}{3} + \frac{2}{3}\frac{-1}{3}+ \frac{-1}{3}\frac{-1}{3}=-\frac{1}{3}$ for the neutron.
[1] Sz. Borsanyi, S. Durr, Z. Fodor, C. Hoelbling, S. D. Katz, S. Krieg, L. Lellouch, T. Lippert, A. Portelli, K. K. Szabo, and B. C. Toth. Ab initio calculation of the neutron-proton mass difference. Science, 347(6229):1452–1455, 2015. arxiv.org/abs/1406.4088
A: We can write approximately assuming strong energy $E_s$ contribution  inside  proton and neutron is almost the same:
$m_n c^2 = m_d c^2 +m_d c^2 +m_u c^2 +E_s $
$m_p c^2 = m_u c^2 +m_u c^2 +m_d c^2 +E_s  +E_c $
in terms of quark u and d  masses and $E_c$ - electrostatic energy around and inside the proton, which can be calculated classically $E_c = \frac{3}{5} \frac{k e^2} {R} = 1 MeV $, and R=0.87 fm is charge radius from scattering experiments.
Thus we have
 $m_n c^2 -m_p c^2 $ = $ m_d c^2 - m_u c^2 - E_c $ = 4.8 MeV - 2.3 MeV - 1 MeV= 1.5 MeV
On the other hand we have $m_n c^2 -m_p c^2 $ = 1.3 MeV i.e very close (and quark masses are not know so precisely)  
A: Masses and coupling between quarks are free parameters in the standard model, so there is not real explanation to that fact.
About the measurment: you can have a look at this wikipedia article about Penning traps which are devices used for precision measurements for nucleus. Through the cyclotron frequency (Larmor factor) we can obtain the mass of the particle.
Edit: "A neutron is a proton + an electron" is a common answer to this question, but it is a totally invalid reasoning.
Both protons and neutrons are made of three quarks. The mass of the quarks is not known with enough precision, and even more important (and that's a why for the masses of the quarks), the interaction between them is responsible for the mass value to a much larger extend.
A: A proton is made of two up quarks and a down quark, whereas a neutron is made of two down quarks and an up quark. The quark masses contribute very little of the actual mass of the proton and neutron, which mostly arises from energy associated with the strong interactions among the quarks. Still, they do contribute a small fraction, and the down quark is slightly heavier than the up quark, which approximately accounts for the difference. (The masses of the up and down quarks, because they're so small, are not extremely well-measured, and detailed calculations of what the proton and neutron masses would be for given quark masses are difficult. So it's hard to be quantitative about the answer in a precise way.)
You can read a bit about the state of the art in calculations of the proton mass here: http://news.sciencemag.org/sciencenow/2008/11/21-02.html
