Open system preferences > click on Apple ID icon > under password and security click on edit ( this is for Mac OS catalina 10.15.4 ) , for previous versions of Mac you have to open system preferences > click on iCloud
Can you see the trusted numbers and are they verified ( it depends upon you to add a mobile number or a landline number to get the code ) , if they are not added and verified click on plus sign add them and verify them , if you use landline number verify it .
It will prompt to enter admin password .
Enter the number , use any desired option and click on continue .
When ever you enter iCloud it will prompt to enter admin password , don't enter it rather click on cancel , enter Apple ID and password manually and click on enter key .
A map window will appear , click on do not allow , next prompt will be to change apple id password , click on don't change , next will be a six digit code displayed , if the iPhone and Mac are signed in with same Apple ID and password , the code will be displayed on the trusted device that is been added ( if you had two two device mobile number / landline number ) , there is choice to click on any one to get the code .
Suppose the Mac and iPhone are not signed with same Apple ID and password on the same network , yet the trusted numbers are added / verified .
If you click on didn't get a verification code , again click on use phone numbers , option appears verify you identity , click on right arrow the code goes to the desired number .
Read these articles https://support.apple.com/en-in/HT204915
https://support.apple.com/en-in/HT204974