I don't understand why 老外 and 洋人 mean what they mean
老 (old) is a common word for making nicknames (indicates casualness, familiarity, or fondness). For example, you met someone and called him 李先生 (Mr. Lee) which is a formal address. Later you two became familiar with each other and you might start calling him 老李 instead, (similar to 'John' became 'Johny'  in English)
外 (outside) 國 (country) 人 (people) people
外國人 = foreigner
老外 is a nickname for the formal term 外國人 (foreigner). It can be people of any race and from any country
洋人 short for 西洋人 (西 = west, 洋 = ocean 人 = people ; 西洋人 = westerner)
When the Europeans came to China, they came from the west by sea and the Chinese called them 西洋人. It could be shortened to 西人 or 洋人. We no longer use the term 洋人 nowadays in day to day speech, but the term 西人 is still in use for 'westerner' (white people from the western world) among Cantonese speakers (Canton is a major entry point to China by sea)