Datasheets, experience, schematic of the board the device is fitted to, all useful.
Logic function chips are fairly easy to substitute unless it's being used on the ragged edge of the specification or is even being used for some non obvious function (74LS logic chips being used as RF amplifiers for instance)
Some chips you'll never get a substitute for, even when you can buy the chip they are programmed at factory and you can't get the code or the programmer is ridiculously expensive.
many analogue chips were multi source and available under different part numbers (LA1230, CA3089 and a 3rd part I can't remember the number of are pin and function compatible for instance), yet more chips you can replace with near equivalents or upgraded versions with minimal modification of the circuit.
Google will get you so far and you'll find you get better at finding substitutes as your experience grows, if you've done your research and haven't got anywhere then come and ask in here, people will usually help if they can and may even off the parts you need.