Yes, in principle. Plenty of titles run on both macOS and Windows and support online play on either.
The catch is that cross-platform servers are not guaranteed. Some games keep Mac and Windows players in separate pools for balance or technical reasons, so two friends on different systems may not be able to join the same match. Check the specific game's documentation before assuming otherwise.