Abraham was chosen for the example here, that one is not justified by works, but rather through faith because he was a Jew by ancestry and was respected by all. It is true that Abraham, if judged based on his good works, would prove to be righteous, because he had reason to boast of his good deeds. I like how Paul uses an example that we can relate with about works and wages. If salvation were based on works, then God would 'owe' us salvation based on our good works. It would be like an employer paying someone their wages. However, God makes it clear in the story of Abraham that it is not by works but by faith. After God told Abraham that his descendants would be innumerable, Genesis 15:6 says, "Abraham believed God and it was counted to him as righteousness." The faith that Abraham had in God saying his descendants would be innumerable is magnificent, because Abraham was almost 100 years old, and Sarah was close to the same age and had never been able to conceive of a child throughout her 'younger years'. How would an old, barren woman be able to conceive? Because that was the promise of God to them, and God's plan prevailed through His power. God's covenant with Abraham is in Genesis 17:4-8: "Behold, my covenant is with you, and you shall be the father of a multitude of nations. No longer shall your name by called Abram, but your name shall be Abraham, for I have made you the father of a multitude of nations. I will make you exceedingly fruitful, and I will make you into nations, and kings shall come from you. And I will establish my covenant between me and you and your offspring after you throughout their generations for an everlasting covenant, to be God to you and to your offspring after you. And I will give to you and to your offspring after you the land of your sojournings, all the land of Canaan, for an everlasting possession, and I will be their God."
Read verses 16-25, I think they speak for themselves:
That is why is depends on faith, in order that the promise may rest on grace an be the adherent of the law but also to the one who shares the faith of Abraham, who is the father of us all, as it is written "I have made you the father of many nations"- in the presence of the God in whom he believed, who gives life to the dead and calls into existence the things that do not exist. In hope he believed against hope, that he should become the father of many nations, as he had been told, " So shall your offspring be." He did not weaken in faith when he considered his own body, which was as good as dead (since he was about a hundred years old), or when he considered the barrenness of Sarah's womb. No distrust made him waver concerning the promise of God, but grew strong in his faith as he gave glory to God, fully convinced that God was able to do what he had promised. That is why his faith was "counted to him as righteousness." But the words "it was counted to him" were not written for his sake alone, but for ours also. It will be counted to us who believe in him who raised from the dead Jesus our Lord, who was delivered up for our trespasses and raised for our justification.