It depends on what you play. Many online games—including a large number of free-to-play titles and browser games—cost nothing to enjoy on a computer.
However, some games require a one-time purchase or a subscription, and certain titles add optional in-game purchases. So while plenty of online gaming is free, not all of it is. Clarifying which specific game you have in mind would allow for a more exact answer.