One of the most frequent things I find myself writing on students' manuscripts is "Who says this?" I did a big post on writing dialogue a couple of years ago, so this is a round-up of solutions to this specific problem.
Start a new paragraph when the speaker changes. This doesn't mean that every speech must have its own, standalone paragraph, separate from any narrative prose, and it can make the narrative feel very choppy if you do.
If the reader has to stop work out the speaker, or is wrong-footed to find they've been "hearing" the wrong speaker, you've failed as a storyteller.
We're not writing a script for actors: dialogue and narrative are all part of the same medium, so they need to flow one into the next. So you'll often want to ...
... Connect the speech to an action by the speaker. The convention is that the grammatical subject of the narrative sentence is also the speaker of any dialogue, if they're in the same paragraph. If the speech is a standalone paragraph, then there's no such anchor for the reader.
Differentiate characters' voices. A radio drama producer I know takes every script and puts a ruler over the left-hand margin, where the characters' names label each speech. If she can't then tell who says what, she rejects the script. But you can be quite cold-blooded and deliberate in maximising the differences between characters' voices.
Use speech tags. I said, she says, they will say, are almost invisible, fancier speech tags are much less so, and some I see are truly awful. More on speech tags here. But if every speech has a tag (particularly if they're always in the same place in relation to the speech itself) even said will start to stick out .
If the reader needs an anchor, they need it soon: a good rule of thumb is to give the reader that handhold - an action, a speech tag, a name spoken - no more about than a line and a half after the beginning of the paragraph.
In a two-handed conversation you probably need an anchor about every five speeches. You will need more if there are more speakers, so it's worth developing a repertoire of anchors and where to put them:
"What do you mean?" I said. "You can't do that!"
Sally poured water onto the coffee. "Why not? Who's to stop me?"
"Oh, don't be ridiculous, the pair of you!" Yousuf burst out, but he didn't look particularly exasperated.
Sally muttered that she wasn't going to be told what to do by a pair of jumped-up adolescents, then pressed the coffee-plunger so hard that hot water and grounds slopped out over the counter. "Now look what you've made me do!"
I said as calmly as I could, "Never mind, Sally. I'll get a cloth."
Starting the line with a speech tag guarantees that the reader will hear the right speaker:
Andy said, "You can't know that it was Gerry. It might have been anyone."
But my sense is that you don't see this so much now, though I'm not sure why. For what it's worth, I chiefly do so when I'm using reported speech:
Andy said that no one could know it was Gerry: that it might have been anyone.
Or I move it a little way in, which to my ear gives the whole line more dynamism and drama.
"You can't know it was Gerry," said Andy. "It might have been anyone."
If one speaker quotes someone else's speech you need to demarcate that speech-inside-speech with different speech-marks:
‘Well, of course I said to him, I said, “Why don’t you pick on someone your own size?” And of course he just stormed off, didn't he. Couldn't handle being told off, could he!’ (normal UK book practice)
“Well, of course I said to him, I said, ‘Why don’t you pick on someone your own size?’ And of course he just stormed off, didn't he. Couldn't handle being told off, could he!” (normal US practice, and normal UK magazine pratice)
or you could use reported speech:
‘I said to him, I said, why didn’t he pick on someone his own size. And of course he just stormed off.’
Don't forget that reading aloud can help highlight the who-says-what problems.