In situ monitoring of the dislocation density during martensitic transformation, and annealing, of the martensitic stainless steel 17–4PH was undertaken using neutron diffraction. The dislocation density in martensite is seen to increase linearly from ?2 × 1015 to ?4 × 1015 m?2 during the transformation. In addition, the dislocation density in the parent phase (austenite) slowly increases from ?0 to 1015 m?2. Annealing of the newly formed martensite in the temperature range 500-700 °C leads to almost complete elimination of dislocations.