Psalm 23, “The Lord is my shepherd,” is arguably the most famous psalm in the Bible. It is labeled “A Psalm of David,” and many scholars believe that David wrote this psalm some time during the later years of his kingship.
David was probably born sometime between 1040 and 1030 BC. He was the son of Jesse of Bethlehem, and his family descended from the line of Judah, one of the twelve sons of Israel. The Bible tells us that as a young man, David was a shepherd. We read in 1 Samuel 16 that when Samuel came to anoint one of Jesse's sons as the future king of Israel, David was out in the field tending the sheep. God rejected all seven of David's older brothers but instructed Samuel to anoint David.
Yet David's reign would not begin for quite some time. Saul was still the king of Israel, and after David single-handedly defeated Goliath, Saul became extremely jealous of the young shepherd-turned-warrior. David had to flee for his life, and he remained in exile for many years, on the run from Saul, who was continually trying to kill him.
Finally, however, in 1000 BC, David became king over his own tribe of Judah. He extended his reign to all of Israel in 993 BC. It was some time after this, probably several years to two or three decades afterward in fact, when David wrote Psalm 23. Bible scholars have noted that the psalm reads as if an older man was looking back over his life and thinking about the lessons he has learned. The tone is calm and meditative, and David remembers his days as a shepherd with nostalgia and love. He recalls how God has always guided and protected him and how He has cared for all his needs, just as David himself used to care for his sheep. David died in 961 BC, still firmly trusting that God has always been his shepherd.