Zelfde is always preceded by another determiner of some kind, usually an article or demonstrative. Certain combinations of these are written as one word:
From Middle Dutchselfde. This was formed from the older selve (modern zelve), probably with -de from some of the ordinal numbers. Further etymology is as for zelf.