How can pilots fly inside a cloud?
When aircraft fly inside clouds, they fly under &quot;instrument rules&quot;. It doesn't matter whether the visibility is reduced (at night) or totally blocked (in a thick cloud), this mode of flying simply assumes the crew has no external visual reference, they fly solely using indications given by on-board instruments.
The following short video shows a situation frequently encountered, the crew doesn't see anything outside prior to being so close to the ground, they are nearly landed.

Landing without visibility, source: YouTube.
After the problem of replacing external references has been solved, the next most important issue is to safely stay away from other aircraft. To prevent collisions, pilots are supported by air traffic control (ATC) from the ground. ATC determines aircraft location and altitude by relying on an on-board transponder. ATC issues appropriate information and instructions for pilots in order to maintain aircraft separated.
Should ATC fail to separate aircraft, commercial aircraft are equipped with a safety net: In last resort, close aircraft, transponder-equipped, are detected and avoided by an on-board collision avoidance system. While this system is efficient when there are only 2 or 3 aircraft involved, the escape maneuver must be done quickly and can be therefore sharp enough for a passenger not belted to be injured. This doesn't work if the other aircraft isn't equipped of a transponder, but all commercial aircraft carry such equipment by regulation.
All large airliners we know fly under instrument rules, regardless of the weather, or the time of day. However for a few runways, landing can be done  by a circling maneuver (or circle-to-land maneuver) in which the crew approaches the runway using an instrumental guidance which is interrupted before landing (usually because the guidance is designed for another runway), leaving the crew under visual rules until touchdown (such maneuvers are known to be more hazardous).
For the sake of completeness, a special kind of visual flight, VFR Over The Top, may be allowed over the cloud layer, during the upper part of the flight, where the horizon and other aircraft can be seen.

1. Technical aspects of instrument flying
It's technically possible to fly inside clouds, fog, snow, at night, etc, but this type of flight is regulated, it requires technical elements both in the aircraft and on the ground, and mandatory additional training for the pilot.
Good sense, and regulation, require the pilot to be able, at any time, to:

a/ Maintain an aircraft safe attitude (flight conditions preservation),
b/ Avoid obstacles and other aircraft (collision prevention),
c/ Find their way to a landing aerodrome (navigation).
d/ Know where they are (position awareness),

Flying without visibility basically means knowing how to carry out these tasks without looking outside the cockpit.
A: Maintain a safe attitude
One of the main references a pilot needs is the horizon. When the horizon is invisible, An artificial horizon reproduces the horizontal plane using a gyroscope. This instrument indicates whether the aircraft is pitched or rolled.
Regarding altitude and speed, the same instruments are used both for visual and instrument flying: Barometric altimeter and airspeed indicator.

Main instruments, traditional presentation. Source: Aircraft Spruce
Image above (left-to-right, top-to-bottom):

speed, attitude (artificial horizon), altitude,
turn indicator, heading, vertical speed


Same instruments on the electronic primary flight display of a A330. Source
Being aware of the aircraft attitude without external visual clues is not natural and more difficult than usually expected. There was a famous study (180-degree turn experiment, Bryan, Stonecipher, Aron) in 1954 which showed a pilot not trained to fly with instruments loses control of the aircraft in 3 minutes in average if external references are lost.
B: Collision prevention
As mentioned, a collision prevention service is provided by radio from the ground. An aircraft flying without visibility is separated by air controllers (ATC) from all other aircraft. The exact type of separation provided varies with airspace category, in particular when radar coverage is missing, e.g. when flying over oceans. For EU countries, see Classification of Airspace at SKYbrary.
Civil ATC determines the aircraft location and altitude by interrogating a transponder on-board the aircraft, from the ground. Should the aircraft transponder be not cooperative, ATC might have access to a primary radar, and perform traditional echo measurement, which is less accurate. Primary radar stations are usually operated by military.

Typical ATC room, source: Learn To Fly Here

See also What is a TRACON? for a full description of control rooms in the US.

ATC is definitely a difficult four-dimension task done using 2D displays. Mistakes are made, most of the time they are fixed in time. In the picture below, VRG231 is descending from FL370 while the facing and climbing DCA337 is through FL262. ATC evaluates they will cross safely, but overlooks the closer XCM3018 approaching from the right at FL360 (more details at SKYbrary).

Loss of separation conditions in place: VRG231 is descending. ATC takes DCA337 into account, but overlooks XCM3018, source
Additional on-board equipment can be used for actual nearby aircraft detection. Such collision avoidance system, known as (TCAS or ACAS), detects transponder-equipped aircraft, typically only within a few minutes radius by using a technique similar to ATC interrogation. In addition, TCAS can provide coordinated conflict resolution advisories to the pilots, to increase separation and prevent collision.

