A Credit Default Swaps (CDS) is a derivative to transfer default risk from one party to the next. The default protection is granted on the reference entity which can in principal be any entity, for example a single company, a group of companies or even a country. The protection buyer makes (quarterly) payments as compensation for the protection until either the end of the contract or the moment of default of the reference entity. This structure results in the pricing of this leg containing a part for the value of the payout in case of default and a part for the accrued premium until default. This side of the swap is called the premium leg.
The protection seller pays out a fixed amount in case of default of the reference entity. This amount is usually quoted as the notional amount times a recovery fraction. This side of the swap is called the protection leg.
To get a feel for the pricing of these kind of swaps please consider the simple attached example based on the book of Hull. In this example the CDS price is computed based on deterministic default probabilities and a fixed interest rate. To get a more realistic pricing, we could change the fixed interest rate with an interest rate model and the deterministic default probability with a stochastic model. However, that aside, we think this example gives a good basic understanding of how a CDS works.
The CDS example spreadsheet is available here : cds example