I want to masturbate with one of my friends. Is that wrong? How can I ask him if he does without offending him?
Yes, it is wrong. He ought to be very offended that you think of him in a sexual way.
It is wrong for two people, who are not husband and wife, to touch each other in a sexual way. Such is essentially what homosexuality is when done between people of the same gender and that is strongly condemned as a sin (I Corinthians 6:9-10).
Even if such touching was not taking place, we still have to consider that you and your friends are seeing each other sexually aroused -- not the accidental view of an erection, say in a shower, but a purposeful view where sexual activity is taking place.
The general rule since the fall of man is that a person doesn't expose their genitals to others. We make efforts to keep our privates private. Of course there will always be times when it can't be avoided, yet we should make efforts to minimize it. Being seen naked in front of others ought to trigger a sense of shame. "Your nakedness shall be uncovered, yes, your shame will be seen" (Isaiah 47:3).
Let me use the example of Ham (Genesis 9:20-27). Ham's father, Noah, sinned by making wine and getting drunk. Ham accidentally walked in on Noah while he laid naked in his tent. Rather than be embarrassed by the situation, Ham went to his brothers. We aren't told what he said, but it is likely he thought it was funny that their father was acting so poorly. I want you to particularly note Japheth and Shem's response. "But Shem and Japheth took a garment, laid it on both their shoulders, and went backward and covered the nakedness of their father. Their faces were turned away, and they did not see their father's nakedness" (Genesis 9:23). I'm sure that over the years there were many occasions when they might have seen their father without clothes. They could have just walked in and covered him up, but they were making a strong point. Their father, because of his drunkenness, was in an embarrassing state and they refused to see their father lowered in their eyes. Thus they went out of their way to make sure they didn't see Noah uncovered.
The implication in this passage appears that Noah wasn't just unclothed, but also sexually aroused. There are other passages that also connect the term "nakedness" with sexual activity (Leviticus 18:6-19).
It is improper to expose your sexual activity before other people. It should be reserved for you and your wife alone.