1801, “a story of a house,” from Scottish flat “floor or story of a house,” from Old English flett “a dwelling, hall; floor, ground,” from Proto-Germanic *flatja-, from suffixed form of PIE root *plat- “to spread.”
The meaning “floor or part of a floor set up as an apartment” is from 1824. Directly from flat (adj.) come the senses “level ground near water” (late 13c.; late 12c. in place-names); “a flat surface, the flat part of anything” (a sword, etc., late 14c.), and “low shoe” (1834).
https://www.etymonline.com/word/flat