The fundamental unit for quantum computing is the qubit, an isolated, controllable two-level system. However, for many proposed quantum computer architectures, especially photonic systems, the qubits can be lost or can leak out of the desired two-level systems, posing a significant obstacle for practical quantum computation. Here, we experimentally demonstrate, both in the quantum circuit model and in the one-way quantum computer model, the smallest nontrivial quantum codes to tackle this problem. In the experiment, we encode single-qubit input states into highly entangled multiparticle code words, and we test their ability to protect encoded quantum information from detected 1-qubit loss error. Our results prove in-principle the feasibility of overcoming the qubit loss error by quantum codes.