Number (multiple of 10) + 代 – age decade (e.g., 20代, 30代)
Number + 年代 – historical decade/era (e.g., 1990年代)
The suffix ~代 (だい) is attached to numbers to express age ranges (decades of life) or historical decades (time periods). It is one of the most common ways to talk about approximate ages or eras in Japanese.
When attached to a multiple of ten, ~代 indicates "one's ___ties" – the range of ages within that decade.
You can further narrow the range with 前半 (first half), 後半 (second half), 半ば (mid-), or 初め (early) / 終わり (late):
When attached to a year number with 年, ~年代 indicates a historical decade (e.g. "the 1990s").
Be careful not to confuse ~代 (だい) meaning "decade/age range" with ~代 (だい) meaning "fee" or "cost" (e.g. でんわだい電話代 = phone bill, しょくじだい食事代 = meal cost). The reading is the same, but the usage and meaning are different.