We derive an analytical approximation for the price of a credit default swap (CDS) contract under a regime-switching Black–Scholes model. To achieve this, we first derive a general formula for the CDS price, and establish the relationship between the unknown no-default probability and the price of a down-and-out binary option written on the same reference asset. Then we present a two-step procedure: the first step assumes that all the future information of the Markov chain is known at the current time and presents an approximation for the conditional price under a time-dependent Black–Scholes model, based on which the second step derives the target option pricing formula written in a Fourier cosine series. The efficiency and accuracy of the newly derived formula are demonstrated through numerical experiments.