For centuries only one of these words existed in English, and it was the one that is used to describe people and things that hang stuff, and devices from which stuff hangs or is hung, as well as historically and occasionally stuff that, itself, hangs.
This is the word that comes directly from the verb hang and has the predictable suffix to prove it: it's hanger. We've got picture hangers and shirt hangers and wallpaper hangers. There are likely hangers in every house in the United States, as well as in a great many of the nation's stores. The word's roots are in Middle and Old English. Hang dates to before the 12th century; hanger is of 15th century vintage.
Hangar, on the other hand, is a relatively recent import to the language with narrow application: it typically refers to a building where aircraft are stored. Hangars are not found in houses and are rare even in back yards. We know of no stores in which hangars are used.
Hangar is of 19th century vintage, and it comes to English by way of French. In earliest English use, the word referred to a shelter or shed. Before people flew, a few (seemingly chiefly British) English speakers put their carriages in hangars; we like to consider the word as having been in the right place at the right time and with the right function when aviation, er, took off, but the word wasn't welcomed warmly by all, ostensibly because of its pronunciation:
The American public has got accustomed to calling an automobile station a garage with more or less variety of pronunciation, but when it comes to calling an aeroplane shed a "hangar," just because the English call it that, the good old English word "shed" will have to do. "Hangar" in French isn't so easy to pronounce as it looks.
— The Jasper (Indiana) Weekly Courier, 29 Apr. 1910
Eventually English speakers decided they could pronounce it just like hanger, setting off a chain of events that brought us to the inevitability of this very article.
Regardless of all that, though, the crux of the matter is this: use hangar for the place where aircraft are kept; like the words aircraft and airplane, it has two A's. Use hanger everywhere else.