The recent Netflix movie The King shows the battle of Agincourt, and in the opening stages a large skirmish between two seemingly identical groups of men at arms takes place. How would these men, in full plate, be able to tell who they were actually supposed to attack?
While I haven't seen the recent Netflix movie you referred to, Hollywood does like to depict pre-gunpowder warfare as an acrobatic melee of pirouetting, hacking, and slashing. For good measure, a dose of "shaky cam" can be used to mask any imperfect choreography, while in other cases villainous goons might patently stand in a circle to attack the main character one at a time.
In such circumstances it is, as you have already ascertained, impossible to distinguish friend from foe.
So it is fairly understandable that this this scenario is something that any medieval or early modern military leader would want to avoid desperately. Indeed (save for rare exceptions) the side which was best able to maintain a disciplined formation in good order would be the side which carried the day. Ranks breaking and soldiers forming smaller groups is a sign that things are going very bad very quickly. Often, it was when one side broke ranks and fled that the majority of casualties would be sustained.
It is also true that most of the planning and execution of military campaigning did not concern itself with the field of battle. Set-piece battles, while certainly more interesting to dramatize in literature and film, were incredibly risky affairs that prudent commanders would want to avoid (because a smaller, weaker force will never engage a larger one unless forced to, almost all battles only ever emerged when both sides felt they had a good chance of winning). Thus raiding, pillaging, laying siege, and controlling strategic locations were more often then not the primary and decisive factors in a military expedition (many military commanders were influenced by the Roman author Vegetus, who advocated for this variety of military strategy; many others adopted these strategies out of convenience).
In a scenario where a commander has sent out several raiding parties it is easier to conceive opposing forces skirmishing in a less disciplined context, but this too would be the result of a grave error. When raiding and pillaging supplies military commanders needed to ensure they could realistically recall their raiding parties in time to assemble for battle should the need arise.
There could, of course, be scenarios where some contingent or other of an armed force might be deployed in a looser manner. Famously, at Agincourt English archers were deployed on the wings and fell upon the French as they fled. Cavalry too was more mobile as a matter of course, but even in a maneuver to flank and charge at an enemy from behind there is strength in numbers: a since man on horseback might spear an enemy, but is then isolated and can be easily pulled off his saddle. A line of men on horseback lined up knee-to-knee is much better at repeatedly charging at an opponent.
But you don't have to take my word for it: in this sub's "Ask Historical Figures" feature last weekend, u/Henry_V_Rex himself offered this comment on how he would distinguish friend from foe on a battlefield.
I'm not a military historian; I'm much more interested in economics. But in many instances, military organization could be said to be a consequence of economic organization: Very rarely could people fight alongside each other if they didn't have strong ties in place. In a time before professionalization, it was often these ties which determined the strength of an army's discipline. The most well-known of these could be a baron or earl fighting alongside his vavasours and retinue, who would all recognize the same banner and know each other's coats of arms, with strong social ties born out of economic interdependence, familial ties, and participation participate in civic as well as religious ceremonies together. But even at other levels of the social ladder, military training and recruitment (especially in cities) would be handled by parish, professional, or civic organizations. Here too, each man would know to recognize the banner of his city, neighborhood, or guild, as well as have close ties to the men standing at his side.
This is a common question but, fortunately /u/Henry_V_Rex, the man himself, came back on Dia Los Muertos to answer your question