Here’s the basic port/starboard rule from the 2021 Racing Rules of Sailing (RRS):
When boats are on opposite tacks, a port-tack boat shall keep clear of a starboard-tack boat.
Two definitions in the RRS tell you how to know which tack you are on.
Tack, Starboard or Port A boat is on the tack, starboard or port, corresponding to her windward side.
That’s easy, but how about when you are running downwind?
Leeward and Windward A boat’s leeward side is the side that is or, when she is head to wind, was away from the wind. However, when sailing by the lee or directly downwind, her leeward side is the side on which her mainsail lies. The other side is her windward side….
All of the boats drawn below are on starboard tack. The arrow indicates the wind.

Before the next race while you are sailing your boat near the starting line, think about which tack you are on both coming toward you and sailing away. I’ll show typical port-starboard situations in a couple of weeks.
Richard adds: A definition of port/starboard that I’ve seen is port is when the mainsail is on the starboard side and starboard is when the mainsail is on the port side. This covers both up and downwind (wing and wing).