There are a few countries where it is more acceptable, but to say bdsm is illegal lacks nuance, and understanding as to what exact activities are ok legally and what isnt legal. To just say bdsm is illegal isnt accurate. To say some, many activities found in the bdsm world is illegal is more accurate.
There are activities that giving consent for, or having consent to do is not a cover re being prosecuted, and some activities that are acceptable. In many countries anything that leaves serious marks, or marks that dont fade quickly is viewed as assault, and the State will say one cant consent to assault. Sadly though the law on this can be very vague. Hows this for guiding legalese.... marks that are of a trifling and transitory nature. What exactly does that mean? In America some States have it that anal sex and giving a blow job is still illegal, things that elsewhere are viewed as being perfectly ok, if done consensually. So what cover is there re using whips, floggers etc, never mind some of the more extreme activities that happens under the bdsm umbrella, if activity found in many peoples vanilla sex lives is illegal.
Classic cases re this sort of thing are Operation Spanner (1), and Rv Brown (2), and its well worth reading up on these and what is and isnt ok round the world, particularly where you live or travel to for play.
https://en.m.wikipedia.org/wiki/BDSM_and_the_law
Germany seems to be the most friendly towards bdsm practitioners. For those in the UK its well worth having a read of the BackLash (3)website and Myles Jackmans (4) to learn more.
(1)
https://en.m.wikipedia.org/wiki/Operation_Spanner
(2)
https://en.m.wikipedia.org/wiki/R_v_Brown
(3)
https://www.backlash.org.uk
(4)
http://www.mylesjackman.com