IIRC, Han refers to the Chinese dynasty that ruled after the Qin dynasty and before the the Warring State period. After that, there were so many different dynasties that ruled China, so how come the Han name stuck?
You're right in thinking that the Han was a dynasty of China. It lasted from 206BCE to 220CE, and was an incredibly important dynasty in Chinese history in terms of scientific, cultural and political developments. Think of it as the Classical Chinese period.
The reason that we talk about 'Han Chinese' is because of the Han Dynasty's prominence in international and so people began to call themselves '漢人' (hànrén), 'The People of Han'.
Some groups of Southern Han peoples use a different phrase however, '唐人' (tángcháo) which means 'People of Tan' in reference to the later Tan Dynasty (618-907CE) which was another very important Dynasty.