I'll try to offer a slightly more "formalistic" explanation.
"Долго" refers to a long stretch of time. How long, and up to which point, depends on the context.
"Недолго" is a short stretch of time.
- "Надолго"/"Ненадолго"1 is for that stretch of time, and usually expresses intention.
"Давно" is a point in time long in the past.
"Недавно" is a recent point.
- In practice, especially in negative sentences and/or in present, "давно" implies since that point, and thus is semantically similar to "долго".
Let's make examples. Some of them will be less commonly used, but they all work.
Он долго живёт в этом доме
He lives in this house for a long stretch of time [up to now, because it's in present].
Он давно живёт в этом доме
He lives in this house since long in the past [and up to now].
The meaning is indeed very similar, if not identical. But let's turn it into past:
Он долго жил в этом доме.
He lived in this house for a long stretch of time [but doesn't now].
Он давно жил в этом доме.
He lived in this house at some point long in the past [i.e. long time ago]. [And he doesn't for a long time already].
Now the difference is substantial.
Let's use "надолго". "Надолго живёт" doesn't work well together, because the word implies intention, but we can use it like that:
Он надолго поселился в этом доме.
He settled in this house and intends to live there for a long time.
A very blunt example:
Это было давно.
It happened long time ago.
Это было долго.
It lasted a really long time.
This is [here to stay] for a long time.
1 There are two slightly different expressions "ненадолго" and "не надолго". Let's leave it for another time. Also, logically, "на недолго" should exist, but it doesn't.