Upper Egypt and Lower Egypt used to be two different kingdoms, but they were unified around 3100 BC. This marked the end of prehistorical Egypt and the beginning of the Early Dynastic Period or Archaic Period (around 3150 BC to around 2686 BC). Egyptian history and tradition credits Menes as the kind who unified the two regions and founded the first dynasty.
The relation between the regions' terminology and the Nile is geographical: Upper Egypt was the southern, highlands region, from which the Nile flows northwards towards the flatter, coastal Lower Egypt, and into the Mediterranean Sea. It might seem counter-intuitive for Upper Egypt to be "below" Lower Egypt on a map, but unlike the Mississippi for example, the Nile flows south-to-north.