The connection between philosophy and science is multifaceted and complex. Science has a philosophical basis at its very core, and philosophy often uses scientific rigor in its methodology. Most people think of science as a physically justified type of knowledge, but many types of science are theoretical. Philosophy is often thought of as purely existing in the realm of thought, but some aspects of philosophy are used in math, language, and other disciplines. There are many ways in which philosophy and science relate, and the specific relation depends on the context.
People often do not realize that science relies on a view of the world that is itself a philosophy. Humans tend to see the world as a series of causes and effects over time, and this basic philosophy is evident in the way in which scientific observations are encoded in scientific theories. It is possible to think about scientific processes deterministically or even through other perspectives. The way in which people philosophically believe the world works affects science drastically.
Philosophy often seems to exist purely in the mental realm, but one important connection between philosophy and science is the rigor with which both disciplines evaluate hypotheses. Both scientific hypotheses and philosophical arguments must be evaluated against all other possible claims. Some types of philosophy are less rigorous than science, but the idea that a proposition can be challenged and tested is important to both philosophy and science.
In ancient times, philosophy and science were much more closely related. The inability to test hypotheses made most scientific experiments the equivalent of philosophical thought experiments. This did not impede scientific progress, and many ideas from ancient times did, in fact, turn out to be correct.
Another one of the most important relationships between philosophy and science has to do with ethics. Science often creates changes in the world, and those changes are subject to ethical considerations. Thinking about the effects of science through a philosophical lens is important both for scientists and people who must live with the results of science.
Besides these broad connections, philosophy and science are also deliberately connected in some situations. The philosophy of science is itself a type of philosophy that considers many aspects of science. Science often makes use of philosophy in the form of logic, but it also draws on the ethical thoughts of the era in which the scientists live. Although science and philosophy are connected, they do not always necessarily draw the same conclusions, and problems must thus be evaluated independently in some cases.