The basic difference between a hat and a cap is a hat has a brim,a shaped crown and cap does not, most caps have a visor or peak and usually fit closer around and to the surface of the head.
Hats also tend to have a function, such as protection against rain/the sun, safety, military, religious or ceremonial reasons, caps are generally just leisure fashion statements.
However, you can find many hats and caps that blur the line I've tried to draw above considerably.
One thing however is almost always true caps are hats, but many hats are not caps.
Don’t say what about bottle caps they are not headwear unless you make a hat out of bottle caps that is.
Some common caps - Baseball Cap, Flat cap, Barge Cap, Garrison Cap, Sleeping Cap, Leasure Cap, Bathing Cap, Docker Cap
Somethings that are worn on the head that are not hats or Caps - Turban, Helmet, Bandanna, Hood, War Bonnet, Masks, Wig, Crown