1606 - the National Flags of Scotland and England were united for use at sea (A problem arose, which flag should be hoisted on the king's ships. English sailors resented the Scottish colours and the Scots scorned the cross of St. George .), thus making the first Union Flag.
1707 - during the reign of Queen Anne, the first Union Flag was by royal proclamation made the National flag of Great Britain, for use ashore and afloat.
Because when the first Union Flag was created in 1606, Wales was already united with England from the 13th century.
How to fly the Union flag correctly
The broader (wider) diagonal white stripe should be at the top on the side of the flag nearest the flagpole.
The UK flag is NOT entirely symmetrical! You can rotate the flag and it still will be the right way up but you can't invert it (not refective symmetry).
Look at the white diagonals and you will see why.
When is the Union Flag Flown?
The Union Flag is flown on government buildings on days marking:
the birthdays of members of the Royal family,
The Queen's official birthday,
Remembrance Day and
on the days of the State Opening and prorogation of Parliament.
It is also flown on St David's Day (Wales), St George's Day (England), St Andrew's Day (Scotland), and St Patrick's Day (Northern Ireland).