B737 TCAS (TA/RA positions on the transponder panel). Source

C: Navigation:
After the two first tasks of the crew (aircraft in safe flight and collision risks under control), it's time to look at how the crew can reach the destination.
Navigational radio aids are positioned at important locations on the ground, and on-board instruments are used to take benefit of them. Today they include VOR (relative bearing determination) and DME (distance determination) for navigation to, from and between airfields. NDB are still used, but their decommissioning has started around the world, they are used as long distance and non-precision VOR.
Extract from Nice airport (LFMN, France) documentation for Runway 04 departures. Note how VOR (circled in green) and NDB (magenta) are used as waypoints. Also note how NIZ VOR-DME is used as a reference for relative bearing and distance (green stars).

Source
Space radio aids, namely GNSS (US GPS, EU Galileo, Russian Glonass...) are complementing or replacing ground aids for operations (ground aids are still used and required by regulation). For example, the same departures from Nice using Precision Area Navigation (P-RNAV) taking advantage of GNSS, inertial and ground aids to obtain a precise combined position:

Waypoints are not referring to any ground aid but defined by their coordinates in the flight management system database. Same source
A manual or an automated landing can be conducted with the guidance of an ILS (instrument landing system), which is a radio lighthouse usable to follow proper direction and proper slope:

ILS principle (magenta clues displayed on the pilot panel)
As you may have noticed, contrary to a persistent belief, pilots don't rely on ATC for navigation (the exception would be when a pilot has lost all instrumental references. ATC may usually be able to provide a position if the transponder is still operational).
In busy terminal airspace, typically around large airports, ATC role is extended. First, the risk of collision being large and airports being in densely populated areas, aircraft must follow more constrained paths, ATC operators constantly monitor these paths and request corrections from pilots when necessary. Second, runways are scarce resources, arriving aircraft (and departing aircraft to a certain extent) must be sequenced (e.g. by adjusting their speed) into orderly and dense landing queues.
D: Position awareness
Current horizontal position has been determined for a long time using VOR and DME and geometry: angle-angle (aka triangulation) or angle-distance equations.
Larger aircraft have also used inertial platforms which are able to provide no only the current position, but also the heading, the ground speed and most uniquely the acceleration, the rate of rotation and the attitude (from which the angle of attack can be obtained).
Today, those technologies are complemented by GNSS which is able to provide the current position and altitude.
The inertial platforms are still used for their complete independence from any external resource, and their precision which is better than GNSS in the short time. Their big con is they drift continuously and must be reset at intervals (e.g. using GNSS data). To take advantage of everything available, sources are often mixed to provide weighted values and cross checking (add to this air sensors providing altitude and airspeed data).

B737 Fight Management Computer page showing current position according to several sensors. Source
Aircraft are also equipped with ground detection, to help prevent so-called &quot;CFIT&quot;, controlled flight into terrain. This sensor is based on on-board radar and stored maps and display ground obstacles around. It is used for horizontal monitoring (hill, mountain) as well as vertical monitoring (ground proximity during landing). Such systems are known as EGPWS, enhanced ground proximity warning system.. They warn pilots by loud advisories, e.g. &quot;Terrain! Terrain, pull up!&quot;.

VSD/EGPWS display on Boeing aircraft, source

2. Regulation point of view
Visibility conditions are determined to be either visual (good visibility) or instrument (insufficient visibility) and there are two sets of rules when flying (visual and instrument). Flying in instrument conditions requires by regulation to perform the flight under instrument rules.
Flying with reference to instruments only, requires:

The pilot has received the proper training,
The specific equipment is available in the aircraft, and on the ground,
ATC is provided from the ground.

VMC vs. IMC
There is a set of minimum conditions to declare that the outside environment is visible: these conditions are known as Visual Meteorological Conditions (VMC).
When VMC are not achieved, the conditions are said to be IMC, for Instrument Meteorological Conditions.
VMC criteria depends on countries and airspace, though ICAO provides international recommendations, e.g. in France, generally:

Minimum horizontal visibility 5 km (8 km above FL100).
Minimum distance to clouds: Horizontally 1.5 km, vertically 1,000 ft.

VFR vs. IFR
Any flight must be done under one of the two existing sets of rules:

Visual Flight Rules (VFR)
Instrument Flight Rules (IFR).

The rules to be followed are dictated by regulation and are directly dependent on the meteorological conditions.

In VMC, both VFR and IFR flight are allowed.

In IMC, only an IFR flight is allowed, the pilot must be qualified to perform IFR and the aircraft must be certified for IFR.


Related:

Spatial disorientation which may lead to fly upside down without knowing. Related training.