Sarai and Abram tried to have a child, but they weren't successful and Sarai was beginning to feel desperate.
So she came to Abram and said to him: 'The Lord hasn't blessed me with a child. Sleep with my slave, Hagar, and maybe you will then have a child that I can call my own.' Abram also thought it was the best thing to do.

Hagar despised her mistress when she found out that she was carrying Abram's child.
Sarai couldn't miss the repulsion that Hagar had for her and spoke to Abram about it. He replied that Hagar was her slave and therefore can Sarai do with her as she sees fits. So Sarai started to treat Hagar very badly. She treated Hagar so badly that Hagar fled from her into the desert.

The Angel of The Lord furthermore said to her: 'I will multiply your seed exceedingly, that it shall not be numbered for multitude ... and you will have a son whom you must call Ismael, because The Lord heard your suffering.
And Ismael will be a wild man. His hand will be against every man, and every man's hand against him ... and he will live in hate of his blood relatives.
Hagar then called the Name of The Lord and said: 'You are the God that saw me, and here I saw Him who saw me.'
The fountain was between Kadesh and Bered.
So the fountain was named Beer-lahai-roi. It was situated between Kadesh and Bered.
And so did Hagar brought a son into the world for Abram, and he was 86 years old when Ismael was born.
Source: The Bible: Genesis 16