Affected by Brexit?
Each EU country has its own social security laws. The obligations and rights under these laws are the same for all workers in that country, whether local or from abroad.
However, EU rules coordinate national systems to make sure people moving to another EU country do not lose their social security cover (for example pension rights and healthcare) and always know which national laws apply to them.
Under EU rules, someone can be subject to only 1 country's social security laws at a time - so they must pay their social security contributions in that country only.
As a general rule, the laws of the country where the person actually works (as an employee or self-employed) apply, and contributions must be paid there. It doesn't matter where the person lives (for example if they commute) or where their employer is based.
There is an exception for workers that have been posted abroad for less than 2 years: they can stay insured and pay contributions in the country from which they are posted.
For people working simultaneously in more than 1 country, specific rules determine which country's laws apply and where they should pay contributions.