Volunteers placed the flags on a grassy slope overlooking a main road in the capital early on Sunday.
Covid-19 has claimed a confirmed 31,232 lives in Spain. But difficulties in testing at the start of the crisis mean many more victims are likely to have gone unrecorded.
“I think it is a beautiful homage to the victims, a lot better than the homage that was given by the prime minister,” 62-year-old retiree Honorio Hernandez said.
“I have been in the Arlington National Cemetery and this reminds me of that. These people at the very least deserve this, if not much more.”
Elsewhere in Madrid, over 1,000 protesters rallied to demand a more vigorous response to the growing second wave of the coronavirus.
Madrid has become the epicentre of the rebound of the virus in Spain, once again the worst hit country in Europe.
Spain has 319 cases per 100,000 inhabitants over 14 days, while France has 229 cases and the UK 96.