Understanding the D8 Algorithm in GIS: How ArcGIS Pro Determines Flow Direction Across Raster Cells

Figure 1: The eight D8 direction codes (left) and a worked example in which the steepest drop decides the code (right). Illustrative heights.

Guide at a glance 
TaskUnderstand how each raster cell is assigned one downslope neighbour, and how that single rule builds flow accumulation, streams and watersheds
SoftwareArcGIS Pro 3.x, Spatial Analyst (Flow Direction, Flow Accumulation, Watershed). Names follow Esri documentation for 3.x
InputA hydrologically conditioned DEM (sinks already filled)
OutputA flow direction raster, then accumulation, stream and watershed rasters

Every hydrology map produced from a raster, from a stream network to a catchment outline to a flow-path trace, is based on a single choice that is repeated millions of times – which neighbour does the water in this cell flow to? The default method for ArcGIS Pro to solve it is the D8 Flow Direction Algorithm. It is easy to compute on a 9 cell grid by hand and that is why it is so reliable and well known for its shortcomings. This guide explains the rule, its codes, the tool settings in Flow Direction in ArcGIS Pro, and the processes created on the rule, as well as computed examples to demonstrate the strengths and weaknesses of the rule.

READ MORE: Powerful DEM Sink Correction in ArcGIS Pro for Better Flow

1.  The Rule Behind D8

The situation of the 8 neighbours of a cell is the origin of the name of D8.The name D8 comes from the way the eight neighbours of a cell are arranged. The algorithm for each cell compares to each neighbour, computes the drop, and pushes all of the flow to the neighbour with the steepest drop. The drop is scaled by the distance between the centres of the cells, which is 1 cell width for neighbours on the edges and about 1.414 for those on the diagonals. Esri reports the result in terms of feet of change over distance, which is multiplied by 100, or a percentage.

As an example, the calculation for one of the cells with a height of 52 is shown in figure 1 (right). The south-east neighbour is 5 lower and 1.414 cells away dropping by 353.6 and the neighbour to the south is 2 lower and 1 cell away dropping by 200. The south-east cell wins and the centre cell receives the code for the south-east cell, 2.

DirectionCodeNeighbour positionNote
East1RightEsri’s starting code, increases clockwise
South-east2Down and right 
South4DownRight and down both equal: 1 + 4 = 5
South-west8Down and left 
West16LeftSteepest drop to the left gives 16
North-west32Up and left 
North64Up 
North-east128Up and rightLargest valid single code

The reason for the powers of two in the codes. If the steepest decrease is equally shared by two or more neighbours, Esri sums the codes – for instance, if a tie exists between east and south, it is assigned the code 5. There is always a sum associated with any combination of directions, and thus the sum may be stored in the raster without loss of information. The output values are thus 1 to 255.

READ MORE: Powerful GIS and Remote Sensing Techniques for Insights

2.  Flow Direction in ArcGIS Pro: Tool Settings

The tool lives in the Spatial Analyst Hydrology toolset and needs a Spatial Analyst licence. The parameters that matter for Flow Direction in ArcGIS Pro are summarised below.

SettingBehaviour
Input surface rasterThe DEM. Run it on a conditioned DEM; see the section on sinks
Flow direction typeD8 (default; steepest downslope neighbour; integer output), MFD (multiple flow direction; needs CRF output, which Flow Accumulation can use) or DINF (D-infinity; float angles from 0 to 360, counter-clockwise from east)
Force all edge cells to flow outwardUnchecked is NORMAL; checked is FORCE. Forcing sends every cell on the border off the surface and avoids edge artefacts in a catchment that is not cut along its watershed divide
Output drop raster (optional)The drop used to choose the direction, as a percentage. Useful for spotting flats and steep chutes

For more than two special cases, Esri documents them. One-cell pits are discarded as noise as they are filtered by a single-cell pit lower than all its 8 neighbours. For flat regions, with multiple neighbors at the same elevation, the flow is assigned by using the lookup table described in Greenlee (1987) to direct flow to lower terrain around flat regions. If a direction is still not known for a cell, it is a sink and can be marked with the Sink tool.

3.  Why a Conditioned DEM Comes First

D8 is a local only rule. Does not allow water to flow towards it from above, hence dead end where its cell is lower than all adjacent cells. All of the water below that dead-end is misplaced: accumulations cease, streams fragment and basins are truncated. Raster Hydrological Analysis, therefore, begins with a DEM that has been filled to remove sinks (as detailed in our companion guide on DEM sink correction).

The effect is large. We have created a synthetic 160×160 cell DEM (30 m cells, calculated by us) and we have drawn the watershed above the same outlet cell twice. The raw DEM only contained 1198 cells in the basin, approximately 1.1 km² of basin area. It contained 15,160 cells, or just under 13.6 km2, on the filled DEM, which is almost thirteen times larger. Figure 2 shows both. This was a case where the outlet was the same, the algorithm was the same and the data was the same, but the sinks varied.

READ MORE: Powerful Digital Elevation Model for Accurate GIS Mapping

Figure 2: The same outlet (black triangle) on a raw DEM and on a filled DEM. Synthetic data, drawn for illustration.

4.  Flow Accumulation in GIS: Counting the Cells Upstream

Once every cell points to one neighbour, the raster becomes a set of tree-like networks. Flow Accumulation in GIS reads those pointers and counts, for each cell, the number of cells whose flow passes through it. Cells on ridges have the value 1, counting only themselves; cells in valleys collect more and more; the cell at an outlet holds the area of the whole basin, expressed in cells. Multiplying by the cell area converts the count to square metres or kilometres.

