Actually the limit is usually set by the context (and sometimes, depending on the country, by the law).
You can't do the same kind of jokes at home with your kids, with friends, on a forum and at work.
Well... You can but you could face serious consequences - like getting fired for example.
As for comedians, they are getting paid by their audience for a kind of on-demand humour.
That's a whole difference story of course.
Louis CK could get in trouble for NOT being offensive.