Edit
The banner of the Kingdom of Sweden.
The design of the flag is a heraldic-right-shifted (towards the flagpole) golden-yellow cross on a light middle-blue background. The exact dimensions of the flag are 4-2-4:5-2-9 for a total proportion of 10:16, which is number that approaches the golden ratio. Key things to take note of is that the blue fields towards the flagpole are not square and the thickness of the cross is half of the blue fields' height.
Legends say that Eric IX ("Eric the Holy") saw the golden cross in the sky when he landed in Finland during the first Swedish crusade in 1157. He took it as a sign from god and made it his flag. However, the legend doesn't match up to the historic usage of the flag nor is there evidence of such a crusade. More likely, the Swedish flag was created in resistance to Denmark -Sweden's arch-nemesis since ancient times- and took inspiration from their flag, Dannebrogen. The blue and yellow were already commonly used as Swedish colours, for example in tre kronor which is the national coat of arms.
There is a military variant of the flag which is significantly longer and has the end cut into three tongues. The proportions on this flag is 1:2. The tongues are cut from each field with the outer edges of the blue fields remaining straight and uncut. The length of the tongues is such that the uncut part of the flag has equally much blue on each side of the cross. The proportions are thus best described as 4-2-4:5-2-5-8 where the last number is the tongues. This flag can have white 5-pointed stars in the upper right field to denote admiralty rank and are only used on navy vessels. Other versions exists with a white square on the centre of the cross. If the square extends outside the cross and has the coat of arms of Sweden, then it is the flag of the King and Queen. Other members of the royal family uses a variant with a smaller square that doesn't extend outside the cross and instead carry a different insignia on it.
In civilian usage the flag was almost exclusively used at sea. The biggest breakthrough towards flying the flag more was made on the 6th of June in 1916 when "Day of the Swedish Flag" was celebrated for the first time, a day which unofficially became Sweden's national holiday until it was officially recognized in 1983.
There are no strict laws governing the flying of the flag, except for the royal and military variants. Everyone is allowed to fly the flag whenever they want and for whatever reason that they find worth flying it for. However, there are several traditions and "unwritten rules" which are good customs to follow, the most important of which is to not fly the flag at night and to not fly the flag for no reason. The most common occasion that Swedes fly the flag for are birthdays and midsummer's eve. Swedish calendars also come with special "flag days" marked, which are good days to fly the flag on such as royal birthdays and historical anniversaries.