Figure 3 shows the idea on a seven by seven grid built for this guide. A valley runs down the centre column. Each side cell sends its water toward the valley, and the valley cells collect it: the accumulation grows 3, 8, 13, 18, 23 and 24 down the channel. Cells on the border drain off the grid, which is why 24 and not 49 arrives at the bottom: the other cells left through the top and the sides.

Figure 3: Elevation and D8 directions (left) and flow accumulation (right) on a 7 by 7 teaching grid.

Accumulation is not the end product but the basis for several. A threshold on accumulation selects stream cells: the larger the threshold, the sparser the network. Esri’s hydrology tools then derive flow length, stream links, stream order and stream features from the accumulation and direction rasters. Choosing the threshold is a modelling decision tied to the scale, climate and purpose of the study, and the same DEM gives a denser or sparser network depending on it.

READ MORE: Powerful Low lying area mapping using GIS for Better Planning

5.  Watershed Delineation Using ArcGIS

Watershed Delineation Using ArcGIS is the last link. A watershed is the set of cells that drain to a chosen outlet, a pour point, which may be a stream mouth, a gauge or a bridge. The Watershed tool follows the D8 pointers upstream from each pour point and marks every cell whose path reaches it. Pour points should sit on a stream cell. If a pour point is a few cells off the channel, the tool will delineate a tiny catchment, which is the commonest source of a watershed that is “too small”. The Snap Pour Point tool moves points to the nearest cell of high accumulation within a chosen distance, and is a standard step before delineation.

Esri’s workflow for runoff characteristics follows exactly this sequence: condition the DEM, derive direction and accumulation, define streams, then delineate watersheds from pour points or from stream segments used as pour points.

Figure 4: The D8 hydrology chain in ArcGIS Pro.

6.  The Limits of D8

The D8 Flow Direction Algorithm has three structural limits, and a competent analyst knows them before trusting a result.

  1. It snaps every direction to one of eight. Real water flows in any compass direction. On a surface that faces exactly east, D8 is perfect; on a surface that faces between two codes, it splits the cells between them and draws a zig-zag. In our test on a plane, a true bearing of 22.5° gave 48 percent of cells an east code and 52 percent a south-east code, while bearings of 0° and 45° gave 100 percent to one code (Figure 5).
  2. It cannot divide flow. All water in a cell goes to one neighbour. On convex slopes, ridges and fans, where water actually spreads, D8 collapses it into parallel lines, and Flow Accumulation in GIS on these slopes is overstated along the lines and unchanged between them.
  3. It is sensitive to the DEM. Small errors in height change the steepest neighbour. This is a larger problem on flats, where the tie-breaking rule decides the path.

Figure 5: Share of cells given each D8 code on a plane with a given true bearing. Synthetic data.

MethodHow it routes flowOutputTypical use
D8All flow to the steepest of 8 neighboursInteger codes 1 to 255Channel networks, catchment boundaries, fast and consistent
MFDDivides flow among all lower neighboursCRF rasterHillslopes and fans where flow spreads
DINFFlow angle between neighbours, shared between twoFloat angle 0 to 360, counter-clockwise from eastSmoother direction on planar slopes

As a rule, D8 is a sound default for channel networks and watersheds, because water in channels does follow a single path. For hillslope processes such as erosion or contaminant spreading, a multiple-flow method may be a better fit.

7.  Practical Checklist

  1. Project the DEM and check vertical units.
  2. Fill sinks (with a z limit where genuine depressions exist) and keep the original DEM.
  3. Run Flow Direction with the D8 type; decide whether to force edge flow.
  4. Run Flow Accumulation and inspect the largest values: they should follow real channels.
  5. Choose a stream threshold for your scale, and test two values.
  6. Place pour points on stream cells, using Snap Pour Point where needed.
  7. Complete the Watershed Delineation Using ArcGIS step and compare the areas with known catchments or gauged areas.

8.  Common Problems

SymptomLikely causeFix
Streams break off mid-slopeUnfilled sinksFill sinks, then re-run Flow Direction
Straight, parallel flow linesD8 on flats or planar slopesUse a finer DEM, enforce channels or compare with MFD or DINF
Watershed far smaller than expectedPour point off the channel, or edge cutSnap the pour point and extend the DEM beyond the catchment
Edge cells show odd flowNORMAL edge handling at the borderBuffer the DEM, or use FORCE where appropriate
Codes look meaninglessReading D8 codes as heightsRemember codes are directions: 1 east, 2 south-east, 4 south, and sums for ties

9.  Limits of This Guide

The behavior of this tool is documented as it does in ArcGIS Pro 3.x (Flow Direction), and can vary in other releases. The figures in this article are not screenshots, but synthetic figures calculated by our own implementation of D8, and the figures are drawn on this terrain, rather than a real one, so the exact figures will vary in ArcGIS Pro. All Raster Hydrological Analysis should be verified with imagery, known streams and gauged areas.

Conclusion

The D8 rule is a comparison of just eight drops and the entire chain of Raster Hydrological Analysis includes direction, accumulation, streams and basins. It has advantages of speed, consistency and the product that is similar to water in channels. It has been known to have weaknesses: grid-aligned flow, no divergence, and DEM must be clean. In our test, the same outlet provided the basin of 1.1 km² on the raw DEM, and of 13.6 km² on the filled one, with the surface being more important than the algorithm. The D8 Flow Direction Algorithm is a reliable basis for catchment studies if the stream threshold is appropriate, and pour points are placed correctly.

Simbi Labs India supports DEM processing, watershed delineation and hydrological modelling for water resources, infrastructure and environmental projects. To discuss a project, book a free consultation or write to grow@simbi.in.

Leave a Comment

Your email address will not be published. Required fields are marked *