In the summer of 1814 the British Empire and the US were into their 3rd year of war. Campaigns had raged back and forth with little lasting result on the US-Canada border in Upstate NY, and along the Great Lakes. The Royal Navy attempted to effect a blockade of key American ports, shutting down both merchants and Privateers raiding British shipping. The American Navy had fought a series of gallant single ship actions and punched above their weight, but had few ships and many were being run down and captured, or blockaded in port. But for Britain it had remained a secondary concern while it fought against Napoleon, who abdicated the first time in April 1814. Allowing additional ships and army units to be sent to America.
A plan which emerged was to attack the vulnerable key ports of the Mid Atlantic and Chesapeake Bay. British forces already controlled and raided much of the lower bay, making it difficult at best for ships to slip out of Baltimore, Annapolis, or Norfolk. Raids towards Norfolk and along the coast had been carried out, including the burning the town of Harve de Grace the year before. Reinforced, this joint Army-Navy force, under Admiral George Cockburn and General Robert Ross was ordered by theater commander Admiral Cochrane to launch a larger inland expedition.
Their orders were explicit:
You are hereby required and directed to destroy and lay waste such towns and districts as you may find assailable. You will hold strictly in view the conduct of the American army towards His Majesty's unoffending Canadian subjects and you will spare merely the lives of the unarmed inhabitants of the United States. (the commanders were also told that taking payment in return for sparing a town was acceptable).
The joint targets would be Washington, for the political impact, and Baltimore as a major port. Other cities considered for targets included Philadelphia, or New Orleans on the Gulf Coast. In the background too was a desire to meet in kind the burning of the Canadian town of Port Dover by American troops in May. While the overall goal would also be to distract from the buildup of forces in Canada for a major invasion from that theater.
A British force of about 4500 then was landed in MD and marched towards Washington. While nervous about being potentially cut off there was little initial resistance by American forces. Royal Navy forces also forced back what American naval forces were left in the region and worked their way up the Potomac to screen the landing force. On August 24 a scratch American force of Army, Navy, Marines, and Militia was brushed aside by the British at the Battle of Bladensburg. And the British column entered DC that afternoon into evening.
Targeted looting and destruction then began. President Madison's party had already fled to Virginia, Dolly Madison and the staff, including the family's slaves, saved some of the valuables and many fled as well. The British forces then ransacked the building, including enjoying the dinner that had been prepared before the evacuation, and set fire, gutting the inside but the exterior walls survived.
A similar story took place at the incomplete Capitol building. The South Wing was ignited, destroying among other things, the Library of Congress. The flames consumed much but again the exterior walls survived. Into the next day several other buildings were looted and burned, including the Treasury, War, and State Dept offices. The Navy Yard had been burned by retreating American forces. And Fort McNair had been evacuated, and was damaged when British forces accidentally set off left over barrels of gunpowder while trying to dump them down a well. The city while not totally burned, was in a very sorry state, with just about all the public buildings damaged in one way or the other.
But in the afternoon of August 25th a ferocious storm struck the city. Accounts differ but many report strong rains, winds, and even hurricane force winds and tornadoes! Cockburn's forces decided they had had enough and began the march back towards the Bay and their ships. At the same time British forces had worked their way up the Potomac and actually extracted payment in the form of merchant ships and food and other goods from Alexandria VA as ransom to not bombard the city. This force then also retreated back down the river several days later too.
And finally as part 2 of the operation the attack on Baltimore could begin. In mid September a landing force was put ashore at North Point while the naval forces would bombard Fort McHenry into submission. On September 12th 1814 the British landing force was met by a better organized and prepared American force. General Ross was killed early in the battle and while the Americans were forced to fall back and concede the the field, they did so in good order. While British casualties and now decapitated leadership meant the shore element waited for the naval element to breakdown the defenses and go from there. That of course would not happen as Fort McHenry survived a night of bombardment and had a very nice flag to put up in the morning, and after some additional maneuvering the British landing force withdrew.
As a final addendum many of the same British forces, reinforced again, were part of a task force led by Admiral Cochrane against New Orleans in December 1814. Which on January 8th culminated in the defense of the city by American forces under Andrew Jackson and a sharp bloody repulse by the British Army and again the death of their commander in General Pakenham.
FURTHER READING:
For some free reading on the topic you may be interested in the US Army's official history of the campaign: https://history.army.mil/html/books/074/74-5/cmhPub_74-5.pdf
While for an accessible book you might look at Lion in the Bay by Stanley Quick.