In 40 BC Herod was fleeing from the Parthians (the Parthian kingdom was in ancient Iran) and Antigonus of the Hasmonean dynasty (king of Judea from 40 BC).
Appreciating the strategic location of Masada, he sought refuge there with his family. He then had 800 of his best soldiers placed in the fortress and set out for Rome himself to get help. Soon after, the siege of Masada led by Antigonus began.
Upon his return from Rome, Herod gathered an army of mercenaries and Judeans and set out to liberate Masada. After conquering the fortress, already as king of Judea (since 37 BC), he decided to expand and fortify it.