Swap arises due to the overnight interest rates for each currency being different. Since currencies are always traded in pairs, you always need to borrow one currency in order to buy another, so it follows that you have to pay interest on the loan, but you also receive interest on the currency you are holding. If the difference between what you pay and what you receive is positive, then you are eligible for a net swap credit. If the difference is negative, that is if you pay more interest than you receive, then your account will be debited the appropriate swap amount.
Most brokers use interbank overnight rates for their base calculations, update them daily, and then skim a little off the top. Other brokers update their rates only from time to time, and others still don't bother with the idea of swap at all. You will notice a lot of brokers claiming to be swap-free in order to attract Islamic clients who are forbidden from engaging in interest-bearing deals due to religious reasons.
There are also differences between how brokers display swap (i won't get into details here). Most brokers apply swap daily at New York close, and triple the amount on Wednesdays to make up for Saturday and Sunday when there is no trading, but there are exceptions - Oanda being a notable one.
Hope that helps.