Forgive my ignorance.

What actually constitutes prostitution or is illegal? or at what point does it turn from legal consenting behavior to illegal behavior?

Hypothetically speaking I would think that it would be legal to spend time with someone and cuddle someone. I guess I am at a loss for when the act becomes unlawful or illegal.
What I am seeing online talks about penetration. What if a guy just wanted to cuddle and maybe sexually touch himself. Is that illegal?