Dobby was the downtrodden house-elf servant of the Malfoy family for many years, where he was subjected to frequent threats, humiliation, and abuse. Most house-elves seem to accept this as standard practice and do not seek to change it. Dobby, however, disliked his masters and sought to help Harry when he heard that they were plotting against him. His commitment to Harry's cause (and his hatred for the Malfoys) was enough to make him willing to do this… even if it meant ironing his hands. Harry (with some helpful advice from Dobby along the way) managed to thwart Lucius Malfoy's plan and even tricked him into giving Dobby a sock. The act of giving clothes releases a house-elf from servitude. Hence, Dobby was free.