Mark Watney's crew made it back to Mars orbit to collect him on sol 549, which means that Watney spent 564 days, or approximately eighteen months, on Mars. After the first six sols, he spent this time all alone, although at certain points in the story, he was able to communicate with NASA authorities.
What was meant to be a month-long exploration of Mars turned into something much longer and more traumatic for Watney when a severe storm blew up on sol 6, forcing the mission to be abandoned. As the crew made their way from the Hab (which was their home on Mars) to the MAV (Mars Ascent Vehicle), Watney was struck by flying debris, which caused him to fall out of formation with his crew and collapse, unconscious. His crew mates, though devastated, thought he was dead, and returned to Hermes without him for their homeward journey.
When Mark awakes, he realizes the sickening horror of his predicament: he is alone on a godforsaken, unreachable planet with no way of letting anyone know that he is alive. However, through tenacity, strong-mindedness, and good humor, Watney manages to survive everything that Mars has to throw at him and make the long, difficult journey from Acidalia Planitia to Schiaparelli, where another MAV could be used to return him to orbit and to his crewmates on Hermes.