Funding on happens every 1 hour at 00:00 UTC, 01:00 UTC, 02:00 UTC,... and 23:00 UTC.
Traders will only pay or receive funding if they hold a position at one of these times. If traders close their positions prior to the funding periodic payment then they will not pay or receive funding.
The funding traders pay or receive is calculated as follows: Funding = Position Value * Funding Rate
For instance, if a trader holds 200 BTCUSDC contracts, funding is charged/received with respect to the notional value of those contracts, and is not based on how much margin one has assigned to the position.
When the Funding Rate is positive, long traders pay short traders. When the Funding Rate is negative, short traders pay long traders.