Here's a more detailed explanation:
During the Battle of Baltimore in September 1814, British forces had succeeded in capturing Washington, D.C. and were poised to attack Baltimore. Fort McHenry was a key defensive point for the city and was subjected to a brutal bombardment by British ships for over 24 hours.
Throughout the night of September 13-14, 1814, Francis Scott Key, a 35-year-old lawyer, observed the battle from aboard a British ship where he was being held prisoner. As dawn broke, Key looked anxiously towards the fort, hoping to catch a glimpse of the American flag still flying. To his relief and joy, he saw the large U.S. flag, measuring 30 by 42 feet, still flying defiantly above the fort.
The flag's resilience in the face of overwhelming odds inspired Key to write the poem "Defence of Fort M'Henry" that same morning. The poem would later be set to music and become known as the Star-Spangled Banner, the national anthem of the United States.
To Key, the flag symbolized the perseverance, courage, and determination of the American people. It represented the nation's ability to withstand even the most daunting challenges and emerge victorious. The flag's presence over Fort McHenry became a symbol of hope and national pride, reinforcing the belief that the United States would endure as a sovereign and independent nation.