There’s various methods that aid identification, but I’d argue that the real method is how armies are set up – with battle lines, with plans, with command and control hierachies etc.
The people behind you and beside you are probably friendly. The people coming at you from in front of you are probably hostile. You’ll hopefully be told beforehand if bad guys are going to show up, and from where. You’ll also be told if a friendly unit is going to turn up at a certain time and thus to not worry about them. You won’t just be told to go to a place and shoot enemies, you’ll be told that e.g. scouts in the field identified an enemy at THIS LOCATION and go shoot that up. If you need to retreat through a place guarded by your friends you’ll radio on ahead and warn them you are coming through.
A lot of the time this is the only information you have to figure that out. For example during WWII radar would just give you blobs for planes, and you just have to try and guess if they are friendly or enemy. For much of history people didn’t even have uniforms. They made do.
This is indeed a huge problem in warfare. It has been a big problem forever, of course, but especially in modern high-speed dynamic warfare, where there often aren’t clear lines of engagement, where long-range weapons systems are extremely powerful, and consequently camouflage and force concealment is a top priority.
The US military’s solution is called “[Blue Force Tracking](https://en.wikipedia.org/wiki/Blue_force_tracking)” (because in traditional military planning, friendly forces are “blue” and enemy forces are “red”). The idea is that you put GPS radio signal markers on all of your friendly units, and then you can track them all on a big ol’ computer system and know where everything of yours is at all times, so you never get confused.
And of course, you track the enemy as well, through satellite and aerial imaging, signal intelligence and analysis (SIGINT in technical jargon), and every other tool to collect battlefield telemetry and intelligence.
When it all works right, it’s amazing and it wins you wars. Not only do you prevent friendly-fire accidents, but you can also coordinate and deploy your forces with much greater efficiency and speed, because you know exactly where everything is at all times. It’s a strategist’s dream.
Every country would like to do something similar, and tries their best with whatever technology systems they have. But of course the US has billions of dollars to throw around to make sure its systems are the best of the best.
Some people think the US is doing all this battlefield intel for Ukraine right now, which would certainly help explain why the Ukrainians have been so much better at coordinating their forces than the Russians have been. Top level people aren’t saying anything publicly about it, of course.
Reminds me of the movie Saving Private Ryan, there was a scene where the protanonists were running through a small French village during ww2. They were then spotted by a small group of ally soldiers that yelled out “thunder!” They then responded back with “flash!”. They obviously circulated commucation that would be their codeword for the day / week / month or whatever. Supposedly, in German these words to difficult to pronounce, hence they would be able to hear a faker easily.
In another scene, the same group of allies runs across town and suspect that someone is out there around the corner. They yell the same “thunder” repeatedly, until the commanding officer says “thunder or we will fire on you”.
They will obviously not fire on civilians, and is their duty to make sure of that first.
Friendly fire (shooting/shelling friendly forces) is actually a big problem up to this day. [Pat Tillman](https://en.m.wikipedia.org/wiki/Pat_Tillman) is a modern example that got a lot of attention.
We’re pretty good about not firing on friendly vehicles and aircraft since they look different, but positively identifying foot soldiers at distance (especially ones who don’t want to be seen) is hard.
It doesn’t seem like it should be that hard with modern optics and remote sensing technology, but one thing movies don’t convey about war is just how confusing it is. Everyone is scared and jumpy, and also often exhausted. The noise doesn’t help either, regular guns are like tiny firecrackers compared to artillery and bombs.
Oftentimes they don’t. Incidents of an army accidentally attacking its own units (sometimes called *friendly fire* incidents, because you’re firing at people you’re supposed to be friendly toward) constitute a major problem in war, and modern technologies have arguably made it worse.
This has led to many standards of identification over the years. Ancient armies used standards: banners or statues attached to long poles, so that a soldier could know where to find friendly units. Uniforms and camouflage patterns evolved along similar lines. Knights’ coats of arms actually served a similar purpose, since you can’t really tell what a person in full armor looks like. Knights would wear these emblems on their shields or other conspicuous places, partly so that friendly forces would not attack them.
In more recent years, radio beacons called IFF (Identify Friend or Foe) systems are often used, so that units can be sorted out from far away. That’s important for long-range missiles, artillery, or drone attacks, where the operator generally can’t see the target and has to rely on other forms of identification. But the beacons fail sometimes, and when they do, friendly fire incidents can happen.
Typically, units do not just roam around looking for trouble. There are specific missions, such as “Patrol through this valley, moving from here to here. We’re not sure what’s in there, but it is possible that some enemy squads are hiding in there. If you make contact, call it in; we’ve got battalion mortars ready to provide indirect fire support, and A Co. is positioned up on the ridge to your west and can provide additional support if necessary. Do not cross phase line blue; that is 2nd battalion’s area.”
Now if someone starts shooting at you, you shoot back. They’re enemy.
If you’re getting close to one of your own units, you will radio to them and let them know.
At night you have signals with IR lights on your night optics—maybe 1 flash is replied to with 3, or something like that.
If you’re operating near a line that is another battalion’s AO, you will absolutely never initiate contact with a force on the other side of the line. You don’t know what’s going on there. The other battalion may have set up an ambush or might be observing them for some reason. Call it in and wait for orders.
The reality is in combat you seldom see the person or force your fighting; further, most engagements are over some distance and each side is using cover and concealment to avoid being seen.
So to avoid friendly fire, in advanced militaries there is a detailed brief before a mission or movement. Part of the brief includes risk assessment and intelligence updates. The intelligence updates provide known locations of green forces and the probable locations of red forces.
Using this information, a unit is assigned a corridor for movement or assigned fields of fire for longer range systems.
That said, mistakes happen. Intelligence can be stale or bad, green forces can be somewhere other than where briefed. As others said, communication is critical and fortunately with modern comms it is easy to disseminate information real time especially GPS coordinates.
The leaders generally know where their own troops are, and they’ll order them to attack places where they think the enemy troops are. After that, troops generally find ways to identify each other by uniform and equipment. When they have time, they’ll use passwords and such, or ask for names and unit numbers that the enemy wouldn’t know.
There was a case during WWII where the Germans had a much better submachine gun than the Allies, and a group of Allied soldiers captured a supply depot and took a bunch of them. Later, an Allied mortar company heard the distinctive sound of the German guns firing close by and dropped mortar bombs on them until it stopped. The system doesn’t always work.
Today, countries do their best to make their uniforms different enough to tell, and they try to stay in radio contact with every other unit nearby, because neither side wants their people shooting each other. It will still happen, because war is chaotic, but they try.
Latest Answers