We analyze theoretically the formation of stretched Pd-nanowires and their interaction with hydrogen. In our approach, we simulate the nanowire stretching process using a first-principles molecular-dynamics method to obtain realistic atomic geometries of the contact in its final stages before the nanowire breaks. The electrical conductance of the nanowire is also calculated at each point of the deformation path. For the clean Pd-nanowire in the last stages of the deformation process we find that the nanowire develops, first, a one-atom-neck and, at the end, a dimer whose bond is finally broken. For these atomic configurations, the calculated electrical conductances are in good agreement with the experimental evidence. The interaction with hydrogen is analyzed adsorbing one or two H atoms on the Pd-nanowire for different configurations along the stretching process. In the case of one H atom we obtain geometries with conductances in the range 0.8-1.4G(0), while for two H atoms we find conductance plateaus with values ∼0.5G(0) and ∼1.0G(0). These results are in excellent agreement with the experimental evidence for nanocontact breaking in an H(2) atmosphere and indicate that the conductance peak around 0.5G(0) observed experimentally is associated with nanowires where two H atoms have been adsorbed.