Can you boot into macOS normally? If so, then create a bootable macOS USB installer using the instructions in the following Apple article:
Create a bootable installer for macOS - Apple Support
If not, then boot the Mac using Command + Option + R which theoretically should boot into the online installer for the most recent macOS installer that is compatible with that Mac. Unfortunately some Macs may boot to the online installer for the OS which originally shipped with the Mac from the factory.....using this key combination should still work at least to bypass the need to authenticate with an AppleID for an OS you never "purchased".
Another option would be to create a bootable macOS USB installer using another compatible Mac. We would need the exact model of this Mac in order to provide all your options for which other Mac models would be acceptable. At the very least generally a Mac model 2007 - mid2018 would allow you to create a bootable macOS 10.11 or 10.13 USB installer. If this old Mac is from 2013 to 2014, then you would have more options with models from 2018-mid-2021.
You can get the exact model by clicking the Apple menu and selecting "About This Mac", but if you cannot boot into macOS, then enter the system serial number on the check coverage page here (don't post the serial number on this forum since it is considered personal information):
Check Your Service and Support Coverage - Apple Support