After America gained its independence during the Revolutionary War, its relations with Britain were often strained at best. This was especially true when the British went to war with France starting in 1793. The British began to blockade many European ports in order to cut off American neutral shipping to France. This resulted in British seizure of much American cargo and ships and therefore was extremely unpopular with the Americans, who clamored for retaliation of some sort or another. Although the Washington and Adams administrations successfully eased tensions with the British, whose war with France ended in 1802, when Napoleon came to power in France and the wars started again in Europe America was no longer able to remain neutral. Starting in about 1805, the British began to tighten their blockades and intensified their seizures of American property until they issued the 1807 Orders of Council, a decree that severely restricted the ability of neutral nations to conduct trade with the European continent. None of the seizures of American property incited the popular imagination quite so much as the British practice of stopping American vessels in order to look for deserters from their own navy, though. They often made mistakes concerning identities of various sailors, however, and it is estimated that the British impressed around six thousand men into their navy who had never served in the British navy before.
Americans demanded that something be done. Jefferson and Madison, the presidents during this period, tried to use economic coercion on England, and a number of measures were passed limiting American trade with the British. The most extreme measure taken was the Embargo Act of 1807, which made it illegal to ship anything across the Atlantic, limiting ship traffic to the coastal variety only. This act was repealed a year later without the British having taken much notice. The British refused to change their policies, and a strong pro-war movement began to build in the United States, known usually as the War Hawk movement. This movement not only favored the American right to ship products and people without losing them all to British confiscation, but they also had other grievances with the British. They believed that the British were inciting natives around the Great Lakes (who had grievances regarding their claims to land in the American West that the United States had not addressed) to attack Americans and that Britain represented a major threat to the concept of republican government. There was also a certain amount of discussion about conquering Canada and making it into an American territory in order to reduce British influence in North America and also to expand the United States. Support for the war was not universal in the legislature by any stretch of the imagination, being limited primarily to young lawmakers of the Democratic-Republican party from the West and South, opposed by Federalists from New England whose constituency depended on trans-Atlantic trade that would be severely hurt by war with England. There were even riots in Baltimore during the summer between the two sides that didn't really end until September. Although divided on the subject, America still declared war on Britain and its Indian allies on June 18, 1812.
The first year of the war went horribly for the Americans. They had planned to invade Canada from three directions: along Lake Champlain, north from Detroit, and near Niagara. The Detroit offensive backfired badly, and Detroit itself was made to surrender to Britain on August 18th. The Americans were then defeated at the Niagara front in October, and American invasion forces at Lake Champlain withdrew without even engaging Britain. The naval war went a bit better. The American ship Constitution defeated the British Guerriere in August, followed by the American capture by the United States of the British Macedonian. The Constitution also defeated the British ship Java off the coast of Brazil. Unfortunately, in spite of these victories and successful forays by American privateers against British ships, the British blockaded the American coast and were able to raid it at their leisure.
In 1813, the Canadian invasion went a little bit better with American victories at the Battle of the Great Lakes and the Battle of the River Thames in Canada, but the Americans were still frustrated in their attempts to gain a real foothold. Things got worse in 1814, though, when France began to crumble, allowing the British to devote more of their formidable resources to crushing the American forces. Although the Americans repelled British advances from Canada at the Battles of Chippawa and Lundy's Lane, they were unable to successfully defend Washington itself, which the British occupied in August. As other authors have noted, the British burning of the public buildings of the city is the reason why the White House was renamed as such. America was generally in a bad way, with the British blockade strangling the economy, the U.S. public credit collapsed, the leadership ousted from its capital, and New England Federalists becoming more and more vocally opposed to the war. America needed victories, and it was lucky enough to get them. The British army occupying Washington was successfully driven from Baltimore when they tried to invade, and another British invasion force was routed at the Battle of Plattsburg Bay as it tried to invade along Lake Champlain. It has been said that this defeat was the one that made the British tire of the war, since they were made to believe that reconquering America would be impossible. The two countries had been negotiating a peace settlement in Ghent, Belgium, and it was signed on Christmas Eve of 1814. Word of the treaty did not reach America for quite some time, however, and Andrew Jackson had led his army to a crushing victory over the British at New Orleans by the time it did. Because Americans heard about the war ending and Jackson's victory at the same time, the two events were conflated innacurately, leading to Americans thinking that they had won a war that had in fact been stopped primarily due to the British losing interest.
Sources: http://members.tripod.com/~war1812, http://www.militaryheritage.com/1812.htm, and the History Channel.