No one knows for sure.
Some people believe they really lived that long.
Others believe that the Biblical writer exaggerated the ages of the patriarchs (or grouped them in a manner not obvious from the text so as to create centuries-long lifespans) in order to teach a lesson or get a point across.
Still others believe it was the result of mistakes in the copying of the text. When one compares the Massoretic text (Hebrew copy of the Old Testament) with the Samaritan text (Samaritan copy), you find that in many cases the numbers are off by exactly 100 years and, in general, the Samaritan text has shorter lifespans (although still ranging up into the 800s).