Short answer: molarity is moles ÷ litres. 5.844 g of NaCl (58.44 g/mol) in 0.5 L is 0.1 mol ÷ 0.5 L = 0.2 M. For dilution, C₁V₁ = C₂V₂: 10 ml of 2 M brought to 40 ml is 0.5 M.
Why the volume is the solution, not the solvent
Adding 0.1 mol of salt to half a litre of water gives slightly more than half a litre of solution, so the molarity is a little lower than dividing by 0.5 suggests. Volumetric flasks exist precisely because the distinction matters at the precision chemistry needs.
Worked dilution
You have 2 M stock and need 40 ml of 0.5 M. V₁ = C₂V₂ ÷ C₁ = 0.5 × 40 ÷ 2 = 10 ml of stock, then make up to 40 ml with solvent — 30 ml added. The calculator reports both the dilution and the solvent volume so the bench step is unambiguous.