An answer on this site claims that the first flags were heraldic flags used in battles. But when was this, and for which nations?
The Shahdad Standard is currently the oldest known flag in the world. The squared bronze flag from Shahdad, Iran dates back to about 2400 BC.
It bears many of the hallmarks of a modern flag:
The second source describes the emblem a little different:
I have a different answer for this and just sharing what I know about this, it also does not mean the flag was invented in India, but in India more than 5000 years ago, flags were used. Perhaps it could be the first flag.
In the epic Mahabharatha, for the Kurukshethra war between pandavas and kauravas, flags were used.
The Embelem on the flag of the arjuna chariot was Hanuman. The flag was called "Kapi Dhwaj". There is a specific description about this flag in Mahabharatha, since it has a certain importance.
If we come to Vedas, in the Atharva Veda it is mentioned that Indra had a Flag of his own called 'Indra Dhwaj'. There is no hard pictorial evidence for these references but the abundant use of the Sanskrit word 'Dhwaj' in almost all the scriptures is nothing but a flag which is attached to either the king's Chariot or at the entrance of his palace.
So this answer tries to put some historical input from ancient India to this question.
This depends on what you accept as "flag". Arguably the first flags were spears with certain signs attached to them such as strips of clothes. Then appeared various specially designed solid signs with figures and inscriptions. Then spears with painted matter attached to them.