This paper considers the valuation of a CDS (credit default swap) contract. To find out a more accurate CDS price, we work on an extended Merton's model by assuming that the price of the reference asset follows a regime switching Black–Scholes model, and moreover, the reference asset can default at any time before the expiry time. A general pricing formula for the CDS containing the unknown no default probability is derived first. It is then subsequently shown that the no default probability is equivalent to the price of a down-and-out binary option written on the same reference asset. By simulating the Markov chain with the Monte-Carlo technique, we obtain an approximation formula for the down-and-out binary option, with the availability of which, the calculation of the CDS price becomes straightforward. Finally, some numerical experiments are conducted to examine the accuracy of the approximation approach as well as the impacts of the introduction of the regime switching mechanics on the CDS price.