Legal basis is one of the criteria for a lawful processing of data under the GDPR. The legal basis is stated in article 6 GDPR and in there are six available legal basis to motivate a processing of data with:
- Consent
- performance of a Contract (including taking steps to conclude a contract)
- Legal obligation
- Vital interest of the data subject or another individual
- Task of public interest
- Legitimate interest of the data controller
Which one that is the most appropriate depends on the context of your processing.
Note that public authorities most often cannot rely on legitimate interest as a legal basis.