3 way switch with 3 black wires
It really matters how wires are grouped into cables or conduits.  

One black is supply.  It is always-hot.   It is probably grouped black-white-copper. 

Another black is simply passing power through to something else.  You may notice with the switch removed, something else doesn't work.   That's where that black goes.   It is probably grouped black-white-copper. 

The remaining black, and the red, are 3-way messengers going to the other 3-way switch.  They work together as a matched set, and they are interchangeable.  Think of them as a matched set.   They will be grouped black-red-white-copper. 

Your 3-way switch will have a ground screw.  It will also have 3 other screws, with one an odd color compared to the others.  The two same-color screws are the messengers. 

That leaves the "always hot" black wire, and the black wire going to the "something else".  Those need to be joined to each other, and connected to the remaining screw on the switch.