I've been there. The best thing I ever did was be 100% honest. My oldest was 4 when I divorced his and his brother's father. I explained it like I would any other relationship. I explained that having a friend meant you both liked each other and were nice to each other.
Once you can no longer like the person or be nice then you can't be friends anymore.
The biggest thing is to make sure the child understands it has nothing to do with them. On top of that making sure you don't down the other parent no matter how much they may be hated in the process or how bad they behave.
My ex husband use to talk bad about me to my boys. No matter how much he said I always kept my mouth shut and reminded my boys that grown ups can be grouchy sometimes. That is as far as I would take it.
My advice would be to be as honest as possible while reiterating the fact it is not their fault, they are loved by BOTH parents, and not to ever speak bad of the other parent even if you don't like them.