A significant obstacle for practical quantum computation is the loss of physical qubits in quantum computers, a decoherence mechanism most notably in optical systems. Here we experimentally demonstrate, both in the quantum circuit model and in the one-way quantum computer model, the smallest non-trivial quantum codes to tackle this problem. In the experiment, we encode single-qubit input states into highly-entangled multiparticle codewords, and we test their ability to protect encoded quantum information from detected one-qubit loss error. Our results prove the in-principle feasibility of overcoming the qubit loss error by quantum codes.